foundry: Arbitrum fork can't read l2 block number
Component
Forge, Anvil
Have you ensured that all of these are up to date?
- Foundry
- Foundryup
What version of Foundry are you on?
forge 0.2.0 (1caa0fa 2023-05-30T00:11:10.062347000Z)
What command(s) is the bug in?
forge test --mt testGetArbL2BlockNumber -vvvv
Operating System
macOS (Apple Silicon)
Describe the bug
Since block.number on arbitrum is block number on l1, arbitrum has a precompiled address (0x64) to reflect l2 address. Call address(0x64) arbBlockNumber to get l2 block number.
interface ArbSys {
/**
* @notice Get Arbitrum block number (distinct from L1 block number; Arbitrum genesis block has block number 0)
* @return block number as int
*/
function arbBlockNumber() external view returns (uint);
}
Create arbitrum fork and call 0x64 with arbBlockNumber(), it wil revert with "EvmError: InvalidFEOpcode".
I think it’s just because the foundry evm doesn’t fulfill the precompile contract function, but there should be a way to get l2 block number on arbitrum fork. Fulfill it to compatible with arbitrum official implemtation would be great.
A minimal test to reproduce it
interface ArbSys {
/**
* @notice Get Arbitrum block number (distinct from L1 block number; Arbitrum genesis block has block number 0)
* @return block number as int
*/
function arbBlockNumber() external view returns (uint);
}
contract ArbL2NumberTest is Test {
function testGetArbL2BlockNumber() public {
// <https://arbiscan.io/block/75219831>
vm.createSelectFork("https://rpc.ankr.com/arbitrum", 75219831);
ArbSys(address(0x64)).arbBlockNumber();
}
}
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 2
- Comments: 18 (5 by maintainers)
Any updates on this? Also facing this issue.
@noyyyy @trojanMcAfee you may try to change Arbitrum chainId to 4216138 (
vm.chainId(4216138)), thats worked for me.@mattsse Could you kindly provide more details on how to address this problem? In test cases, there is an already-deployed contract on arbitrum that utilizes
arbBlockNumber(), leading to the occurrence of this error.@ashablovskiy That worked for me aswell, i was struggling with that too! Thanks 🤝
fyi @klkvr prime candiate for chain specific precompile
working on making this possible
hmm,
you could add the precompile call of the arbysys interface
https://docs.arbitrum.io/for-devs/dev-tools-and-resources/precompiles#arbsys https://github.com/OffchainLabs/nitro/blob/v2.0.14/contracts/src/precompiles/ArbSys.sol
to the mock contract
https://github.com/saucepoint/foundry-arbitrum/blob/main/src/ArbitrumTest.sol
that should be a simple PR
looks like this is related to arbitrum precompile,
ptal at https://github.com/saucepoint/foundry-arbitrum/
Related to https://github.com/foundry-rs/foundry/issues/748