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

fix(cancun): mcopy check offsets #252

Merged
merged 5 commits into from
May 29, 2024
Merged

Conversation

Nashtare
Copy link
Collaborator

Noticed while working with John's edge case txns.
We aren't checking for valid memory offsets, which would then cause the prover to panic and abort when performing the mem_cpy.

@wborgeaud I noticed we aren't performing this check for the other syscalls of the wcopy family. Don't you think we should?

Makes 4th txn of witness-0233.json pass.

@Nashtare Nashtare added the bug Something isn't working label May 27, 2024
@Nashtare Nashtare added this to the Cancun - Q2 2024 milestone May 27, 2024
@Nashtare Nashtare self-assigned this May 27, 2024
@Nashtare Nashtare changed the title fix(cancun): mcopy check offsets fix(cancun): mcopy check offsets May 27, 2024
@github-actions github-actions bot added the crate: evm_arithmetization Anything related to the evm_arithmetization crate. label May 27, 2024
@wborgeaud
Copy link
Contributor

@wborgeaud I noticed we aren't performing this check for the other syscalls of the wcopy family. Don't you think we should?

Hm unless I'm missing something, for the wcopy syscalls a large offset is handled in wcopy_large_offset and a large dest_offset or size is handled in %ensure_reasonable_offset.

evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm Outdated Show resolved Hide resolved
DUP2
%ensure_offset_in_range
DUP3
%ensure_offset_in_range
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related to this PR, but I noticed we call %update_mem_bytes only on dest_offset+size below.
My understanding of the EIP, especially the line

If length > 0 and (src + length or dst + length) is beyond the current memory length, the memory is extended with respective gas cost applied.

would imply we also need to call it with offset+size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm actually I think this would also be handling the error in that particular txn case. Will update the PR to have it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think there may be issues with the current mcopy_with_overlap. I don't think the current impl is valid if SRC < DST and DST - SRC < min(32, size). To alleviate it without too much overhead, I guess we could simply have a %memcpy_bytes_reversed macro that processes the copy backwards, starting from the last offset to read / write from and decrementing both DST, SRC and size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would also like confirmation on this one! (Other MCOPY PR got merged into this branch)

Copy link
Contributor

@wborgeaud wborgeaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Nashtare Nashtare merged commit e48f8e9 into feat/cancun May 29, 2024
6 checks passed
@Nashtare Nashtare deleted the cancun/mcopy_check_offsets branch May 29, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crate: evm_arithmetization Anything related to the evm_arithmetization crate.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants