Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
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
张蕾
Geth-Modification
Commits
42bd67bd
Commit
42bd67bd
authored
Sep 04, 2018
by
Diep Pham
Committed by
Felix Lange
Sep 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi: fix unpacking of negative int256 (#17583)
parent
beee7a52
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
3 deletions
+30
-3
unpack.go
accounts/abi/unpack.go
+25
-3
unpack_test.go
accounts/abi/unpack_test.go
+5
-0
No files found.
accounts/abi/unpack.go
View file @
42bd67bd
...
...
@@ -25,8 +25,17 @@ import (
"github.com/ethereum/go-ethereum/common"
)
var
(
maxUint256
=
big
.
NewInt
(
0
)
.
Add
(
big
.
NewInt
(
0
)
.
Exp
(
big
.
NewInt
(
2
),
big
.
NewInt
(
256
),
nil
),
big
.
NewInt
(
-
1
))
maxInt256
=
big
.
NewInt
(
0
)
.
Add
(
big
.
NewInt
(
0
)
.
Exp
(
big
.
NewInt
(
2
),
big
.
NewInt
(
255
),
nil
),
big
.
NewInt
(
-
1
))
)
// reads the integer based on its kind
func
readInteger
(
kind
reflect
.
Kind
,
b
[]
byte
)
interface
{}
{
func
readInteger
(
typ
byte
,
kind
reflect
.
Kind
,
b
[]
byte
)
interface
{}
{
switch
kind
{
case
reflect
.
Uint8
:
return
b
[
len
(
b
)
-
1
]
...
...
@@ -45,7 +54,20 @@ func readInteger(kind reflect.Kind, b []byte) interface{} {
case
reflect
.
Int64
:
return
int64
(
binary
.
BigEndian
.
Uint64
(
b
[
len
(
b
)
-
8
:
]))
default
:
return
new
(
big
.
Int
)
.
SetBytes
(
b
)
// the only case lefts for integer is int256/uint256.
// big.SetBytes can't tell if a number is negative, positive on itself.
// On EVM, if the returned number > max int256, it is negative.
ret
:=
new
(
big
.
Int
)
.
SetBytes
(
b
)
if
typ
==
UintTy
{
return
ret
}
if
ret
.
Cmp
(
maxInt256
)
>
0
{
ret
.
Add
(
maxUint256
,
big
.
NewInt
(
0
)
.
Neg
(
ret
))
ret
.
Add
(
ret
,
big
.
NewInt
(
1
))
ret
.
Neg
(
ret
)
}
return
ret
}
}
...
...
@@ -179,7 +201,7 @@ func toGoType(index int, t Type, output []byte) (interface{}, error) {
case
StringTy
:
// variable arrays are written at the end of the return bytes
return
string
(
output
[
begin
:
begin
+
end
]),
nil
case
IntTy
,
UintTy
:
return
readInteger
(
t
.
Kind
,
returnOutput
),
nil
return
readInteger
(
t
.
T
,
t
.
Kind
,
returnOutput
),
nil
case
BoolTy
:
return
readBool
(
returnOutput
)
case
AddressTy
:
...
...
accounts/abi/unpack_test.go
View file @
42bd67bd
...
...
@@ -117,6 +117,11 @@ var unpackTests = []unpackTest{
enc
:
"0000000000000000000000000000000000000000000000000000000000000001"
,
want
:
big
.
NewInt
(
1
),
},
{
def
:
`[{"type": "int256"}]`
,
enc
:
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
want
:
big
.
NewInt
(
-
1
),
},
{
def
:
`[{"type": "address"}]`
,
enc
:
"0000000000000000000000000100000000000000000000000000000000000000"
,
...
...
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