_checkDelay will not work properly for Arbitrum or Optimism due to block.number
The trade delay mechanism used block.number, which on Arbitrum and Optimism does not advance predictably per transaction, so a user could open and close a position within the intended delay period and exploit multiple valid prices.
\_checkDelay enforces a delay of a specific number of block between opening and closing a position. While this structure will work on mainnet, it is problematic for use on Arbitrum.
According to Arbitrum Docsblock.number returns the most recently synced L1 block number. Once per minute the block number in the Sequencer is synced to the actual L1 block number. This period could be abused to completely bypass this protection.
The user would open their position 1 Arbitrum block before the sync happens, then close it the very next block. It would appear that there has been 5 blocks (60 / 12) since the last transaction but in reality it has only been 1 Arbitrum block. Given that Arbitrum has 2 seconds blocks it would be impossible to block this behavior through parameter changes.
It also presents an issue for Optimism because each transaction is it’s own block. No matter what value is used for the block delay, the user can pad enough tiny transactions to allow them to close the trade immediately.
Recommended Mitigation Steps
The delay should be measured using block.timestamp rather than block.number.
As a general rule, any timing assumptions a contract makes about block numbers and timestamps should be considered generally reliable in the longer term (i.e., on the order of at least several hours) but unreliable in the shorter term (minutes). (It so happens these are generally the same assumptions one should operate under when using block numbers directly on Ethereum!)
From a trusted Arbitrum Dev: using block.number is generally fine if you want to measure time, since that will roughly follow L1 block time
So ultimately this is dependent on how big or small of a delay is required.
For minutes to hours, there seems to be no risk, while for shorter timeframes, some risk is possible.
In terms of impact, the main impact would be that an operation that would be expected to be executed 12 seconds later, could actually be executed as rapidly as 1 or 2 seconds after (if we assume that one L2 block goes from number A to B).
I don’t think the finding can be categorized High Severity due to the reliance on settings and intentions, but at this point I believe the finding is valid and am thinking it should be of Medium Severity as it may break expectations (e.g. being able to use the same oracle price in 2 separate blocks due to unexpectedly small timestamp differences), but this is reliant on an external condition.
Leading me to further agree with the risk involved with the finding, at this time I believe block.timestamp to be a better tool for all L2 integrations.
The original report as published on Code4rena, by 0x52. 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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the contract measured time using block.number, which on Arbitrum and Optimism does not reliably advance with each transaction, instead of using block.timestamp.
Impact
A user could bypass the intended trade delay and potentially use the same oracle price in two separate blocks, though the judge noted this depends on the configured delay and external conditions.
What the attacker needed
Contract deployed on Arbitrum or Optimism; ability to open and close a trade
How it was found
Open a position one Arbitrum block before the block number syncs to the L1 block number.
Close the position in the very next block, which appears to have advanced by several blocks but in reality is only one Arbitrum block later.
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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A smart contract used the number of the current block to enforce a waiting period between opening and closing a trade. On some layer-2 networks the block number does not increase with every transaction in the same way as on Ethereum, so the waiting period could be bypassed. This let a trader close a position sooner than intended and potentially use more than one price for the same trade.
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.