You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
packages/vm/core/evm/evmimpl/iscmagic_state.go contains the magic number MAX_UINT256.
for token approval it is only possible to approve anything <= MAX_UINT64. There is 1 exception, which is that if the value is == MAX_UINT256, then ithe approval amount is clamped to MAX_UINT64. That means that it became a magic number and all values > MAX_UINT64 && values < MAX_UINT256 you throw an error. To remove the magic number and make it cleaner, just clamp everything above MAX_UINT64 to MAX_UINT64 as it all means approve as much as posible. This also makes the code easier:
OLD:
if !numTokens.IsUint64() {
// Calling `approve(MAX_UINT256)` is semantically equivalent to an "infinite" allowance
if numTokens.Cmp(gethmath.MaxBig256) == 0 {
numTokens = big.NewInt(0).SetUint64(math.MaxUint64)
} else {
panic(errBaseTokensMustBeUint64)
}
}
allowance.BaseTokens = numTokens.Uint64()
NEW:
if !numTokens.IsUint64() {
// Calling `approve( > MAX_UINT64)` is semantically equivalent to an "infinite" allowance
numTokens = big.NewInt(0).SetUint64(math.MaxUint64)
}
allowance.BaseTokens = numTokens.Uint64()
Also it prevents unexpected behaviour for smart contract developers.
The text was updated successfully, but these errors were encountered:
packages/vm/core/evm/evmimpl/iscmagic_state.go contains the magic number MAX_UINT256.
for token approval it is only possible to approve anything <= MAX_UINT64. There is 1 exception, which is that if the value is == MAX_UINT256, then ithe approval amount is clamped to MAX_UINT64. That means that it became a magic number and all values > MAX_UINT64 && values < MAX_UINT256 you throw an error. To remove the magic number and make it cleaner, just clamp everything above MAX_UINT64 to MAX_UINT64 as it all means approve as much as posible. This also makes the code easier:
OLD:
NEW:
Also it prevents unexpected behaviour for smart contract developers.
The text was updated successfully, but these errors were encountered: