-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Behaviour of block.number on eth_call is incorrect #530
Description
Problem: When using block.number in Solidity code, sometimes it uses the blockNumber of L1 and sometimes it uses the blockNumber of L2. (See screenshot and code for detailed instructions).
Requirement: What exactly is the behaviour of block.number? How to ensure that it always returns the L1 or L2 blockNumber in the contract.
This is my test code: https://github.com/guanzhenxing/optimism-test
And I run my code.Get the result like this:

A red underline indicates that block.number has not been changed. A green underline means that I called the method that changed blockNumber.
And in my project code, the difference between BlockNumberTest1.sol and BlockNumberTest.sol is the compareAndUpdateUserState() method.
When running require(state.blockNumber <= blockNumber, "state.blockNumber must be smaller or equal to blockNumber") first; it gives an error, but running updateUserState() is fine.