Skip to content
Business logic Audit finding Intermediate

anchorTime() will not work properly on Optimism due to use of block.number

The contract uses block.number to compute a time anchor, which is unreliable on Optimism because block numbers do not correspond to constant time intervals. This could cause the holding duration for votes to deviate from the intended 90-day minimum, affecting redeem().

peakbolt Follow with Udsen and Tricko

Originally disclosed on Code4rena

Submitted by peakbolt, also found by Udsen and Tricko

When deploying to Optimism, Equity.anchorTime() will not be accurate due to the use of block.number.

    function anchorTime() internal view returns (uint64){
        return uint64(block.number << BLOCK_TIME_RESOLUTION_BITS);
    }

Impact

The inaccuracy of block.number will affect the computation of the holding duration for the votes. That will affect redeem() as the issue will cause it to deviate from the intended design of 90 days minimum holding duration (stated in comments).

https://github.com/code-423n4/2023-04-frankencoin/blob/main/contracts/Equity.sol#L54-L59

Detailed Explanation

Noted that the devs have mentioned that it is conceivable that Frankencoin will be deployed on other evm chains. So it is worth reviewing the use of block.number, such that it is compatible with other chains like Optimism.

On Optimism, the block.number is not a reliable source of timing information and the time between each block is also different from Ethereum. This is because each transaction on L2 is placed in a separate block and blocks are not produce at a constant rate. This will cause the holding duration computation using anchorTime() to fluctuate. (see Optimism docs https://community.optimism.io/docs/developers/build/differences/#block-numbers-and-timestamps)

Recommended Mitigation Steps

Consider using block.timestamp instead of block.number for more accurate measurement of time.

luziusmeisser (Frankencoin) confirmed and commented:

I guess I should switch from block number to timestamp.


The original report as published on Code4rena, by peakbolt. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the contract assumes block.number advances at a constant rate, which is not true on Optimism where block production is irregular.

Impact

The holding duration computation could fluctuate, causing redeem() to deviate from the intended 90-day minimum holding period.

What the attacker needed

Deployment on Optimism

The fix

The contract should use block.timestamp instead of block.number for more accurate time measurement.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This report is about a smart contract that uses the number of blocks on the blockchain to measure time. On some networks like Optimism, blocks are not created at a steady rate, so counting blocks does not give an accurate duration. That could let users redeem tokens earlier or later than the intended 90-day waiting period.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by peakbolt

View all

16 more disclosed reports, best first.

More from Frankencoin

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.