Skip to content

Behaviour of block.number on eth_call is incorrect #530

@guanzhenxing

Description

@guanzhenxing

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:

image
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugsC-questionUser questions that are neither feature requests nor bug reportsS-unconfirmedStatus: Issue might be valid, but it’s not yet confirmed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions