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 { ...@@ -206,19 +206,6 @@ func (abi *ABI) overloadedEventName(rawName string) string {
return name 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 // EventByID looks an event up by its topic hash in the
// ABI and returns nil if none found. // ABI and returns nil if none found.
func (abi *ABI) EventByID(topic common.Hash) (*Event, error) { func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
...@@ -255,7 +242,7 @@ func (abi *ABI) MethodByID(sigdata []byte) (*Method, error) { ...@@ -255,7 +242,7 @@ func (abi *ABI) MethodByID(sigdata []byte) (*Method, error) {
} }
var revertSelector = crypto.Keccak256([]byte("Error(string)"))[:4] var revertSelector = crypto.Keccak256([]byte("Error(string)"))[:4]
// UnpackRevert 解包转换为string
func UnpackRevert(data []byte) (string, error) { func UnpackRevert(data []byte) (string, error) {
if len(data) < 4 { if len(data) < 4 {
return "", errors.New("invalid data for unpacking") return "", errors.New("invalid data for unpacking")
......
...@@ -950,7 +950,7 @@ func TestABI_MethodById(t *testing.T) { ...@@ -950,7 +950,7 @@ func TestABI_MethodById(t *testing.T) {
} }
for name, m := range abi.Methods { for name, m := range abi.Methods {
a := fmt.Sprintf("%v", m) a := fmt.Sprintf("%v", m)
m2, err := abi.MethodById(m.ID) m2, err := abi.MethodByID(m.ID)
if err != nil { if err != nil {
t.Fatalf("Failed to look up ABI method: %v", err) t.Fatalf("Failed to look up ABI method: %v", err)
} }
...@@ -960,17 +960,17 @@ func TestABI_MethodById(t *testing.T) { ...@@ -960,17 +960,17 @@ func TestABI_MethodById(t *testing.T) {
} }
} }
// test unsuccessful lookups // 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") t.Error("Expected error: no method with this id")
} }
// Also test empty // 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") 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") 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") t.Errorf("Expected error, nil is short to decode data")
} }
} }
......
...@@ -251,102 +251,6 @@ func str2GoValue(typ Type, val string) (res interface{}, err error) { ...@@ -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" // 例如:"[a,b,c]" -> "a","b","c"
......
...@@ -30,9 +30,10 @@ type Argument struct { ...@@ -30,9 +30,10 @@ type Argument struct {
Type Type Type Type
Indexed bool // indexed is only used by events Indexed bool // indexed is only used by events
} }
// Arguments 参数
type Arguments []Argument type Arguments []Argument
// ArgumentMarshaling 参数数列化结构体
type ArgumentMarshaling struct { type ArgumentMarshaling struct {
Name string Name string
Type string Type string
......
...@@ -173,7 +173,7 @@ func TestEventTupleUnpack(t *testing.T) { ...@@ -173,7 +173,7 @@ func TestEventTupleUnpack(t *testing.T) {
type EventTransferWithTag struct { type EventTransferWithTag struct {
// this is valid because `value` is not exportable, // this is valid because `value` is not exportable,
// so value is only unmarshalled into `Value1`. // 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"` Value1 *big.Int `abi:"value"`
} }
......
...@@ -17,24 +17,8 @@ ...@@ -17,24 +17,8 @@
package abi package abi
import ( import (
"math/big"
"reflect"
"github.com/33cn/plugin/plugin/dapp/evm/executor/vm/common" "github.com/33cn/plugin/plugin/dapp/evm/executor/vm/common"
) "math/big"
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{})
) )
// U256 converts a big Int into a 256bit EVM number. // U256 converts a big Int into a 256bit EVM number.
......
...@@ -155,9 +155,8 @@ func EmptyAddress() Address { return BytesToAddress([]byte{0}) } ...@@ -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. // If s is larger than len(h), s will be cropped from the left.
func HexToAddress(s string) Hash160Address { return BytesToHash160Address(FromHex(s)) } func HexToAddress(s string) Hash160Address { return BytesToHash160Address(FromHex(s)) }
// INTToAddress 大数字转换为地址 // Uint256ToAddress 大数字转换为地址
func Uint256ToAddress(b *uint256.Int) Address { func Uint256ToAddress(b *uint256.Int) Address {
//TODO 这样转换可能与之前的版本不兼容
a := new(address.Address) a := new(address.Address)
a.Version = 0 a.Version = 0
out := make([]byte, 20) out := make([]byte, 20)
...@@ -166,7 +165,7 @@ func Uint256ToAddress(b *uint256.Int) Address { ...@@ -166,7 +165,7 @@ func Uint256ToAddress(b *uint256.Int) Address {
return Address{Addr: a} return Address{Addr: a}
} }
//十六进制转换为虚拟机中的地址 // HexToAddr 十六进制转换为虚拟机中的地址
func HexToAddr(s string) Address { func HexToAddr(s string) Address {
a := new(address.Address) a := new(address.Address)
a.Version = 0 a.Version = 0
......
...@@ -23,13 +23,13 @@ import ( ...@@ -23,13 +23,13 @@ import (
) )
const ( const (
// The blocksize of BLAKE2b in bytes. // BlockSize BLAKE2b的块大小
BlockSize = 128 BlockSize = 128
// The hash size of BLAKE2b-512 in bytes. // Size BLAKE2b-512 hash大小
Size = 64 Size = 64
// The hash size of BLAKE2b-384 in bytes. // Size384 The hash size of BLAKE2b-384 in bytes.
Size384 = 48 Size384 = 48
// The hash size of BLAKE2b-256 in bytes. // Size256 The hash size of BLAKE2b-256 in bytes.
Size256 = 32 Size256 = 32
) )
...@@ -302,18 +302,18 @@ func appendUint64(b []byte, x uint64) []byte { ...@@ -302,18 +302,18 @@ func appendUint64(b []byte, x uint64) []byte {
return append(b, a[:]...) return append(b, a[:]...)
} }
func appendUint32(b []byte, x uint32) []byte { //func appendUint32(b []byte, x uint32) []byte {
var a [4]byte // var a [4]byte
binary.BigEndian.PutUint32(a[:], x) // binary.BigEndian.PutUint32(a[:], x)
return append(b, a[:]...) // return append(b, a[:]...)
} //}
func consumeUint64(b []byte) ([]byte, uint64) { func consumeUint64(b []byte) ([]byte, uint64) {
x := binary.BigEndian.Uint64(b) x := binary.BigEndian.Uint64(b)
return b[8:], x return b[8:], x
} }
func consumeUint32(b []byte) ([]byte, uint32) { //func consumeUint32(b []byte) ([]byte, uint32) {
x := binary.BigEndian.Uint32(b) // x := binary.BigEndian.Uint32(b)
return b[4:], x // return b[4:], x
} //}
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package blake2b package blake2b
import ( import (
"encoding/binary"
"math/bits" "math/bits"
) )
...@@ -25,23 +24,23 @@ var precomputed = [10][16]byte{ ...@@ -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}, {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) { //func hashBlocksGeneric(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
var m [16]uint64 // var m [16]uint64
c0, c1 := c[0], c[1] // c0, c1 := c[0], c[1]
//
for i := 0; i < len(blocks); { // for i := 0; i < len(blocks); {
c0 += BlockSize // c0 += BlockSize
if c0 < BlockSize { // if c0 < BlockSize {
c1++ // c1++
} // }
for j := range m { // for j := range m {
m[j] = binary.LittleEndian.Uint64(blocks[i:]) // m[j] = binary.LittleEndian.Uint64(blocks[i:])
i += 8 // i += 8
} // }
fGeneric(h, &m, c0, c1, flag, 12) // fGeneric(h, &m, c0, c1, flag, 12)
} // }
c[0], c[1] = c0, c1 // c[0], c[1] = c0, c1
} //}
func fGeneric(h *[8]uint64, m *[16]uint64, c0, c1 uint64, flag uint64, rounds uint64) { 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] 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 ( ...@@ -14,13 +14,13 @@ import (
"testing" "testing"
) )
func fromHex(s string) []byte { //func fromHex(s string) []byte {
b, err := hex.DecodeString(s) // b, err := hex.DecodeString(s)
if err != nil { // if err != nil {
panic(err) // panic(err)
} // }
return b // return b
} //}
func TestHashes(t *testing.T) { func TestHashes(t *testing.T) {
defer func(sse4, avx, avx2 bool) { defer func(sse4, avx, avx2 bool) {
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"math/big" "math/big"
) )
var fuz int = 10 var fuz = 10
func randScalar(max *big.Int) *big.Int { func randScalar(max *big.Int) *big.Int {
a, _ := rand.Int(rand.Reader, max) a, _ := rand.Int(rand.Reader, max)
......
...@@ -39,7 +39,7 @@ type fe6 [3]fe2 ...@@ -39,7 +39,7 @@ type fe6 [3]fe2
// Representation follows c[0] + c[1] * w encoding order. // Representation follows c[0] + c[1] * w encoding order.
type fe12 [2]fe6 type fe12 [2]fe6
func (fe *fe) setBytes(in []byte) *fe { func (fe1 *fe) setBytes(in []byte) *fe {
size := 48 size := 48
l := len(in) l := len(in)
if l >= size { if l >= size {
...@@ -50,19 +50,19 @@ func (fe *fe) setBytes(in []byte) *fe { ...@@ -50,19 +50,19 @@ func (fe *fe) setBytes(in []byte) *fe {
var a int var a int
for i := 0; i < 6; i++ { for i := 0; i < 6; i++ {
a = size - i*8 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-3])<<16 | uint64(padded[a-4])<<24 |
uint64(padded[a-5])<<32 | uint64(padded[a-6])<<40 | uint64(padded[a-5])<<32 | uint64(padded[a-6])<<40 |
uint64(padded[a-7])<<48 | uint64(padded[a-8])<<56 uint64(padded[a-7])<<48 | uint64(padded[a-8])<<56
} }
return fe return fe1
} }
func (fe *fe) setBig(a *big.Int) *fe { func (fe1 *fe) setBig(a *big.Int) *fe {
return fe.setBytes(a.Bytes()) 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" { if s[:2] == "0x" {
s = s[2:] s = s[2:]
} }
...@@ -70,129 +70,129 @@ func (fe *fe) setString(s string) (*fe, error) { ...@@ -70,129 +70,129 @@ func (fe *fe) setString(s string) (*fe, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return fe.setBytes(bytes), nil return fe1.setBytes(bytes), nil
} }
func (fe *fe) set(fe2 *fe) *fe { func (fe1 *fe) set(fe2 *fe) *fe {
fe[0] = fe2[0] fe1[0] = fe2[0]
fe[1] = fe2[1] fe1[1] = fe2[1]
fe[2] = fe2[2] fe1[2] = fe2[2]
fe[3] = fe2[3] fe1[3] = fe2[3]
fe[4] = fe2[4] fe1[4] = fe2[4]
fe[5] = fe2[5] fe1[5] = fe2[5]
return fe return fe1
} }
func (fe *fe) bytes() []byte { func (fe1 *fe) bytes() []byte {
out := make([]byte, 48) out := make([]byte, 48)
var a int var a int
for i := 0; i < 6; i++ { for i := 0; i < 6; i++ {
a = 48 - i*8 a = 48 - i*8
out[a-1] = byte(fe[i]) out[a-1] = byte(fe1[i])
out[a-2] = byte(fe[i] >> 8) out[a-2] = byte(fe1[i] >> 8)
out[a-3] = byte(fe[i] >> 16) out[a-3] = byte(fe1[i] >> 16)
out[a-4] = byte(fe[i] >> 24) out[a-4] = byte(fe1[i] >> 24)
out[a-5] = byte(fe[i] >> 32) out[a-5] = byte(fe1[i] >> 32)
out[a-6] = byte(fe[i] >> 40) out[a-6] = byte(fe1[i] >> 40)
out[a-7] = byte(fe[i] >> 48) out[a-7] = byte(fe1[i] >> 48)
out[a-8] = byte(fe[i] >> 56) out[a-8] = byte(fe1[i] >> 56)
} }
return out return out
} }
func (fe *fe) big() *big.Int { func (fe1 *fe) big() *big.Int {
return new(big.Int).SetBytes(fe.bytes()) 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-- { 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 return "0x" + s
} }
func (fe *fe) zero() *fe { func (fe1 *fe) zero() *fe {
fe[0] = 0 fe1[0] = 0
fe[1] = 0 fe1[1] = 0
fe[2] = 0 fe1[2] = 0
fe[3] = 0 fe1[3] = 0
fe[4] = 0 fe1[4] = 0
fe[5] = 0 fe1[5] = 0
return fe return fe1
} }
func (fe *fe) one() *fe { func (fe1 *fe) one() *fe {
return fe.set(r1) 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()) bi, err := rand.Int(r, modulus.big())
if err != nil { if err != nil {
return nil, err return nil, err
} }
return fe.setBig(bi), nil return fe1.setBig(bi), nil
} }
func (fe *fe) isValid() bool { func (fe1 *fe) isValid() bool {
return fe.cmp(&modulus) < 0 return fe1.cmp(&modulus) < 0
} }
func (fe *fe) isOdd() bool { func (fe1 *fe) isOdd() bool {
var mask uint64 = 1 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 var mask uint64 = 1
return fe[0]&mask == 0 return fe1[0]&mask == 0
} }
func (fe *fe) isZero() bool { func (fe1 *fe) isZero() bool {
return (fe[5] | fe[4] | fe[3] | fe[2] | fe[1] | fe[0]) == 0 return (fe1[5] | fe1[4] | fe1[3] | fe1[2] | fe1[1] | fe1[0]) == 0
} }
func (fe *fe) isOne() bool { func (fe1 *fe) isOne() bool {
return fe.equal(r1) return fe1.equal(r1)
} }
func (fe *fe) cmp(fe2 *fe) int { func (fe1 *fe) cmp(fe2 *fe) int {
for i := 5; i >= 0; i-- { for i := 5; i >= 0; i-- {
if fe[i] > fe2[i] { if fe1[i] > fe2[i] {
return 1 return 1
} else if fe[i] < fe2[i] { } else if fe1[i] < fe2[i] {
return -1 return -1
} }
} }
return 0 return 0
} }
func (fe *fe) equal(fe2 *fe) bool { func (fe1 *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] 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) r := new(fe)
fromMont(r, e) fromMont(r, fe1)
return r[0]&1 == 0 return r[0]&1 == 0
} }
func (fe *fe) div2(e uint64) { func (fe1 *fe) div2(e uint64) {
fe[0] = fe[0]>>1 | fe[1]<<63 fe1[0] = fe1[0]>>1 | fe1[1]<<63
fe[1] = fe[1]>>1 | fe[2]<<63 fe1[1] = fe1[1]>>1 | fe1[2]<<63
fe[2] = fe[2]>>1 | fe[3]<<63 fe1[2] = fe1[2]>>1 | fe1[3]<<63
fe[3] = fe[3]>>1 | fe[4]<<63 fe1[3] = fe1[3]>>1 | fe1[4]<<63
fe[4] = fe[4]>>1 | fe[5]<<63 fe1[4] = fe1[4]>>1 | fe1[5]<<63
fe[5] = fe[5]>>1 | e<<63 fe1[5] = fe1[5]>>1 | e<<63
} }
func (fe *fe) mul2() uint64 { func (fe1 *fe) mul2() uint64 {
e := fe[5] >> 63 e := fe1[5] >> 63
fe[5] = fe[5]<<1 | fe[4]>>63 fe1[5] = fe1[5]<<1 | fe1[4]>>63
fe[4] = fe[4]<<1 | fe[3]>>63 fe1[4] = fe1[4]<<1 | fe1[3]>>63
fe[3] = fe[3]<<1 | fe[2]>>63 fe1[3] = fe1[3]<<1 | fe1[2]>>63
fe[2] = fe[2]<<1 | fe[1]>>63 fe1[2] = fe1[2]<<1 | fe1[1]>>63
fe[1] = fe[1]<<1 | fe[0]>>63 fe1[1] = fe1[1]<<1 | fe1[0]>>63
fe[0] = fe[0] << 1 fe1[0] = fe1[0] << 1
return e return e
} }
......
...@@ -127,7 +127,7 @@ func inverse(inv, e *fe) { ...@@ -127,7 +127,7 @@ func inverse(inv, e *fe) {
laddAssign(s, r) laddAssign(s, r)
z += r.mul2() z += r.mul2()
} }
k += 1 k ++
} }
if !found { if !found {
......
...@@ -846,7 +846,7 @@ func TestFp2NonResidue(t *testing.T) { ...@@ -846,7 +846,7 @@ func TestFp2NonResidue(t *testing.T) {
t.Fatal("element is quadratic non residue, 2", i) t.Fatal("element is quadratic non residue, 2", i)
} }
} else { } else {
i -= 1 i --
} }
} }
} }
......
...@@ -27,6 +27,7 @@ import ( ...@@ -27,6 +27,7 @@ import (
// If z is equal to one the point is considered as in affine form. // If z is equal to one the point is considered as in affine form.
type PointG1 [3]fe type PointG1 [3]fe
// Set 设置G1 point
func (p *PointG1) Set(p2 *PointG1) *PointG1 { func (p *PointG1) Set(p2 *PointG1) *PointG1 {
p[0].set(&p2[0]) p[0].set(&p2[0])
p[1].set(&p2[1]) p[1].set(&p2[1])
...@@ -228,7 +229,7 @@ func (g *G1) IsAffine(p *PointG1) bool { ...@@ -228,7 +229,7 @@ func (g *G1) IsAffine(p *PointG1) bool {
return p[2].isOne() 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 { func (g *G1) Affine(p *PointG1) *PointG1 {
if g.IsZero(p) { if g.IsZero(p) {
return p return p
...@@ -266,9 +267,8 @@ func (g *G1) Add(r, p1, p2 *PointG1) *PointG1 { ...@@ -266,9 +267,8 @@ func (g *G1) Add(r, p1, p2 *PointG1) *PointG1 {
if t[1].equal(t[3]) { if t[1].equal(t[3]) {
if t[0].equal(t[2]) { if t[0].equal(t[2]) {
return g.Double(r, p1) return g.Double(r, p1)
} else {
return r.Zero()
} }
return r.Zero()
} }
sub(t[1], t[1], t[3]) sub(t[1], t[1], t[3])
double(t[4], t[1]) double(t[4], t[1])
......
...@@ -29,6 +29,7 @@ type GT struct { ...@@ -29,6 +29,7 @@ type GT struct {
fp12 *fp12 fp12 *fp12
} }
// Set 设置E
func (e *E) Set(e2 *E) *E { func (e *E) Set(e2 *E) *E {
return e.set(e2) return e.set(e2)
} }
...@@ -36,7 +37,8 @@ func (e *E) Set(e2 *E) *E { ...@@ -36,7 +37,8 @@ func (e *E) Set(e2 *E) *E {
// One sets a new target group element to one // One sets a new target group element to one
func (e *E) One() *E { func (e *E) One() *E {
e = new(fe12).one() e = new(fe12).one()
return e var e1 *E = e
return e1
} }
// IsOne returns true if given element equals to one // IsOne returns true if given element equals to one
...@@ -45,8 +47,8 @@ func (e *E) IsOne() bool { ...@@ -45,8 +47,8 @@ func (e *E) IsOne() bool {
} }
// Equal returns true if given two element is equal, otherwise returns false // Equal returns true if given two element is equal, otherwise returns false
func (g *E) Equal(g2 *E) bool { func (e *E) Equal(g2 *E) bool {
return g.equal(g2) return e.equal(g2)
} }
// NewGT constructs new target group instance. // NewGT constructs new target group instance.
...@@ -67,10 +69,11 @@ func (g *GT) FromBytes(in []byte) (*E, error) { ...@@ -67,10 +69,11 @@ func (g *GT) FromBytes(in []byte) (*E, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if !g.IsValid(e) { var e1 *E = e
return e, errors.New("invalid element") if !g.IsValid(e1) {
return e1, errors.New("invalid element")
} }
return e, nil return e1, nil
} }
// ToBytes serializes target group element. // ToBytes serializes target group element.
......
...@@ -272,8 +272,9 @@ func (e *Engine) Check() bool { ...@@ -272,8 +272,9 @@ func (e *Engine) Check() bool {
// Result computes pairing and returns target group element as result. // Result computes pairing and returns target group element as result.
func (e *Engine) Result() *E { func (e *Engine) Result() *E {
r := e.calculate() r := e.calculate()
var r1 *E = r
e.Reset() e.Reset()
return r return r1
} }
// GT returns target group instance. // GT returns target group instance.
......
...@@ -51,21 +51,21 @@ func (g *G1) String() string { ...@@ -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 // ScalarBaseMult sets e to g*k where g is the generator of the group and then
// returns e. // returns e.
func (e *G1) ScalarBaseMult(k *big.Int) *G1 { func (g *G1) ScalarBaseMult(k *big.Int) *G1 {
if e.p == nil { if g.p == nil {
e.p = &curvePoint{} g.p = &curvePoint{}
} }
e.p.Mul(curveGen, k) g.p.Mul(curveGen, k)
return e return g
} }
// ScalarMult sets e to a*k and then returns e. // ScalarMult sets e to a*k and then returns e.
func (e *G1) ScalarMult(a *G1, k *big.Int) *G1 { func (g *G1) ScalarMult(a *G1, k *big.Int) *G1 {
if e.p == nil { if g.p == nil {
e.p = &curvePoint{} g.p = &curvePoint{}
} }
e.p.Mul(a.p, k) g.p.Mul(a.p, k)
return e return g
} }
// Add sets e to a+b and then returns e. // Add sets e to a+b and then returns e.
......
...@@ -5,12 +5,8 @@ package bn256 ...@@ -5,12 +5,8 @@ package bn256
// This file contains forward declarations for the architecture-specific // This file contains forward declarations for the architecture-specific
// assembly implementations of these functions, provided that they exist. // assembly implementations of these functions, provided that they exist.
import (
"golang.org/x/sys/cpu"
)
//nolint:varcheck //nolint:varcheck
var hasBMI2 = cpu.X86.HasBMI2 //var hasBMI2 = cpu.X86.HasBMI2
// go:noescape // go:noescape
func gfpNeg(c, a *gfP) func gfpNeg(c, a *gfP)
......
...@@ -56,9 +56,9 @@ func MemoryCreate(stack *Stack) (uint64, bool) { ...@@ -56,9 +56,9 @@ func MemoryCreate(stack *Stack) (uint64, bool) {
return calcMemSize64(stack.Back(1), stack.Back(2)) return calcMemSize64(stack.Back(1), stack.Back(2))
} }
func memoryCreate2(stack *Stack) (uint64, bool) { //func memoryCreate2(stack *Stack) (uint64, bool) {
return calcMemSize64(stack.Back(1), stack.Back(2)) // return calcMemSize64(stack.Back(1), stack.Back(2))
} //}
//MemoryCall call所需内存大小 //MemoryCall call所需内存大小
func MemoryCall(stack *Stack) (uint64, bool) { func MemoryCall(stack *Stack) (uint64, bool) {
......
...@@ -112,11 +112,12 @@ type ReturnStack struct { ...@@ -112,11 +112,12 @@ type ReturnStack struct {
data []uint32 data []uint32
} }
// ReturnStack 返回栈对象封装,提供常用的返回栈操作 // NewReturnStack 返回栈对象封装,提供常用的返回栈操作
func NewReturnStack() *ReturnStack { func NewReturnStack() *ReturnStack {
return rStackPool.Get().(*ReturnStack) return rStackPool.Get().(*ReturnStack)
} }
// ReturnRStack 将returnStack还给rStackPool
func ReturnRStack(rs *ReturnStack) { func ReturnRStack(rs *ReturnStack) {
rs.data = rs.data[:0] rs.data = rs.data[:0]
rStackPool.Put(rs) rStackPool.Put(rs)
...@@ -126,17 +127,19 @@ func (st *ReturnStack) Push(d uint32) { ...@@ -126,17 +127,19 @@ func (st *ReturnStack) Push(d uint32) {
st.data = append(st.data, d) 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) { func (st *ReturnStack) Pop() (ret uint32) {
ret = st.data[len(st.data)-1] ret = st.data[len(st.data)-1]
st.data = st.data[:len(st.data)-1] st.data = st.data[:len(st.data)-1]
return return
} }
// Len ReturnStack大小
func (st *ReturnStack) Len() int { func (st *ReturnStack) Len() int {
return len(st.data) return len(st.data)
} }
// Data 返回栈中的所有底层数据
func (st *ReturnStack) Data() []uint32 { func (st *ReturnStack) Data() []uint32 {
return st.data return st.data
} }
...@@ -41,8 +41,12 @@ var ( ...@@ -41,8 +41,12 @@ var (
// ErrNoCoinsAccount no coins account in executor! // ErrNoCoinsAccount no coins account in executor!
ErrNoCoinsAccount = errors.New("no coins account in executor") ErrNoCoinsAccount = errors.New("no coins account in executor")
// ErrReturnStackExceeded
ErrReturnStackExceeded = errors.New("return stack limit reached") ErrReturnStackExceeded = errors.New("return stack limit reached")
// ErrInvalidSubroutineEntry
ErrInvalidSubroutineEntry = errors.New("invalid subroutine entry") ErrInvalidSubroutineEntry = errors.New("invalid subroutine entry")
// ErrInvalidJump
ErrInvalidJump = errors.New("invalid jump destination") ErrInvalidJump = errors.New("invalid jump destination")
// ErrInvalidRetsub
ErrInvalidRetsub = errors.New("invalid retsub") ErrInvalidRetsub = errors.New("invalid retsub")
) )
...@@ -7,21 +7,23 @@ package params ...@@ -7,21 +7,23 @@ package params
import "math/big" import "math/big"
const ( const (
GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations. //GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations.
MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be. //MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be.
GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block. //GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block.
//
MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis. //MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis.
ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction. //ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction.
SloadGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added. //SloadGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added.
CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero.
CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior. CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero.
TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions. CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior.
TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions. TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions.
TxDataZeroGas uint64 = 4 // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions. //TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions.
QuadCoeffDiv uint64 = 512 // Divisor for the quadratic particle of the memory cost equation. //TxDataZeroGas uint64 = 4 // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions.
LogDataGas uint64 = 8 // Per byte in a LOG* operation's data.
CallStipend uint64 = 2300 // Free gas given at beginning of call. QuadCoeffDiv uint64 = 512 // Divisor for the quadratic particle of the memory cost equation.
LogDataGas uint64 = 8 // Per byte in a LOG* operation's data.
CallStipend uint64 = 2300 // Free gas given at beginning of call.
Sha3Gas uint64 = 30 // Once per SHA3 operation. Sha3Gas uint64 = 30 // Once per SHA3 operation.
Sha3WordGas uint64 = 6 // Once per word of the SHA3 operation's data. Sha3WordGas uint64 = 6 // Once per word of the SHA3 operation's data.
...@@ -31,71 +33,72 @@ const ( ...@@ -31,71 +33,72 @@ const (
SstoreClearGas uint64 = 5000 // Once per SSTORE operation if the zeroness doesn't change. SstoreClearGas uint64 = 5000 // Once per SSTORE operation if the zeroness doesn't change.
SstoreRefundGas uint64 = 15000 // Once per SSTORE operation if the zeroness changes to zero. SstoreRefundGas uint64 = 15000 // Once per SSTORE operation if the zeroness changes to zero.
NetSstoreNoopGas uint64 = 200 // Once per SSTORE operation if the value doesn't change. //NetSstoreNoopGas uint64 = 200 // Once per SSTORE operation if the value doesn't change.
NetSstoreInitGas uint64 = 20000 // Once per SSTORE operation from clean zero. //NetSstoreInitGas uint64 = 20000 // Once per SSTORE operation from clean zero.
NetSstoreCleanGas uint64 = 5000 // Once per SSTORE operation from clean non-zero. //NetSstoreCleanGas uint64 = 5000 // Once per SSTORE operation from clean non-zero.
NetSstoreDirtyGas uint64 = 200 // Once per SSTORE operation from dirty. //NetSstoreDirtyGas uint64 = 200 // Once per SSTORE operation from dirty.
//
NetSstoreClearRefund uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot //NetSstoreClearRefund uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot
NetSstoreResetRefund uint64 = 4800 // Once per SSTORE operation for resetting to the original non-zero value //NetSstoreResetRefund uint64 = 4800 // Once per SSTORE operation for resetting to the original non-zero value
NetSstoreResetClearRefund uint64 = 19800 // Once per SSTORE operation for resetting to the original zero value //NetSstoreResetClearRefund uint64 = 19800 // Once per SSTORE operation for resetting to the original zero value
//
SstoreSentryGasEIP2200 uint64 = 2300 // Minimum gas required to be present for an SSTORE call, not consumed //SstoreSentryGasEIP2200 uint64 = 2300 // Minimum gas required to be present for an SSTORE call, not consumed
SstoreNoopGasEIP2200 uint64 = 800 // Once per SSTORE operation if the value doesn't change. //SstoreNoopGasEIP2200 uint64 = 800 // Once per SSTORE operation if the value doesn't change.
SstoreDirtyGasEIP2200 uint64 = 800 // Once per SSTORE operation if a dirty value is changed. //SstoreDirtyGasEIP2200 uint64 = 800 // Once per SSTORE operation if a dirty value is changed.
SstoreInitGasEIP2200 uint64 = 20000 // Once per SSTORE operation from clean zero to non-zero //SstoreInitGasEIP2200 uint64 = 20000 // Once per SSTORE operation from clean zero to non-zero
SstoreInitRefundEIP2200 uint64 = 19200 // Once per SSTORE operation for resetting to the original zero value //SstoreInitRefundEIP2200 uint64 = 19200 // Once per SSTORE operation for resetting to the original zero value
SstoreCleanGasEIP2200 uint64 = 5000 // Once per SSTORE operation from clean non-zero to something else //SstoreCleanGasEIP2200 uint64 = 5000 // Once per SSTORE operation from clean non-zero to something else
SstoreCleanRefundEIP2200 uint64 = 4200 // Once per SSTORE operation for resetting to the original non-zero value //SstoreCleanRefundEIP2200 uint64 = 4200 // Once per SSTORE operation for resetting to the original non-zero value
SstoreClearRefundEIP2200 uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot //SstoreClearRefundEIP2200 uint64 = 15000 // Once per SSTORE operation for clearing an originally existing storage slot
JumpdestGas uint64 = 1 // Once per JUMPDEST operation. JumpdestGas uint64 = 1 // Once per JUMPDEST operation.
EpochDuration uint64 = 30000 // Duration between proof-of-work epochs. //EpochDuration uint64 = 30000 // Duration between proof-of-work epochs.
CreateDataGas uint64 = 200 // CreateDataGas uint64 = 200 //
CallCreateDepth uint64 = 1024 // Maximum depth of call/create stack. CallCreateDepth uint64 = 1024 // Maximum depth of call/create stack.
ExpGas uint64 = 10 // Once per EXP instruction //ExpGas uint64 = 10 // Once per EXP instruction
LogGas uint64 = 375 // Per LOG* operation.
CopyGas uint64 = 3 // LogGas uint64 = 375 // Per LOG* operation.
StackLimit uint64 = 1024 // Maximum size of VM stack allowed. CopyGas uint64 = 3 //
TierStepGas uint64 = 0 // Once per operation, for a selection of them. StackLimit uint64 = 1024 // Maximum size of VM stack allowed.
LogTopicGas uint64 = 375 // Multiplied by the * of the LOG*, per LOG transaction. e.g. LOG0 incurs 0 * c_txLogTopicGas, LOG4 incurs 4 * c_txLogTopicGas. //TierStepGas uint64 = 0 // Once per operation, for a selection of them.
CreateGas uint64 = 32000 // Once per CREATE operation & contract-creation transaction. LogTopicGas uint64 = 375 // Multiplied by the * of the LOG*, per LOG transaction. e.g. LOG0 incurs 0 * c_txLogTopicGas, LOG4 incurs 4 * c_txLogTopicGas.
Create2Gas uint64 = 32000 // Once per CREATE2 operation CreateGas uint64 = 32000 // Once per CREATE operation & contract-creation transaction.
SelfdestructRefundGas uint64 = 24000 // Refunded following a selfdestruct operation. //Create2Gas uint64 = 32000 // Once per CREATE2 operation
MemoryGas uint64 = 3 // Times the address of the (highest referenced byte in memory + 1). NOTE: referencing happens on read, write and in instructions such as RETURN and CALL. SelfdestructRefundGas uint64 = 24000 // Refunded following a selfdestruct operation.
TxDataNonZeroGasFrontier uint64 = 68 // Per byte of data attached to a transaction that is not equal to zero. NOTE: Not payable on data of calls between transactions. MemoryGas uint64 = 3 // Times the address of the (highest referenced byte in memory + 1). NOTE: referencing happens on read, write and in instructions such as RETURN and CALL.
TxDataNonZeroGasEIP2028 uint64 = 16 // Per byte of non zero data attached to a transaction after EIP 2028 (part in Istanbul) //TxDataNonZeroGasFrontier uint64 = 68 // Per byte of data attached to a transaction that is not equal to zero. NOTE: Not payable on data of calls between transactions.
//TxDataNonZeroGasEIP2028 uint64 = 16 // Per byte of non zero data attached to a transaction after EIP 2028 (part in Istanbul)
// These have been changed during the course of the chain //
CallGasFrontier uint64 = 40 // Once per CALL operation & message call transaction. //// These have been changed during the course of the chain
CallGasEIP150 uint64 = 700 // Static portion of gas for CALL-derivates after EIP 150 (Tangerine) //CallGasFrontier uint64 = 40 // Once per CALL operation & message call transaction.
BalanceGasFrontier uint64 = 20 // The cost of a BALANCE operation //CallGasEIP150 uint64 = 700 // Static portion of gas for CALL-derivates after EIP 150 (Tangerine)
BalanceGasEIP150 uint64 = 400 // The cost of a BALANCE operation after Tangerine //BalanceGasFrontier uint64 = 20 // The cost of a BALANCE operation
BalanceGasEIP1884 uint64 = 700 // The cost of a BALANCE operation after EIP 1884 (part of Istanbul) //BalanceGasEIP150 uint64 = 400 // The cost of a BALANCE operation after Tangerine
ExtcodeSizeGasFrontier uint64 = 20 // Cost of EXTCODESIZE before EIP 150 (Tangerine) //BalanceGasEIP1884 uint64 = 700 // The cost of a BALANCE operation after EIP 1884 (part of Istanbul)
ExtcodeSizeGasEIP150 uint64 = 700 // Cost of EXTCODESIZE after EIP 150 (Tangerine) //ExtcodeSizeGasFrontier uint64 = 20 // Cost of EXTCODESIZE before EIP 150 (Tangerine)
SloadGasFrontier uint64 = 50 //ExtcodeSizeGasEIP150 uint64 = 700 // Cost of EXTCODESIZE after EIP 150 (Tangerine)
SloadGasEIP150 uint64 = 200 //SloadGasFrontier uint64 = 50
SloadGasEIP1884 uint64 = 800 // Cost of SLOAD after EIP 1884 (part of Istanbul) //SloadGasEIP150 uint64 = 200
SloadGasEIP2200 uint64 = 800 // Cost of SLOAD after EIP 2200 (part of Istanbul) //SloadGasEIP1884 uint64 = 800 // Cost of SLOAD after EIP 1884 (part of Istanbul)
//SloadGasEIP2200 uint64 = 800 // Cost of SLOAD after EIP 2200 (part of Istanbul)
ExtcodeHashGasConstantinople uint64 = 400 // Cost of EXTCODEHASH (introduced in Constantinople) ExtcodeHashGasConstantinople uint64 = 400 // Cost of EXTCODEHASH (introduced in Constantinople)
ExtcodeHashGasEIP1884 uint64 = 700 // Cost of EXTCODEHASH after EIP 1884 (part in Istanbul) //ExtcodeHashGasEIP1884 uint64 = 700 // Cost of EXTCODEHASH after EIP 1884 (part in Istanbul)
SelfdestructGasEIP150 uint64 = 5000 // Cost of SELFDESTRUCT post EIP 150 (Tangerine) //SelfdestructGasEIP150 uint64 = 5000 // Cost of SELFDESTRUCT post EIP 150 (Tangerine)
//
// EXP has a dynamic portion depending on the size of the exponent //// EXP has a dynamic portion depending on the size of the exponent
ExpByteFrontier uint64 = 10 // was set to 10 in Frontier //ExpByteFrontier uint64 = 10 // was set to 10 in Frontier
ExpByteEIP158 uint64 = 50 // was raised to 50 during Eip158 (Spurious Dragon) //ExpByteEIP158 uint64 = 50 // was raised to 50 during Eip158 (Spurious Dragon)
//
// Extcodecopy has a dynamic AND a static cost. This represents only the //// Extcodecopy has a dynamic AND a static cost. This represents only the
// static portion of the gas. It was changed during EIP 150 (Tangerine) //// static portion of the gas. It was changed during EIP 150 (Tangerine)
ExtcodeCopyBaseFrontier uint64 = 20 //ExtcodeCopyBaseFrontier uint64 = 20
ExtcodeCopyBaseEIP150 uint64 = 700 //ExtcodeCopyBaseEIP150 uint64 = 700
//
// CreateBySelfdestructGas is used when the refunded account is one that does //// CreateBySelfdestructGas is used when the refunded account is one that does
// not exist. This logic is similar to call. //// not exist. This logic is similar to call.
// Introduced in Tangerine Whistle (Eip 150) //// Introduced in Tangerine Whistle (Eip 150)
CreateBySelfdestructGas uint64 = 25000 //CreateBySelfdestructGas uint64 = 25000
MaxCodeSize = 24576 // Maximum bytecode to permit for a contract MaxCodeSize = 24576 // Maximum bytecode to permit for a contract
...@@ -133,8 +136,12 @@ const ( ...@@ -133,8 +136,12 @@ const (
var Bls12381MultiExpDiscountTable = [128]uint64{1200, 888, 764, 641, 594, 547, 500, 453, 438, 423, 408, 394, 379, 364, 349, 334, 330, 326, 322, 318, 314, 310, 306, 302, 298, 294, 289, 285, 281, 277, 273, 269, 268, 266, 265, 263, 262, 260, 259, 257, 256, 254, 253, 251, 250, 248, 247, 245, 244, 242, 241, 239, 238, 236, 235, 233, 232, 231, 229, 228, 226, 225, 223, 222, 221, 220, 219, 219, 218, 217, 216, 216, 215, 214, 213, 213, 212, 211, 211, 210, 209, 208, 208, 207, 206, 205, 205, 204, 203, 202, 202, 201, 200, 199, 199, 198, 197, 196, 196, 195, 194, 193, 193, 192, 191, 191, 190, 189, 188, 188, 187, 186, 185, 185, 184, 183, 182, 182, 181, 180, 179, 179, 178, 177, 176, 176, 175, 174} var Bls12381MultiExpDiscountTable = [128]uint64{1200, 888, 764, 641, 594, 547, 500, 453, 438, 423, 408, 394, 379, 364, 349, 334, 330, 326, 322, 318, 314, 310, 306, 302, 298, 294, 289, 285, 281, 277, 273, 269, 268, 266, 265, 263, 262, 260, 259, 257, 256, 254, 253, 251, 250, 248, 247, 245, 244, 242, 241, 239, 238, 236, 235, 233, 232, 231, 229, 228, 226, 225, 223, 222, 221, 220, 219, 219, 218, 217, 216, 216, 215, 214, 213, 213, 212, 211, 211, 210, 209, 208, 208, 207, 206, 205, 205, 204, 203, 202, 202, 201, 200, 199, 199, 198, 197, 196, 196, 195, 194, 193, 193, 192, 191, 191, 190, 189, 188, 188, 187, 186, 185, 185, 184, 183, 182, 182, 181, 180, 179, 179, 178, 177, 176, 176, 175, 174}
var ( var (
DifficultyBoundDivisor = big.NewInt(2048) // The bound divisor of the difficulty, used in the update calculations. // DifficultyBoundDivisor The bound divisor of the difficulty, used in the update calculations.
GenesisDifficulty = big.NewInt(131072) // Difficulty of the Genesis block. DifficultyBoundDivisor = big.NewInt(2048)
MinimumDifficulty = big.NewInt(131072) // The minimum that the difficulty may ever be. // GenesisDifficulty Difficulty of the Genesis block.
DurationLimit = big.NewInt(13) // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not. GenesisDifficulty = big.NewInt(131072)
// MinimumDifficulty The minimum that the difficulty may ever be.
MinimumDifficulty = big.NewInt(131072)
// DurationLimit The decision boundary on the blocktime duration used to determine whether difficulty should go up or not.
DurationLimit = big.NewInt(13)
) )
...@@ -843,7 +843,7 @@ func opPush1(pc *uint64, evm *EVM, callContext *callCtx) ([]byte, error) { ...@@ -843,7 +843,7 @@ func opPush1(pc *uint64, evm *EVM, callContext *callCtx) ([]byte, error) {
codeLen = uint64(len(callContext.contract.Code)) codeLen = uint64(len(callContext.contract.Code))
integer = new(uint256.Int) integer = new(uint256.Int)
) )
*pc += 1 *pc++
if *pc < codeLen { if *pc < codeLen {
callContext.stack.Push(integer.SetUint64(uint64(callContext.contract.Code[*pc]))) callContext.stack.Push(integer.SetUint64(uint64(callContext.contract.Code[*pc])))
} else { } else {
......
...@@ -47,12 +47,14 @@ var ( ...@@ -47,12 +47,14 @@ var (
// ConstantinopleInstructionSet 对应EVM不同版本的指令集,从上往下,从旧版本到新版本, // ConstantinopleInstructionSet 对应EVM不同版本的指令集,从上往下,从旧版本到新版本,
// 新版本包含旧版本的指令集(目前直接使用康士坦丁堡指令集) // 新版本包含旧版本的指令集(目前直接使用康士坦丁堡指令集)
ConstantinopleInstructionSet = NewConstantinopleInstructionSet() ConstantinopleInstructionSet = NewConstantinopleInstructionSet()
YoloV1InstructionSet = NewYoloV1InstructionSet() // YoloV1InstructionSet 黄皮书指令集
YoloV1InstructionSet = NewYoloV1InstructionSet()
) )
// JumpTable contains the EVM opcodes supported at a given fork. // JumpTable contains the EVM opcodes supported at a given fork.
type JumpTable [256]Operation type JumpTable [256]Operation
// NewYoloV1InstructionSet 黄皮书指令集
func NewYoloV1InstructionSet() JumpTable { func NewYoloV1InstructionSet() JumpTable {
instructionSet := NewConstantinopleInstructionSet() instructionSet := NewConstantinopleInstructionSet()
// New opcode // New opcode
...@@ -85,6 +87,15 @@ func NewYoloV1InstructionSet() JumpTable { ...@@ -85,6 +87,15 @@ func NewYoloV1InstructionSet() JumpTable {
ValidateStack: mm.MakeStackFunc(0, 1), ValidateStack: mm.MakeStackFunc(0, 1),
Valid: true, 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 return instructionSet
} }
......
...@@ -6,7 +6,6 @@ package runtime ...@@ -6,7 +6,6 @@ package runtime
import ( import (
"encoding/json" "encoding/json"
"errors"
"io" "io"
"math/big" "math/big"
"time" "time"
...@@ -36,8 +35,6 @@ type JSONLogger struct { ...@@ -36,8 +35,6 @@ type JSONLogger struct {
encoder *json.Encoder encoder *json.Encoder
} }
var errTraceLimitReached = errors.New("the number of logs reached the specified limit")
// Storage represents a contract's storage. // Storage represents a contract's storage.
type Storage map[common.Hash]common.Hash type Storage map[common.Hash]common.Hash
......
...@@ -322,9 +322,9 @@ const ( ...@@ -322,9 +322,9 @@ const (
DIFFICULTY DIFFICULTY
// GASLIMIT op // GASLIMIT op
GASLIMIT GASLIMIT
// CHAINID // CHAINID op
CHAINID OpCode = 0x46 CHAINID OpCode = 0x46
// SELFBALANCE // SELFBALANCE op
SELFBALANCE OpCode = 0x47 SELFBALANCE OpCode = 0x47
) )
...@@ -516,7 +516,7 @@ const ( ...@@ -516,7 +516,7 @@ const (
RETURN RETURN
// DELEGATECALL op // DELEGATECALL op
DELEGATECALL DELEGATECALL
// CREATE2 op
CREATE2 CREATE2
// STATICCALL op // STATICCALL op
......
...@@ -43,8 +43,8 @@ func InitFork(cfg *types.Chain33Config) { ...@@ -43,8 +43,8 @@ func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(ExecutorName, ForkEVMABI, 1250000) cfg.RegisterDappFork(ExecutorName, ForkEVMABI, 1250000)
// EEVM合约用户金额冻结 // EEVM合约用户金额冻结
cfg.RegisterDappFork(ExecutorName, ForkEVMFrozen, 1300000) cfg.RegisterDappFork(ExecutorName, ForkEVMFrozen, 1300000)
// EEVM 黄皮分叉高度 // EEVM 黄皮v1分叉高度
cfg.RegisterDappFork(ExecutorName, ForkEVMYoloV1, 0) cfg.RegisterDappFork(ExecutorName, ForkEVMYoloV1, 9500000)
} }
//InitExecutor ... //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