overflow error while using contract abi
Ethers Version
5.6.6
Search Terms
abi,overflow,BigNumber.from,NUMERIC_FAULT
Describe the Problem
Issue
When using the contract ABI directly from etherscan, it causes ethers.utils.Interface.getSighash to fail with an overflow error
Problematic Contract
https://etherscan.io/address/0x2c6c87e7e6195ab7a4f19d3cf31d867580bb2a1b#code
Expected Behaviour
Maybe the library should internally cast gas fields to string before conversion to avoid this failure
Working Manually Modified ABI
{ "name": "claim_many", "outputs": [ { "type": "bool", "name": "" } ], "inputs": [ { "type": "address[20]", "name": "_receivers" } ], "stateMutability": "nonpayable", "type": "function", "gas": "13211877381977777897829449389491290286058105250349588356902110335302888091941138088" }
Code Snippet
const ethers = require('ethers');
var abi = { "name": "claim_many", "outputs": [ { "type": "bool", "name": "" } ], "inputs": [ { "type": "address[20]", "name": "_receivers" } ], "stateMutability": "nonpayable", "type": "function", "gas": 13211877381977777897829449389491290286058105250349588356902110335302888091941138088 }
var function_sig = ethers.utils.FunctionFragment.from(abi);
var sighash = ethers.utils.Interface.getSighash(function_sig);
console.log(sighash);
Contract ABI
{ "name": "claim_many", "outputs": [ { "type": "bool", "name": "" } ], "inputs": [ { "type": "address[20]", "name": "_receivers" } ], "stateMutability": "nonpayable", "type": "function", "gas": 13211877381977777897829449389491290286058105250349588356902110335302888091941138088 }
Errors
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32) {
reason: 'overflow',
code: 'NUMERIC_FAULT',
fault: 'overflow',
operation: 'BigNumber.from',
value: 1.3211877381977778e+82
}
Environment
node.js (v12 or newer)
Environment (Other)
No response
That value is not really valid for a gas amount, so I don't really know what it is trying to represent.
But there is no such thing as "casting internally". The value is already a IEEE 754 number in your above example, there is no safe way to pull it in from a JSON object. If you are pulling data in with bad values in it, you can delete those values before passing it to the library, but I'm more curious why there are bad values in that payload.
Where did you get that data from?
think is an issue specifically when I try to interact with smart contracts in Mumbai network, (network that has gas estimation issues) that is the reason why appear the gas amount into ABI. Btw this cannot happen in Polygon mainnet
Closing older issues. But if this is still happening in v6, please re-open or start a new issue.
Thanks! :)