Commit c9ec7b28 authored by harrylee's avatar harrylee Committed by 33cn

make linter

parent 4e6ee9d0
......@@ -206,19 +206,6 @@ func (abi *ABI) overloadedEventName(rawName string) string {
return name
}
// MethodById looks up a method by the 4-byte id, returns nil if none found
func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
if len(sigdata) < 4 {
return nil, fmt.Errorf("data too short (%d bytes) for abi method lookup", len(sigdata))
}
for _, method := range abi.Methods {
if bytes.Equal(method.ID, sigdata[:4]) {
return &method, nil
}
}
return nil, fmt.Errorf("no method with id: %#x", sigdata[:4])
}
// EventByID looks an event up by its topic hash in the
// ABI and returns nil if none found.
func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
......@@ -255,7 +242,7 @@ func (abi *ABI) MethodByID(sigdata []byte) (*Method, error) {
}
var revertSelector = crypto.Keccak256([]byte("Error(string)"))[:4]
// UnpackRevert 解包转换为string
func UnpackRevert(data []byte) (string, error) {
if len(data) < 4 {
return "", errors.New("invalid data for unpacking")
......
......@@ -950,7 +950,7 @@ func TestABI_MethodById(t *testing.T) {
}
for name, m := range abi.Methods {
a := fmt.Sprintf("%v", m)
m2, err := abi.MethodById(m.ID)
m2, err := abi.MethodByID(m.ID)
if err != nil {
t.Fatalf("Failed to look up ABI method: %v", err)
}
......@@ -960,17 +960,17 @@ func TestABI_MethodById(t *testing.T) {
}
}
// test unsuccessful lookups
if _, err = abi.MethodById(crypto.Keccak256()); err == nil {
if _, err = abi.MethodByID(crypto.Keccak256()); err == nil {
t.Error("Expected error: no method with this id")
}
// Also test empty
if _, err := abi.MethodById([]byte{0x00}); err == nil {
if _, err := abi.MethodByID([]byte{0x00}); err == nil {
t.Errorf("Expected error, too short to decode data")
}
if _, err := abi.MethodById([]byte{}); err == nil {
if _, err := abi.MethodByID([]byte{}); err == nil {
t.Errorf("Expected error, too short to decode data")
}
if _, err := abi.MethodById(nil); err == nil {
if _, err := abi.MethodByID(nil); err == nil {
t.Errorf("Expected error, nil is short to decode data")
}
}
......
......@@ -251,102 +251,6 @@ func str2GoValue(typ Type, val string) (res interface{}, err error) {
}
}
//func str2GoValue(typ Type, val string) (res interface{}, err error) {
// switch typ.T {
// case IntTy:
// if typ.Size < 256 {
// x, err := strconv.ParseInt(val, 10, typ.Size)
// if err != nil {
// return res, err
// }
// return convertInt(x, typ.Kind), nil
// }
// b := new(big.Int)
// b.SetString(val, 10)
// return b, err
// case UintTy:
// if typ.Size < 256 {
// x, err := strconv.ParseUint(val, 10, typ.Size)
// if err != nil {
// return res, err
// }
// return convertUint(x, typ.Kind), nil
// }
// b := new(big.Int)
// b.SetString(val, 10)
// return b, err
// case BoolTy:
// x, err := strconv.ParseBool(val)
// if err != nil {
// return res, err
// }
// return x, nil
// case StringTy:
// return val, nil
// case SliceTy:
// subs, err := procArrayItem(val)
// if err != nil {
// return res, err
// }
// rval := reflect.MakeSlice(typ.Type, len(subs), len(subs))
// for idx, sub := range subs {
// subVal, er := str2GoValue(*typ.Elem, sub)
// if er != nil {
// return res, er
// }
// rval.Index(idx).Set(reflect.ValueOf(subVal))
// }
// return rval.Interface(), nil
// case ArrayTy:
// rval := reflect.New(typ.Type).Elem()
// subs, err := procArrayItem(val)
// if err != nil {
// return res, err
// }
// for idx, sub := range subs {
// subVal, er := str2GoValue(*typ.Elem, sub)
// if er != nil {
// return res, er
// }
// rval.Index(idx).Set(reflect.ValueOf(subVal))
// }
// return rval.Interface(), nil
// case AddressTy:
// addr := common.StringToAddress(val)
// if addr == nil {
// return res, fmt.Errorf("invalid address: %v", val)
// }
// return addr.ToHash160(), nil
// case FixedBytesTy:
// // 固定长度多字节,输入时以十六进制方式表示,如 0xabcd00ff
// x, err := common.HexToBytes(val)
// if err != nil {
// return res, err
// }
// rval := reflect.New(typ.Type).Elem()
// for i, b := range x {
// rval.Index(i).Set(reflect.ValueOf(b))
// }
// return rval.Interface(), nil
// case BytesTy:
// // 单个字节,输入时以十六进制方式表示,如 0xab
// x, err := common.HexToBytes(val)
// if err != nil {
// return res, err
// }
// return x, nil
// case HashTy:
// // 哈希类型,也是以十六进制为输入,如:0xabcdef
// x, err := common.HexToBytes(val)
// if err != nil {
// return res, err
// }
// return common.BytesToHash(x), nil
// default:
// return res, fmt.Errorf("not support type: %v", typ.stringKind)
// }
//}
// 本方法可以将一个表示数组的字符串,经过处理后,返回数组内的字面元素;
// 如果数组为多层,则只返回第一级
// 例如:"[a,b,c]" -> "a","b","c"
......
......@@ -30,9 +30,10 @@ type Argument struct {
Type Type
Indexed bool // indexed is only used by events
}
// Arguments 参数
type Arguments []Argument
// ArgumentMarshaling 参数数列化结构体
type ArgumentMarshaling struct {
Name string
Type string
......
......@@ -173,7 +173,7 @@ func TestEventTupleUnpack(t *testing.T) {
type EventTransferWithTag struct {
// this is valid because `value` is not exportable,
// so value is only unmarshalled into `Value1`.
value *big.Int //lint:ignore U1000 unused field is part of test
//value *big.Int //lint:ignore U1000 unused field is part of test
Value1 *big.Int `abi:"value"`
}
......
......@@ -17,24 +17,8 @@
package abi
import (
"math/big"
"reflect"
"github.com/33cn/plugin/plugin/dapp/evm/executor/vm/common"
)
var (
bigT = reflect.TypeOf(&big.Int{})
derefbigT = reflect.TypeOf(big.Int{})
uint8T = reflect.TypeOf(uint8(0))
uint16T = reflect.TypeOf(uint16(0))
uint32T = reflect.TypeOf(uint32(0))
uint64T = reflect.TypeOf(uint64(0))
int8T = reflect.TypeOf(int8(0))
int16T = reflect.TypeOf(int16(0))
int32T = reflect.TypeOf(int32(0))
int64T = reflect.TypeOf(int64(0))
addressT = reflect.TypeOf(common.Hash160Address{})
"math/big"
)
// U256 converts a big Int into a 256bit EVM number.
......
......@@ -155,9 +155,8 @@ func EmptyAddress() Address { return BytesToAddress([]byte{0}) }
// If s is larger than len(h), s will be cropped from the left.
func HexToAddress(s string) Hash160Address { return BytesToHash160Address(FromHex(s)) }
// INTToAddress 大数字转换为地址
// Uint256ToAddress 大数字转换为地址
func Uint256ToAddress(b *uint256.Int) Address {
//TODO 这样转换可能与之前的版本不兼容
a := new(address.Address)
a.Version = 0
out := make([]byte, 20)
......@@ -166,7 +165,7 @@ func Uint256ToAddress(b *uint256.Int) Address {
return Address{Addr: a}
}
//十六进制转换为虚拟机中的地址
// HexToAddr 十六进制转换为虚拟机中的地址
func HexToAddr(s string) Address {
a := new(address.Address)
a.Version = 0
......
......@@ -23,13 +23,13 @@ import (
)
const (
// The blocksize of BLAKE2b in bytes.
// BlockSize BLAKE2b的块大小
BlockSize = 128
// The hash size of BLAKE2b-512 in bytes.
// Size BLAKE2b-512 hash大小
Size = 64
// The hash size of BLAKE2b-384 in bytes.
// Size384 The hash size of BLAKE2b-384 in bytes.
Size384 = 48
// The hash size of BLAKE2b-256 in bytes.
// Size256 The hash size of BLAKE2b-256 in bytes.
Size256 = 32
)
......@@ -302,18 +302,18 @@ func appendUint64(b []byte, x uint64) []byte {
return append(b, a[:]...)
}
func appendUint32(b []byte, x uint32) []byte {
var a [4]byte
binary.BigEndian.PutUint32(a[:], x)
return append(b, a[:]...)
}
//func appendUint32(b []byte, x uint32) []byte {
// var a [4]byte
// binary.BigEndian.PutUint32(a[:], x)
// return append(b, a[:]...)
//}
func consumeUint64(b []byte) ([]byte, uint64) {
x := binary.BigEndian.Uint64(b)
return b[8:], x
}
func consumeUint32(b []byte) ([]byte, uint32) {
x := binary.BigEndian.Uint32(b)
return b[4:], x
}
//func consumeUint32(b []byte) ([]byte, uint32) {
// x := binary.BigEndian.Uint32(b)
// return b[4:], x
//}
......@@ -5,7 +5,6 @@
package blake2b
import (
"encoding/binary"
"math/bits"
)
......@@ -25,23 +24,23 @@ var precomputed = [10][16]byte{
{10, 8, 7, 1, 2, 4, 6, 5, 15, 9, 3, 13, 11, 14, 12, 0},
}
func hashBlocksGeneric(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
var m [16]uint64
c0, c1 := c[0], c[1]
for i := 0; i < len(blocks); {
c0 += BlockSize
if c0 < BlockSize {
c1++
}
for j := range m {
m[j] = binary.LittleEndian.Uint64(blocks[i:])
i += 8
}
fGeneric(h, &m, c0, c1, flag, 12)
}
c[0], c[1] = c0, c1
}
//func hashBlocksGeneric(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
// var m [16]uint64
// c0, c1 := c[0], c[1]
//
// for i := 0; i < len(blocks); {
// c0 += BlockSize
// if c0 < BlockSize {
// c1++
// }
// for j := range m {
// m[j] = binary.LittleEndian.Uint64(blocks[i:])
// i += 8
// }
// fGeneric(h, &m, c0, c1, flag, 12)
// }
// c[0], c[1] = c0, c1
//}
func fGeneric(h *[8]uint64, m *[16]uint64, c0, c1 uint64, flag uint64, rounds uint64) {
v0, v1, v2, v3, v4, v5, v6, v7 := h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7]
......
......@@ -14,13 +14,13 @@ import (
"testing"
)
func fromHex(s string) []byte {
b, err := hex.DecodeString(s)
if err != nil {
panic(err)
}
return b
}
//func fromHex(s string) []byte {
// b, err := hex.DecodeString(s)
// if err != nil {
// panic(err)
// }
// return b
//}
func TestHashes(t *testing.T) {
defer func(sse4, avx, avx2 bool) {
......
......@@ -5,7 +5,7 @@ import (
"math/big"
)
var fuz int = 10
var fuz = 10
func randScalar(max *big.Int) *big.Int {
a, _ := rand.Int(rand.Reader, max)
......
......@@ -39,7 +39,7 @@ type fe6 [3]fe2
// Representation follows c[0] + c[1] * w encoding order.
type fe12 [2]fe6
func (fe *fe) setBytes(in []byte) *fe {
func (fe1 *fe) setBytes(in []byte) *fe {
size := 48
l := len(in)
if l >= size {
......@@ -50,19 +50,19 @@ func (fe *fe) setBytes(in []byte) *fe {
var a int
for i := 0; i < 6; i++ {
a = size - i*8
fe[i] = uint64(padded[a-1]) | uint64(padded[a-2])<<8 |
fe1[i] = uint64(padded[a-1]) | uint64(padded[a-2])<<8 |
uint64(padded[a-3])<<16 | uint64(padded[a-4])<<24 |
uint64(padded[a-5])<<32 | uint64(padded[a-6])<<40 |
uint64(padded[a-7])<<48 | uint64(padded[a-8])<<56
}
return fe
return fe1
}
func (fe *fe) setBig(a *big.Int) *fe {
return fe.setBytes(a.Bytes())
func (fe1 *fe) setBig(a *big.Int) *fe {
return fe1.setBytes(a.Bytes())
}
func (fe *fe) setString(s string) (*fe, error) {
func (fe1 *fe) setString(s string) (*fe, error) {
if s[:2] == "0x" {
s = s[2:]
}
......@@ -70,129 +70,129 @@ func (fe *fe) setString(s string) (*fe, error) {
if err != nil {
return nil, err
}
return fe.setBytes(bytes), nil
return fe1.setBytes(bytes), nil
}
func (fe *fe) set(fe2 *fe) *fe {
fe[0] = fe2[0]
fe[1] = fe2[1]
fe[2] = fe2[2]
fe[3] = fe2[3]
fe[4] = fe2[4]
fe[5] = fe2[5]
return fe
func (fe1 *fe) set(fe2 *fe) *fe {
fe1[0] = fe2[0]
fe1[1] = fe2[1]
fe1[2] = fe2[2]
fe1[3] = fe2[3]
fe1[4] = fe2[4]
fe1[5] = fe2[5]
return fe1
}
func (fe *fe) bytes() []byte {
func (fe1 *fe) bytes() []byte {
out := make([]byte, 48)
var a int
for i := 0; i < 6; i++ {
a = 48 - i*8
out[a-1] = byte(fe[i])
out[a-2] = byte(fe[i] >> 8)
out[a-3] = byte(fe[i] >> 16)
out[a-4] = byte(fe[i] >> 24)
out[a-5] = byte(fe[i] >> 32)
out[a-6] = byte(fe[i] >> 40)
out[a-7] = byte(fe[i] >> 48)
out[a-8] = byte(fe[i] >> 56)
out[a-1] = byte(fe1[i])
out[a-2] = byte(fe1[i] >> 8)
out[a-3] = byte(fe1[i] >> 16)
out[a-4] = byte(fe1[i] >> 24)
out[a-5] = byte(fe1[i] >> 32)
out[a-6] = byte(fe1[i] >> 40)
out[a-7] = byte(fe1[i] >> 48)
out[a-8] = byte(fe1[i] >> 56)
}
return out
}
func (fe *fe) big() *big.Int {
return new(big.Int).SetBytes(fe.bytes())
func (fe1 *fe) big() *big.Int {
return new(big.Int).SetBytes(fe1.bytes())
}
func (fe *fe) string() (s string) {
func (fe1 *fe) string() (s string) {
for i := 5; i >= 0; i-- {
s = fmt.Sprintf("%s%16.16x", s, fe[i])
s = fmt.Sprintf("%s%16.16x", s, fe1[i])
}
return "0x" + s
}
func (fe *fe) zero() *fe {
fe[0] = 0
fe[1] = 0
fe[2] = 0
fe[3] = 0
fe[4] = 0
fe[5] = 0
return fe
func (fe1 *fe) zero() *fe {
fe1[0] = 0
fe1[1] = 0
fe1[2] = 0
fe1[3] = 0
fe1[4] = 0
fe1[5] = 0
return fe1
}
func (fe *fe) one() *fe {
return fe.set(r1)
func (fe1 *fe) one() *fe {
return fe1.set(r1)
}
func (fe *fe) rand(r io.Reader) (*fe, error) {
func (fe1 *fe) rand(r io.Reader) (*fe, error) {
bi, err := rand.Int(r, modulus.big())
if err != nil {
return nil, err
}
return fe.setBig(bi), nil
return fe1.setBig(bi), nil
}
func (fe *fe) isValid() bool {
return fe.cmp(&modulus) < 0
func (fe1 *fe) isValid() bool {
return fe1.cmp(&modulus) < 0
}
func (fe *fe) isOdd() bool {
func (fe1 *fe) isOdd() bool {
var mask uint64 = 1
return fe[0]&mask != 0
return fe1[0]&mask != 0
}
func (fe *fe) isEven() bool {
func (fe1 *fe) isEven() bool {
var mask uint64 = 1
return fe[0]&mask == 0
return fe1[0]&mask == 0
}
func (fe *fe) isZero() bool {
return (fe[5] | fe[4] | fe[3] | fe[2] | fe[1] | fe[0]) == 0
func (fe1 *fe) isZero() bool {
return (fe1[5] | fe1[4] | fe1[3] | fe1[2] | fe1[1] | fe1[0]) == 0
}
func (fe *fe) isOne() bool {
return fe.equal(r1)
func (fe1 *fe) isOne() bool {
return fe1.equal(r1)
}
func (fe *fe) cmp(fe2 *fe) int {
func (fe1 *fe) cmp(fe2 *fe) int {
for i := 5; i >= 0; i-- {
if fe[i] > fe2[i] {
if fe1[i] > fe2[i] {
return 1
} else if fe[i] < fe2[i] {
} else if fe1[i] < fe2[i] {
return -1
}
}
return 0
}
func (fe *fe) equal(fe2 *fe) bool {
return fe2[0] == fe[0] && fe2[1] == fe[1] && fe2[2] == fe[2] && fe2[3] == fe[3] && fe2[4] == fe[4] && fe2[5] == fe[5]
func (fe1 *fe) equal(fe2 *fe) bool {
return fe2[0] == fe1[0] && fe2[1] == fe1[1] && fe2[2] == fe1[2] && fe2[3] == fe1[3] && fe2[4] == fe1[4] && fe2[5] == fe1[5]
}
func (e *fe) sign() bool {
func (fe1 *fe) sign() bool {
r := new(fe)
fromMont(r, e)
fromMont(r, fe1)
return r[0]&1 == 0
}
func (fe *fe) div2(e uint64) {
fe[0] = fe[0]>>1 | fe[1]<<63
fe[1] = fe[1]>>1 | fe[2]<<63
fe[2] = fe[2]>>1 | fe[3]<<63
fe[3] = fe[3]>>1 | fe[4]<<63
fe[4] = fe[4]>>1 | fe[5]<<63
fe[5] = fe[5]>>1 | e<<63
func (fe1 *fe) div2(e uint64) {
fe1[0] = fe1[0]>>1 | fe1[1]<<63
fe1[1] = fe1[1]>>1 | fe1[2]<<63
fe1[2] = fe1[2]>>1 | fe1[3]<<63
fe1[3] = fe1[3]>>1 | fe1[4]<<63
fe1[4] = fe1[4]>>1 | fe1[5]<<63
fe1[5] = fe1[5]>>1 | e<<63
}
func (fe *fe) mul2() uint64 {
e := fe[5] >> 63
fe[5] = fe[5]<<1 | fe[4]>>63
fe[4] = fe[4]<<1 | fe[3]>>63
fe[3] = fe[3]<<1 | fe[2]>>63
fe[2] = fe[2]<<1 | fe[1]>>63
fe[1] = fe[1]<<1 | fe[0]>>63
fe[0] = fe[0] << 1
func (fe1 *fe) mul2() uint64 {
e := fe1[5] >> 63
fe1[5] = fe1[5]<<1 | fe1[4]>>63
fe1[4] = fe1[4]<<1 | fe1[3]>>63
fe1[3] = fe1[3]<<1 | fe1[2]>>63
fe1[2] = fe1[2]<<1 | fe1[1]>>63
fe1[1] = fe1[1]<<1 | fe1[0]>>63
fe1[0] = fe1[0] << 1
return e
}
......
......@@ -127,7 +127,7 @@ func inverse(inv, e *fe) {
laddAssign(s, r)
z += r.mul2()
}
k += 1
k ++
}
if !found {
......
......@@ -846,7 +846,7 @@ func TestFp2NonResidue(t *testing.T) {
t.Fatal("element is quadratic non residue, 2", i)
}
} else {
i -= 1
i --
}
}
}
......
......@@ -27,6 +27,7 @@ import (
// If z is equal to one the point is considered as in affine form.
type PointG1 [3]fe
// Set 设置G1 point
func (p *PointG1) Set(p2 *PointG1) *PointG1 {
p[0].set(&p2[0])
p[1].set(&p2[1])
......@@ -228,7 +229,7 @@ func (g *G1) IsAffine(p *PointG1) bool {
return p[2].isOne()
}
// Add adds two G1 points p1, p2 and assigns the result to point at first argument.
// Affine Add adds two G1 points p1, p2 and assigns the result to point at first argument.
func (g *G1) Affine(p *PointG1) *PointG1 {
if g.IsZero(p) {
return p
......@@ -266,9 +267,8 @@ func (g *G1) Add(r, p1, p2 *PointG1) *PointG1 {
if t[1].equal(t[3]) {
if t[0].equal(t[2]) {
return g.Double(r, p1)
} else {
return r.Zero()
}
return r.Zero()
}
sub(t[1], t[1], t[3])
double(t[4], t[1])
......
......@@ -29,6 +29,7 @@ type GT struct {
fp12 *fp12
}
// Set 设置E
func (e *E) Set(e2 *E) *E {
return e.set(e2)
}
......@@ -36,7 +37,8 @@ func (e *E) Set(e2 *E) *E {
// One sets a new target group element to one
func (e *E) One() *E {
e = new(fe12).one()
return e
var e1 *E = e
return e1
}
// IsOne returns true if given element equals to one
......@@ -45,8 +47,8 @@ func (e *E) IsOne() bool {
}
// Equal returns true if given two element is equal, otherwise returns false
func (g *E) Equal(g2 *E) bool {
return g.equal(g2)
func (e *E) Equal(g2 *E) bool {
return e.equal(g2)
}
// NewGT constructs new target group instance.
......@@ -67,10 +69,11 @@ func (g *GT) FromBytes(in []byte) (*E, error) {
if err != nil {
return nil, err
}
if !g.IsValid(e) {
return e, errors.New("invalid element")
var e1 *E = e
if !g.IsValid(e1) {
return e1, errors.New("invalid element")
}
return e, nil
return e1, nil
}
// ToBytes serializes target group element.
......
......@@ -272,8 +272,9 @@ func (e *Engine) Check() bool {
// Result computes pairing and returns target group element as result.
func (e *Engine) Result() *E {
r := e.calculate()
var r1 *E = r
e.Reset()
return r
return r1
}
// GT returns target group instance.
......
......@@ -51,21 +51,21 @@ func (g *G1) String() string {
// ScalarBaseMult sets e to g*k where g is the generator of the group and then
// returns e.
func (e *G1) ScalarBaseMult(k *big.Int) *G1 {
if e.p == nil {
e.p = &curvePoint{}
func (g *G1) ScalarBaseMult(k *big.Int) *G1 {
if g.p == nil {
g.p = &curvePoint{}
}
e.p.Mul(curveGen, k)
return e
g.p.Mul(curveGen, k)
return g
}
// ScalarMult sets e to a*k and then returns e.
func (e *G1) ScalarMult(a *G1, k *big.Int) *G1 {
if e.p == nil {
e.p = &curvePoint{}
func (g *G1) ScalarMult(a *G1, k *big.Int) *G1 {
if g.p == nil {
g.p = &curvePoint{}
}
e.p.Mul(a.p, k)
return e
g.p.Mul(a.p, k)
return g
}
// Add sets e to a+b and then returns e.
......
......@@ -5,12 +5,8 @@ package bn256
// This file contains forward declarations for the architecture-specific
// assembly implementations of these functions, provided that they exist.
import (
"golang.org/x/sys/cpu"
)
//nolint:varcheck
var hasBMI2 = cpu.X86.HasBMI2
//var hasBMI2 = cpu.X86.HasBMI2
// go:noescape
func gfpNeg(c, a *gfP)
......
......@@ -56,9 +56,9 @@ func MemoryCreate(stack *Stack) (uint64, bool) {
return calcMemSize64(stack.Back(1), stack.Back(2))
}
func memoryCreate2(stack *Stack) (uint64, bool) {
return calcMemSize64(stack.Back(1), stack.Back(2))
}
//func memoryCreate2(stack *Stack) (uint64, bool) {
// return calcMemSize64(stack.Back(1), stack.Back(2))
//}
//MemoryCall call所需内存大小
func MemoryCall(stack *Stack) (uint64, bool) {
......
......@@ -112,11 +112,12 @@ type ReturnStack struct {
data []uint32
}
// ReturnStack 返回栈对象封装,提供常用的返回栈操作
// NewReturnStack 返回栈对象封装,提供常用的返回栈操作
func NewReturnStack() *ReturnStack {
return rStackPool.Get().(*ReturnStack)
}
// ReturnRStack 将returnStack还给rStackPool
func ReturnRStack(rs *ReturnStack) {
rs.data = rs.data[:0]
rStackPool.Put(rs)
......@@ -126,17 +127,19 @@ func (st *ReturnStack) Push(d uint32) {
st.data = append(st.data, d)
}
// A uint32 is sufficient as for code below 4.2G
// Pop A uint32 is sufficient as for code below 4.2G
func (st *ReturnStack) Pop() (ret uint32) {
ret = st.data[len(st.data)-1]
st.data = st.data[:len(st.data)-1]
return
}
// Len ReturnStack大小
func (st *ReturnStack) Len() int {
return len(st.data)
}
// Data 返回栈中的所有底层数据
func (st *ReturnStack) Data() []uint32 {
return st.data
}
......@@ -41,8 +41,12 @@ var (
// ErrNoCoinsAccount no coins account in executor!
ErrNoCoinsAccount = errors.New("no coins account in executor")
// ErrReturnStackExceeded
ErrReturnStackExceeded = errors.New("return stack limit reached")
// ErrInvalidSubroutineEntry
ErrInvalidSubroutineEntry = errors.New("invalid subroutine entry")
// ErrInvalidJump
ErrInvalidJump = errors.New("invalid jump destination")
// ErrInvalidRetsub
ErrInvalidRetsub = errors.New("invalid retsub")
)
......@@ -843,7 +843,7 @@ func opPush1(pc *uint64, evm *EVM, callContext *callCtx) ([]byte, error) {
codeLen = uint64(len(callContext.contract.Code))
integer = new(uint256.Int)
)
*pc += 1
*pc++
if *pc < codeLen {
callContext.stack.Push(integer.SetUint64(uint64(callContext.contract.Code[*pc])))
} else {
......
......@@ -47,12 +47,14 @@ var (
// ConstantinopleInstructionSet 对应EVM不同版本的指令集,从上往下,从旧版本到新版本,
// 新版本包含旧版本的指令集(目前直接使用康士坦丁堡指令集)
ConstantinopleInstructionSet = NewConstantinopleInstructionSet()
YoloV1InstructionSet = NewYoloV1InstructionSet()
// YoloV1InstructionSet 黄皮书指令集
YoloV1InstructionSet = NewYoloV1InstructionSet()
)
// JumpTable contains the EVM opcodes supported at a given fork.
type JumpTable [256]Operation
// NewYoloV1InstructionSet 黄皮书指令集
func NewYoloV1InstructionSet() JumpTable {
instructionSet := NewConstantinopleInstructionSet()
// New opcode
......@@ -85,6 +87,15 @@ func NewYoloV1InstructionSet() JumpTable {
ValidateStack: mm.MakeStackFunc(0, 1),
Valid: true,
}
// New opcode
instructionSet[EXTCODEHASH] = Operation{
Execute: opExtCodeHash,
GasCost: gas.ConstGasFunc(params.ExtcodeHashGasConstantinople),
ValidateStack: mm.MakeStackFunc(1, 1),
Valid: true,
}
// create2 不支持
// chainID 不支持
return instructionSet
}
......
......@@ -6,7 +6,6 @@ package runtime
import (
"encoding/json"
"errors"
"io"
"math/big"
"time"
......@@ -36,8 +35,6 @@ type JSONLogger struct {
encoder *json.Encoder
}
var errTraceLimitReached = errors.New("the number of logs reached the specified limit")
// Storage represents a contract's storage.
type Storage map[common.Hash]common.Hash
......
......@@ -322,9 +322,9 @@ const (
DIFFICULTY
// GASLIMIT op
GASLIMIT
// CHAINID
// CHAINID op
CHAINID OpCode = 0x46
// SELFBALANCE
// SELFBALANCE op
SELFBALANCE OpCode = 0x47
)
......@@ -516,7 +516,7 @@ const (
RETURN
// DELEGATECALL op
DELEGATECALL
// CREATE2 op
CREATE2
// STATICCALL op
......
......@@ -43,8 +43,8 @@ func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(ExecutorName, ForkEVMABI, 1250000)
// EEVM合约用户金额冻结
cfg.RegisterDappFork(ExecutorName, ForkEVMFrozen, 1300000)
// EEVM 黄皮分叉高度
cfg.RegisterDappFork(ExecutorName, ForkEVMYoloV1, 0)
// EEVM 黄皮v1分叉高度
cfg.RegisterDappFork(ExecutorName, ForkEVMYoloV1, 9500000)
}
//InitExecutor ...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment