axiom-crypto / snark-verifier

Apache License 2.0
94 stars 36 forks source link

[feat] make assembly block Solidity memory safe #39

Closed jonathanpwang closed 1 year ago

jonathanpwang commented 1 year ago

Previously the assembly block for snark verifier started mstore from memory offset 0. This does not respect Solidity's memory layout where 0x40 = 64 is reserved as a free memory pointer. See https://docs.soliditylang.org/en/latest/assembly.html#memory-safety

We make the assembly block memory safe by changing EvmLoader::new to start ptr from MEM_PTR_START = 0x80, and check in the assembly block preamble that mload(0x40) = 0x80. This means that the memory between 0 and 0x80 is never used.