Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsafe cast in ScrollChain.finalizeBundleWithProof #70

Open
barakman opened this issue Dec 31, 2024 · 0 comments
Open

Unsafe cast in ScrollChain.finalizeBundleWithProof #70

barakman opened this issue Dec 31, 2024 · 0 comments

Comments

@barakman
Copy link

In case you've missed it (since this issue is typically easy to miss), in the aforementioned contract function, you are performing an unsafe cast:

uint32(_batchIndex - _finalizedBatchIndex), // numBatches

If the value of _batchIndex - _finalizedBatchIndex is larger than type(uint32).max, then the expression above will be evaluated incorrectly, instead of reverting the transaction at hand on overflow (as it should).

You can either add this as a preliminary requirement, prior to the code above:

require(_batchIndex - _finalizedBatchIndex <= type(uint32).max);

Or you can replace that cast with a call to OpenZeppelin's de-facto standard library function SafeCast.toUint32:

SafeCast.toUint32(_batchIndex - _finalizedBatchIndex), // numBatches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant