[feat] make assembly block Solidity memory safe #50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously the assembly block for snark verifier started mstore from memory offset
0
. This does not respect Solidity's memory layout where0x40 = 64
is reserved as a free memory pointer. See https://docs.soliditylang.org/en/latest/assembly.html#memory-safetyWe make the assembly block memory safe by changing
EvmLoader::new
to startptr
fromMEM_PTR_START = 0x80
, and check in the assembly block preamble thatmload(0x40) = 0x80
. This means that the memory between0
and0x80
is never used.@han0110 The one thing I was a little unsure of was the
common_scalar
inEvmTranscript
: iscommon_scalar
only called exactly once at the very beginning on thetranscript_initial_repr
and so it's special casemload
to0x80
(formerly0x00
)?