good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
42bd67bd
Commit
42bd67bd
authored
Sep 4, 2018
by
Diep Pham
Committed by
Felix Lange
Sep 4, 2018
Browse files
Options
Downloads
Patches
Plain Diff
accounts/abi: fix unpacking of negative int256 (#17583)
parent
beee7a52
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
accounts/abi/unpack.go
+25
-3
25 additions, 3 deletions
accounts/abi/unpack.go
accounts/abi/unpack_test.go
+5
-0
5 additions, 0 deletions
accounts/abi/unpack_test.go
with
30 additions
and
3 deletions
accounts/abi/unpack.go
+
25
−
3
View file @
42bd67bd
...
@@ -25,8 +25,17 @@ import (
...
@@ -25,8 +25,17 @@ import (
"github.com/ethereum/go-ethereum/common"
"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
// 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
{
switch
kind
{
case
reflect
.
Uint8
:
case
reflect
.
Uint8
:
return
b
[
len
(
b
)
-
1
]
return
b
[
len
(
b
)
-
1
]
...
@@ -45,7 +54,20 @@ func readInteger(kind reflect.Kind, b []byte) interface{} {
...
@@ -45,7 +54,20 @@ func readInteger(kind reflect.Kind, b []byte) interface{} {
case
reflect
.
Int64
:
case
reflect
.
Int64
:
return
int64
(
binary
.
BigEndian
.
Uint64
(
b
[
len
(
b
)
-
8
:
]))
return
int64
(
binary
.
BigEndian
.
Uint64
(
b
[
len
(
b
)
-
8
:
]))
default
:
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) {
...
@@ -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
case
StringTy
:
// variable arrays are written at the end of the return bytes
return
string
(
output
[
begin
:
begin
+
end
]),
nil
return
string
(
output
[
begin
:
begin
+
end
]),
nil
case
IntTy
,
UintTy
:
case
IntTy
,
UintTy
:
return
readInteger
(
t
.
Kind
,
returnOutput
),
nil
return
readInteger
(
t
.
T
,
t
.
Kind
,
returnOutput
),
nil
case
BoolTy
:
case
BoolTy
:
return
readBool
(
returnOutput
)
return
readBool
(
returnOutput
)
case
AddressTy
:
case
AddressTy
:
...
...
This diff is collapsed.
Click to expand it.
accounts/abi/unpack_test.go
+
5
−
0
View file @
42bd67bd
...
@@ -117,6 +117,11 @@ var unpackTests = []unpackTest{
...
@@ -117,6 +117,11 @@ var unpackTests = []unpackTest{
enc
:
"0000000000000000000000000000000000000000000000000000000000000001"
,
enc
:
"0000000000000000000000000000000000000000000000000000000000000001"
,
want
:
big
.
NewInt
(
1
),
want
:
big
.
NewInt
(
1
),
},
},
{
def
:
`[{"type": "int256"}]`
,
enc
:
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
want
:
big
.
NewInt
(
-
1
),
},
{
{
def
:
`[{"type": "address"}]`
,
def
:
`[{"type": "address"}]`
,
enc
:
"0000000000000000000000000100000000000000000000000000000000000000"
,
enc
:
"0000000000000000000000000100000000000000000000000000000000000000"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment