From 89c6c5bb85ff24c152218f245fa366e733c951a7 Mon Sep 17 00:00:00 2001 From: Thomas Bocek Date: Thu, 2 Jun 2016 18:43:27 +0200 Subject: 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? --- accounts/abi/method.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'accounts/abi/method.go') diff --git a/accounts/abi/method.go b/accounts/abi/method.go index f3d1a44b5..d56f3bc3d 100644 --- a/accounts/abi/method.go +++ b/accounts/abi/method.go @@ -62,7 +62,7 @@ func (m Method) pack(method Method, args ...interface{}) ([]byte, error) { // calculate the offset offset := len(method.Inputs)*32 + len(variableInput) // set the offset - ret = append(ret, packNum(reflect.ValueOf(offset), UintTy)...) + ret = append(ret, packNum(reflect.ValueOf(offset))...) // Append the packed output to the variable input. The variable input // will be appended at the end of the input. variableInput = append(variableInput, packed...) -- cgit