Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
c9ec7b28
Commit
c9ec7b28
authored
Jul 30, 2020
by
harrylee
Committed by
33cn
Aug 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make linter
parent
4e6ee9d0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
179 additions
and
290 deletions
+179
-290
abi.go
plugin/dapp/evm/executor/abi/abi.go
+1
-14
abi_test.go
plugin/dapp/evm/executor/abi/abi_test.go
+5
-5
api.go
plugin/dapp/evm/executor/abi/api.go
+0
-96
argument.go
plugin/dapp/evm/executor/abi/argument.go
+2
-1
event_test.go
plugin/dapp/evm/executor/abi/event_test.go
+1
-1
numbers.go
plugin/dapp/evm/executor/abi/numbers.go
+1
-17
address.go
plugin/dapp/evm/executor/vm/common/address.go
+2
-3
blake2b.go
plugin/dapp/evm/executor/vm/common/crypto/blake2b/blake2b.go
+13
-13
blake2b_generic.go
.../evm/executor/vm/common/crypto/blake2b/blake2b_generic.go
+17
-18
blake2b_test.go
...app/evm/executor/vm/common/crypto/blake2b/blake2b_test.go
+7
-7
bls12_381_test.go
.../evm/executor/vm/common/crypto/bls12381/bls12_381_test.go
+1
-1
field_element.go
...p/evm/executor/vm/common/crypto/bls12381/field_element.go
+72
-72
fp.go
plugin/dapp/evm/executor/vm/common/crypto/bls12381/fp.go
+1
-1
fp_test.go
...in/dapp/evm/executor/vm/common/crypto/bls12381/fp_test.go
+1
-1
g1.go
plugin/dapp/evm/executor/vm/common/crypto/bls12381/g1.go
+3
-3
gt.go
plugin/dapp/evm/executor/vm/common/crypto/bls12381/gt.go
+9
-6
pairing.go
...in/dapp/evm/executor/vm/common/crypto/bls12381/pairing.go
+2
-1
bn256.go
...p/evm/executor/vm/common/crypto/bn256/cloudflare/bn256.go
+10
-10
gfp_decl.go
...vm/executor/vm/common/crypto/bn256/cloudflare/gfp_decl.go
+1
-5
memory_table.go
plugin/dapp/evm/executor/vm/mm/memory_table.go
+3
-3
stack.go
plugin/dapp/evm/executor/vm/mm/stack.go
+5
-2
errors.go
plugin/dapp/evm/executor/vm/model/errors.go
+4
-0
protocol_params.go
plugin/dapp/evm/executor/vm/params/protocol_params.go
+0
-0
instructions.go
plugin/dapp/evm/executor/vm/runtime/instructions.go
+1
-1
jump_table.go
plugin/dapp/evm/executor/vm/runtime/jump_table.go
+12
-1
logger.go
plugin/dapp/evm/executor/vm/runtime/logger.go
+0
-3
opcodes.go
plugin/dapp/evm/executor/vm/runtime/opcodes.go
+3
-3
evm.go
plugin/dapp/evm/types/evm.go
+2
-2
No files found.
plugin/dapp/evm/executor/abi/abi.go
View file @
c9ec7b28
...
...
@@ -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"
)
...
...
plugin/dapp/evm/executor/abi/abi_test.go
View file @
c9ec7b28
...
...
@@ -950,7 +950,7 @@ func TestABI_MethodById(t *testing.T) {
}
for
name
,
m
:=
range
abi
.
Methods
{
a
:=
fmt
.
Sprintf
(
"%v"
,
m
)
m2
,
err
:=
abi
.
MethodByI
d
(
m
.
ID
)
m2
,
err
:=
abi
.
MethodByI
D
(
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
.
MethodByI
d
(
crypto
.
Keccak256
());
err
==
nil
{
if
_
,
err
=
abi
.
MethodByI
D
(
crypto
.
Keccak256
());
err
==
nil
{
t
.
Error
(
"Expected error: no method with this id"
)
}
// Also test empty
if
_
,
err
:=
abi
.
MethodByI
d
([]
byte
{
0x00
});
err
==
nil
{
if
_
,
err
:=
abi
.
MethodByI
D
([]
byte
{
0x00
});
err
==
nil
{
t
.
Errorf
(
"Expected error, too short to decode data"
)
}
if
_
,
err
:=
abi
.
MethodByI
d
([]
byte
{});
err
==
nil
{
if
_
,
err
:=
abi
.
MethodByI
D
([]
byte
{});
err
==
nil
{
t
.
Errorf
(
"Expected error, too short to decode data"
)
}
if
_
,
err
:=
abi
.
MethodByI
d
(
nil
);
err
==
nil
{
if
_
,
err
:=
abi
.
MethodByI
D
(
nil
);
err
==
nil
{
t
.
Errorf
(
"Expected error, nil is short to decode data"
)
}
}
...
...
plugin/dapp/evm/executor/abi/api.go
View file @
c9ec7b28
...
...
@@ -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"
...
...
plugin/dapp/evm/executor/abi/argument.go
View file @
c9ec7b28
...
...
@@ -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
...
...
plugin/dapp/evm/executor/abi/event_test.go
View file @
c9ec7b28
...
...
@@ -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"`
}
...
...
plugin/dapp/evm/executor/abi/numbers.go
View file @
c9ec7b28
...
...
@@ -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.
...
...
plugin/dapp/evm/executor/vm/common/address.go
View file @
c9ec7b28
...
...
@@ -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
))
}
//
INT
ToAddress 大数字转换为地址
//
Uint256
ToAddress 大数字转换为地址
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
...
...
plugin/dapp/evm/executor/vm/common/crypto/blake2b/blake2b.go
View file @
c9ec7b28
...
...
@@ -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
//
}
plugin/dapp/evm/executor/vm/common/crypto/blake2b/blake2b_generic.go
View file @
c9ec7b28
...
...
@@ -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
]
...
...
plugin/dapp/evm/executor/vm/common/crypto/blake2b/blake2b_test.go
View file @
c9ec7b28
...
...
@@ -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
)
{
...
...
plugin/dapp/evm/executor/vm/common/crypto/bls12381/bls12_381_test.go
View file @
c9ec7b28
...
...
@@ -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
)
...
...
plugin/dapp/evm/executor/vm/common/crypto/bls12381/field_element.go
View file @
c9ec7b28
...
...
@@ -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
(
fe
1
*
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
|
fe
1
[
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
fe
1
}
func
(
fe
*
fe
)
setBig
(
a
*
big
.
Int
)
*
fe
{
return
fe
.
setBytes
(
a
.
Bytes
())
func
(
fe
1
*
fe
)
setBig
(
a
*
big
.
Int
)
*
fe
{
return
fe
1
.
setBytes
(
a
.
Bytes
())
}
func
(
fe
*
fe
)
setString
(
s
string
)
(
*
fe
,
error
)
{
func
(
fe
1
*
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
fe
1
.
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
(
fe
1
*
fe
)
set
(
fe2
*
fe
)
*
fe
{
fe
1
[
0
]
=
fe2
[
0
]
fe
1
[
1
]
=
fe2
[
1
]
fe
1
[
2
]
=
fe2
[
2
]
fe
1
[
3
]
=
fe2
[
3
]
fe
1
[
4
]
=
fe2
[
4
]
fe
1
[
5
]
=
fe2
[
5
]
return
fe
1
}
func
(
fe
*
fe
)
bytes
()
[]
byte
{
func
(
fe
1
*
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
(
fe
1
[
i
])
out
[
a
-
2
]
=
byte
(
fe
1
[
i
]
>>
8
)
out
[
a
-
3
]
=
byte
(
fe
1
[
i
]
>>
16
)
out
[
a
-
4
]
=
byte
(
fe
1
[
i
]
>>
24
)
out
[
a
-
5
]
=
byte
(
fe
1
[
i
]
>>
32
)
out
[
a
-
6
]
=
byte
(
fe
1
[
i
]
>>
40
)
out
[
a
-
7
]
=
byte
(
fe
1
[
i
]
>>
48
)
out
[
a
-
8
]
=
byte
(
fe
1
[
i
]
>>
56
)
}
return
out
}
func
(
fe
*
fe
)
big
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
SetBytes
(
fe
.
bytes
())
func
(
fe
1
*
fe
)
big
()
*
big
.
Int
{
return
new
(
big
.
Int
)
.
SetBytes
(
fe
1
.
bytes
())
}
func
(
fe
*
fe
)
string
()
(
s
string
)
{
func
(
fe
1
*
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
,
fe
1
[
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
(
fe
1
*
fe
)
zero
()
*
fe
{
fe
1
[
0
]
=
0
fe
1
[
1
]
=
0
fe
1
[
2
]
=
0
fe
1
[
3
]
=
0
fe
1
[
4
]
=
0
fe
1
[
5
]
=
0
return
fe
1
}
func
(
fe
*
fe
)
one
()
*
fe
{
return
fe
.
set
(
r1
)
func
(
fe
1
*
fe
)
one
()
*
fe
{
return
fe
1
.
set
(
r1
)
}
func
(
fe
*
fe
)
rand
(
r
io
.
Reader
)
(
*
fe
,
error
)
{
func
(
fe
1
*
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
fe
1
.
setBig
(
bi
),
nil
}
func
(
fe
*
fe
)
isValid
()
bool
{
return
fe
.
cmp
(
&
modulus
)
<
0
func
(
fe
1
*
fe
)
isValid
()
bool
{
return
fe
1
.
cmp
(
&
modulus
)
<
0
}
func
(
fe
*
fe
)
isOdd
()
bool
{
func
(
fe
1
*
fe
)
isOdd
()
bool
{
var
mask
uint64
=
1
return
fe
[
0
]
&
mask
!=
0
return
fe
1
[
0
]
&
mask
!=
0
}
func
(
fe
*
fe
)
isEven
()
bool
{
func
(
fe
1
*
fe
)
isEven
()
bool
{
var
mask
uint64
=
1
return
fe
[
0
]
&
mask
==
0
return
fe
1
[
0
]
&
mask
==
0
}
func
(
fe
*
fe
)
isZero
()
bool
{
return
(
fe
[
5
]
|
fe
[
4
]
|
fe
[
3
]
|
fe
[
2
]
|
fe
[
1
]
|
fe
[
0
])
==
0
func
(
fe
1
*
fe
)
isZero
()
bool
{
return
(
fe
1
[
5
]
|
fe1
[
4
]
|
fe1
[
3
]
|
fe1
[
2
]
|
fe1
[
1
]
|
fe1
[
0
])
==
0
}
func
(
fe
*
fe
)
isOne
()
bool
{
return
fe
.
equal
(
r1
)
func
(
fe
1
*
fe
)
isOne
()
bool
{
return
fe
1
.
equal
(
r1
)
}
func
(
fe
*
fe
)
cmp
(
fe2
*
fe
)
int
{
func
(
fe
1
*
fe
)
cmp
(
fe2
*
fe
)
int
{
for
i
:=
5
;
i
>=
0
;
i
--
{
if
fe
[
i
]
>
fe2
[
i
]
{
if
fe
1
[
i
]
>
fe2
[
i
]
{
return
1
}
else
if
fe
[
i
]
<
fe2
[
i
]
{
}
else
if
fe
1
[
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
(
fe
1
*
fe
)
equal
(
fe2
*
fe
)
bool
{
return
fe2
[
0
]
==
fe
1
[
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
(
fe
1
*
fe
)
div2
(
e
uint64
)
{
fe
1
[
0
]
=
fe1
[
0
]
>>
1
|
fe1
[
1
]
<<
63
fe
1
[
1
]
=
fe1
[
1
]
>>
1
|
fe1
[
2
]
<<
63
fe
1
[
2
]
=
fe1
[
2
]
>>
1
|
fe1
[
3
]
<<
63
fe
1
[
3
]
=
fe1
[
3
]
>>
1
|
fe1
[
4
]
<<
63
fe
1
[
4
]
=
fe1
[
4
]
>>
1
|
fe1
[
5
]
<<
63
fe
1
[
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
(
fe
1
*
fe
)
mul2
()
uint64
{
e
:=
fe
1
[
5
]
>>
63
fe
1
[
5
]
=
fe1
[
5
]
<<
1
|
fe1
[
4
]
>>
63
fe
1
[
4
]
=
fe1
[
4
]
<<
1
|
fe1
[
3
]
>>
63
fe
1
[
3
]
=
fe1
[
3
]
<<
1
|
fe1
[
2
]
>>
63
fe
1
[
2
]
=
fe1
[
2
]
<<
1
|
fe1
[
1
]
>>
63
fe
1
[
1
]
=
fe1
[
1
]
<<
1
|
fe1
[
0
]
>>
63
fe
1
[
0
]
=
fe1
[
0
]
<<
1
return
e
}
...
...
plugin/dapp/evm/executor/vm/common/crypto/bls12381/fp.go
View file @
c9ec7b28
...
...
@@ -127,7 +127,7 @@ func inverse(inv, e *fe) {
laddAssign
(
s
,
r
)
z
+=
r
.
mul2
()
}
k
+
=
1
k
+
+
}
if
!
found
{
...
...
plugin/dapp/evm/executor/vm/common/crypto/bls12381/fp_test.go
View file @
c9ec7b28
...
...
@@ -846,7 +846,7 @@ func TestFp2NonResidue(t *testing.T) {
t
.
Fatal
(
"element is quadratic non residue, 2"
,
i
)
}
}
else
{
i
-
=
1
i
-
-
}
}
}
...
...
plugin/dapp/evm/executor/vm/common/crypto/bls12381/g1.go
View file @
c9ec7b28
...
...
@@ -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.
// A
ffine A
dd 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
])
...
...
plugin/dapp/evm/executor/vm/common/crypto/bls12381/gt.go
View file @
c9ec7b28
...
...
@@ -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
e
1
,
nil
}
// ToBytes serializes target group element.
...
...
plugin/dapp/evm/executor/vm/common/crypto/bls12381/pairing.go
View file @
c9ec7b28
...
...
@@ -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
r
1
}
// GT returns target group instance.
...
...
plugin/dapp/evm/executor/vm/common/crypto/bn256/cloudflare/bn256.go
View file @
c9ec7b28
...
...
@@ -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.
...
...
plugin/dapp/evm/executor/vm/common/crypto/bn256/cloudflare/gfp_decl.go
View file @
c9ec7b28
...
...
@@ -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
)
...
...
plugin/dapp/evm/executor/vm/mm/memory_table.go
View file @
c9ec7b28
...
...
@@ -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
)
{
...
...
plugin/dapp/evm/executor/vm/mm/stack.go
View file @
c9ec7b28
...
...
@@ -112,11 +112,12 @@ type ReturnStack struct {
data
[]
uint32
}
// ReturnStack 返回栈对象封装,提供常用的返回栈操作
//
New
ReturnStack 返回栈对象封装,提供常用的返回栈操作
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
}
plugin/dapp/evm/executor/vm/model/errors.go
View file @
c9ec7b28
...
...
@@ -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"
)
)
plugin/dapp/evm/executor/vm/params/protocol_params.go
View file @
c9ec7b28
This diff is collapsed.
Click to expand it.
plugin/dapp/evm/executor/vm/runtime/instructions.go
View file @
c9ec7b28
...
...
@@ -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
{
...
...
plugin/dapp/evm/executor/vm/runtime/jump_table.go
View file @
c9ec7b28
...
...
@@ -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
}
...
...
plugin/dapp/evm/executor/vm/runtime/logger.go
View file @
c9ec7b28
...
...
@@ -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
...
...
plugin/dapp/evm/executor/vm/runtime/opcodes.go
View file @
c9ec7b28
...
...
@@ -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
...
...
plugin/dapp/evm/types/evm.go
View file @
c9ec7b28
...
...
@@ -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
,
950000
0
)
}
//InitExecutor ...
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment