comptime: symbolic free memory pointer allowing to eval keccak256 over memory - #548
Draft
mbenke wants to merge 1 commit into
Draft
comptime: symbolic free memory pointer allowing to eval keccak256 over memory#548mbenke wants to merge 1 commit into
mbenke wants to merge 1 commit into
Conversation
Let the partial evaluator run memory operations and keccak256 at compile time, so that hashing idioms such as the EIP-712 domain separator fold to a literal. Memory ops (mload/mstore/mstore8/keccak256) are gated on comptime mode: outside it, hashing memory the compiler cannot see would be unsound, so the block is abandoned. Memory is byte-level and sparse; an unwritten byte reads as unknown rather than zero, since runtime code may have written it first. The free memory pointer's value is unknown at compile time, so it is tracked symbolically as YulVal = Concrete | FreeOffset: mload(0x40) yields FreeOffset 0, add/sub shift the offset, and every other operation on it fails. That address has no MAST form, so evaluating an expression now yields both what to emit and what the evaluator additionally knows (EvalResult); emission goes through the former, which makes leaking a symbolic address into the program impossible by construction. Absolute and free-relative addresses may alias at run time, so one evaluation may use only one region, and any write disturbing the pointer slot aborts the evaluation. Finally, a call to a '-> comptime' function whose arguments are all known must have folded by the time the verifier runs; if it survived, the annotation's promise was not kept and the call site is reported. Assisted-By: Claude Opus 5 (claude-opus-5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Let the partial evaluator run memory operations and keccak256 at compile time, so that hashing idioms such as the EIP-712 domain separator fold to a literal.
Memory ops (mload/mstore/mstore8/keccak256) are gated on comptime mode: outside it, hashing memory the compiler cannot see would be unsound, so the block is abandoned. Memory is byte-level and sparse; an unwritten byte reads as unknown rather than zero, since runtime code may have written it first.
The free memory pointer's value is unknown at compile time, so it is tracked symbolically as YulVal = Concrete | FreeOffset: mload(0x40) yields FreeOffset 0, add/sub shift the offset, and every other operation on it fails. That address has no MAST form, so evaluating an expression now yields both what to emit and what the evaluator additionally knows (EvalResult); emission goes through the former, which makes leaking a symbolic address into the program impossible by construction.
Absolute and free-relative addresses may alias at run time, so one evaluation may use only one region, and any write disturbing the pointer slot aborts the evaluation.
Finally, a call to a '-> comptime' function whose arguments are all known must have folded by the time the verifier runs; if it survived, the annotation's promise was not kept and the call site is reported.
Assisted-By: Claude Opus 5 (claude-opus-5)