Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RangeError: Maximum BigInt size exceeded in Exp #129

Open
acuarica opened this issue Jun 28, 2024 · 1 comment
Open

Fix RangeError: Maximum BigInt size exceeded in Exp #129

acuarica opened this issue Jun 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@acuarica
Copy link
Owner

acuarica commented Jun 28, 2024

When analyzing contract 0xEC702942609FaD2afC1489277d918611f0e17ceb, the following error is raised

RangeError: Maximum BigInt size exceeded

How to reproduce it

Run

$ sevm abi 0xEC702942609FaD2afC1489277d918611f0e17ceb
RangeError: Maximum BigInt size exceeded

After further investigation, the error stack is

RangeError: Maximum BigInt size exceeded
    at Exp.eval (<path>/evm/dist/src/ast/alu.js:122:47)
    at Local.eval (<path>/evm/dist/src/ast/index.js:140:66)
    at new Jumpi (<path>/evm/dist/src/ast/flow.js:41:30)
    at FrontierStep.JUMPI (<path>/evm/dist/src/step.js:713:24)
    at EVM.exec (<path>/evm/dist/src/evm.js:123:40)
    at EVM.run (<path>/evm/dist/src/evm.js:92:18)
    at new Contract (<path>/evm/dist/src/index.js:59:17)
    at Object.handler (file://<path>/evm/bin/sevm.mjs:165:32)

This issue is a follow up of #125, where some errors were reported when running sevm on a large contract dataset. The other errors encountered in the dataset were (these are already fixed)

@acuarica acuarica added the bug Something isn't working label Jun 28, 2024
@acuarica
Copy link
Owner Author

acuarica commented Jun 28, 2024

Creating a smaller contract based on 0xEC702942609FaD2afC1489277d918611f0e17ceb, the following contract causes this issue

interface IERC20 {
    function decimals() external view returns (uint256);
}

contract Test {
    function truToToken() external view returns (uint256) {
        return 10**IERC20(0xdAC17F958D2ee523a2206206994597C13D831ec7).decimals();
    }
}

The CFG for this contract (it was generated by temporarily patching the Exp eval to avoid the error) looks like

image

On pc 51 you can see the Exp AST node 0xa ** 0x313ce56700000000000000000000000000000000000000000000000000000000, which is causing the issue. The 0x313ce567 value is a function selector for decimals()

$ cast sig 'decimals()'
0x313ce567

This 0x313ce567 value was first moved into memory to perform the staticcall on pc 165. All of this heavily implies that the STATICCALL (and CALL and DELEGATECALL) steps need to invalidate previous memory locations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant