Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

epic: ensure no operation overflows #904

Open
enitrat opened this issue Sep 4, 2024 · 2 comments
Open

epic: ensure no operation overflows #904

enitrat opened this issue Sep 4, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@enitrat
Copy link
Contributor

enitrat commented Sep 4, 2024

Ensure that no operation overflows.

example, in returndatacopy:

    fn exec_returndatacopy(ref self: VM) -> Result<(), EVMError> {
        let dest_offset = self.stack.pop_usize()?;
        let offset = self.stack.pop_usize()?;
        let size = self.stack.pop_usize()?;
        let return_data: Span<u8> = self.return_data();

        let (last_returndata_index, overflow) = offset.overflowing_add(size);
        if overflow {
            return Result::Err(EVMError::ReturnDataOutOfBounds);
        }
        ensure(!(last_returndata_index > return_data.len()), EVMError::ReturnDataOutOfBounds)?;

instead of doing size + offset to get the last returndata index, we check for overflows. Otherwise, we would get a CairoVM error that would fail the entire transaction

we can use something like

offset.overflowing_add(size).ok_or(EVMError::ReturnDataOutOfBounds)?;

to manage this efficiently

@enitrat enitrat added the enhancement New feature or request label Sep 4, 2024
@github-project-automation github-project-automation bot moved this to 🆕 Backlog in Kakarot on Starknet Sep 4, 2024
@ShantelPeters

This comment was marked as abuse.

Copy link

onlydustapp bot commented Sep 5, 2024

Hey @ShantelPeters!
Thanks for showing interest.
We've created an application for you to contribute to Kakarot zkEVM.
Go check it out on OnlyDust!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
No open projects
Status: 🆕 Backlog
Development

No branches or pull requests

2 participants