accounts/abi/abigen: use golang uint256.Int for solidity uint256 params #31607
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, abigen generates a big.Int binding in Golang for uint256 Solidity parameters.
The danger is that negative big.Int values are serialized into very large uint256 values due to two’s complement. For example,
big.NewInt(-1)
is serialized to the maximum uint256 value.Consider this binding where the type of amount in Solidity is uint256, but the generated binding uses big.Int.
The risk is that, due to programmer error, an accidental call like
erc20Token.Mint(..., big.NewInt(-1))
is made. Unexpectedly, the call will not return an error, but instead serializes a transaction whereamount=0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
due togo-ethereum/common/math/big.go
Line 170 in 4ff5093
Another similar scenario is demonstrated in this test mirokuratczyk@170d120, which fails with
Generating a uint256.Int binding in Golang for uint256 Solidity parameters ensures proper type safety and makes this unexpected behavior impossible.