* accounts/abi: reorganizing package and some notes and a quick correction of name.
Signed-off-by: RJ Catalano <rj@monax.io>
get rid of some imports
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: move file names
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: fix boolean decode function
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: fix for the array set and for creating a bool
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: be very very very correct
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: fix up error message and variable names
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: take out unnecessary argument in pack method
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: add bool unpack test and add a panic to readBool function
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: fix panic message
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: change from panic to basic error
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: fix nil to false
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: fill out type regex tests and fill with the correct type for integers
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: move packNumbers into pack.go.
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: separation of the testing suite into appropriately named files.
Signed-off-by: RJ Catalano <rj@monax.io>
* account/abi: change to hex string tests.
Signed-off-by: RJ Catalano <rj@monax.io>
* account/abi: fix up rest of tests to hex
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: declare bool at the package level
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: use errors package in the error file.
Signed-off-by: RJ Catalano <rj@monax.io>
* accounts/abi: fix ugly hack and fix error type declaration.
Signed-off-by: RJ Catalano <rj@monax.io>
* common/math: optimize PaddedBigBytes, use it more
name old time/op new time/op delta
PaddedBigBytes-8 71.1ns ± 5% 46.1ns ± 1% -35.15% (p=0.000 n=20+19)
name old alloc/op new alloc/op delta
PaddedBigBytes-8 48.0B ± 0% 32.0B ± 0% -33.33% (p=0.000 n=20+20)
* all: unify big.Int zero checks
Various checks were in use. This commit replaces them all with Int.Sign,
which is cheaper and less code.
eg templates:
func before(x *big.Int) bool { return x.BitLen() == 0 }
func after(x *big.Int) bool { return x.Sign() == 0 }
func before(x *big.Int) bool { return x.BitLen() > 0 }
func after(x *big.Int) bool { return x.Sign() != 0 }
func before(x *big.Int) int { return x.Cmp(common.Big0) }
func after(x *big.Int) int { return x.Sign() }
* common/math, crypto/secp256k1: make ReadBits public in package math
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
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?
Refactored the abi package parsing and type handling. Relying mostly on
package reflect as opposed to most of our own type reflection. Our own
type reflection is still used however for cases such as Bytes and
FixedBytes (abi: bytes•).
This also inclused several fixes for slice handling of arbitrary and
fixed size for all supported types.
This also further removes implicit type casting such as assigning,
for example `[2]T{} = []T{1}` will fail, however `[2]T{} == []T{1, 2}`
(notice assigning *slice* to fixed size *array*). Assigning arrays to
slices will always succeed if they are of the same element type.
Incidentally also fixes#2379
Fixed up `[]byte` slice support such that `function print(bytes input)`
accepts `[]byte` as input and treats it as 1 element rather than a slice
of multiple elements.
Added support for variable length input parameters like `bytes` and
`strings`.