diff options
author | Thomas Bocek <tom@tomp2p.net> | 2016-06-03 00:43:27 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-06-14 22:11:57 +0800 |
commit | 39f1d909d185816bade35c7336364fe5e842c7c5 (patch) | |
tree | 6bbc0e6938a1cf3f842f6212790bd4fb96a1673b /accounts/abi/packing.go | |
parent | 71b577f83953838d79cf78b77ab0d9d671bd5edf (diff) | |
download | go-tangerine-39f1d909d185816bade35c7336364fe5e842c7c5.tar go-tangerine-39f1d909d185816bade35c7336364fe5e842c7c5.tar.gz go-tangerine-39f1d909d185816bade35c7336364fe5e842c7c5.tar.bz2 go-tangerine-39f1d909d185816bade35c7336364fe5e842c7c5.tar.lz go-tangerine-39f1d909d185816bade35c7336364fe5e842c7c5.tar.xz go-tangerine-39f1d909d185816bade35c7336364fe5e842c7c5.tar.zst go-tangerine-39f1d909d185816bade35c7336364fe5e842c7c5.zip |
[release/1.4.7] accounts/abi: Negative numbers not properly converted in ABI encoding
When converting a negative number e.g., -2, the resulting ABI encoding
should look as follows:
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe.
However, since the check of the type is for an uint instead of an
int, it results in the following ABI encoding:
0101010101010101010101010101010101010101010101010101010101010102. The
Ethereum ABI
(https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI) says,
that signed integers are stored in two's complement which should be
of the form ffffff.... and not 01010101..... for e.g. -1. Thus, I
removed the type check in numbers.go as well as the function S256
as I don't think they are correct. Or maybe I'm missing something?
(cherry picked from commit 89c6c5bb85ff24c152218f245fa366e733c951a7)
Diffstat (limited to 'accounts/abi/packing.go')
-rw-r--r-- | accounts/abi/packing.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/accounts/abi/packing.go b/accounts/abi/packing.go index c765dfdf3..0c37edf17 100644 --- a/accounts/abi/packing.go +++ b/accounts/abi/packing.go @@ -25,7 +25,7 @@ import ( // packBytesSlice packs the given bytes as [L, V] as the canonical representation // bytes slice func packBytesSlice(bytes []byte, l int) []byte { - len := packNum(reflect.ValueOf(l), UintTy) + len := packNum(reflect.ValueOf(l)) return append(len, common.RightPadBytes(bytes, (l+31)/32*32)...) } @@ -34,7 +34,7 @@ func packBytesSlice(bytes []byte, l int) []byte { func packElement(t Type, reflectValue reflect.Value) []byte { switch t.T { case IntTy, UintTy: - return packNum(reflectValue, t.T) + return packNum(reflectValue) case StringTy: return packBytesSlice([]byte(reflectValue.String()), reflectValue.Len()) case AddressTy: |