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

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
Collaborator

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
@ShantelPeters
Copy link

Hi @enitrat can I work on this ?

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 🆕 Backlog
Development

No branches or pull requests

2 participants