Model keccak256 opcode, unaligned calldata, and SHA-256 engine in executable semantics#1943
Open
Th0rgal wants to merge 20 commits into
Open
Model keccak256 opcode, unaligned calldata, and SHA-256 engine in executable semantics#1943Th0rgal wants to merge 20 commits into
Th0rgal wants to merge 20 commits into
Conversation
Surface declared raw-Yul storage writes in the modifies() write-set, flag computed-slot writes as untrackable, and treat fragment call mechanics as external interactions for CEI ordering and external-call detection.
…ntics Make evalExpr/evalExprWithHelpers evaluate Expr.keccak256 via the in-tree KeccakEngine over a word-aligned RuntimeState memory slice, instead of returning none (revert). Adds keccakMemorySlice/memorySliceBytesBE/wordToBytesBE helpers; updates evalExpr_keccak256 and the helper-surface equivalence case. No new axiom or sorry: reuses the CI-cross-checked kernel Keccak. Trust docs (AXIOMS.md, TRUST_ASSUMPTIONS.md) updated to record the word-aligned-access faithfulness assumption (keccak256_memory_slice_matches_evm). Builds green: SourceSemantics + 8 reverse-dependency importers + SphincsMinusVerifiers.
Pure-Lean, axiom-free SHA-256 over ByteArray (Sha256Engine.sha256), mirroring KeccakEngine's role: prerequisite for modeling the EVM SHA-256 precompile (0x02) in the executable source semantics with a computed 32-byte digest. Verified against reference vectors (empty, "abc", quick-brown-fox, and the 56-byte padding-boundary case). UInt32 wrapping matches spec add-mod-2^32.
calldataloadWord now returns the EVM-faithful byte-addressed 32-byte window for unaligned offsets (r != 0), composing the hi/lo words with big-endian zero-padding. Aligned reads (r = 0) reduce to the prior single-word behaviour exactly. Needed for the C13 auth-path sibling reads at 16-byte-strided offsets in the Merkle-climb correspondence.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
2 tasks
Member
Author
|
@codex review |
|
To use Codex here, create a Codex account and connect to github. |
Contributor
| \n### CI Failure Hints\n\nFailed jobs: `build`\n\nCopy-paste local triage:\n```bash\nmake check\nlake build\nFOUNDRY_PROFILE=difftest forge test -vv\n``` |
…pport # Conflicts: # Compiler/CompilationModel/Types.lean # Compiler/CompilationModel/Validation.lean # Compiler/CompilationModelFeatureTest.lean
…e-Yul review invariants ff6c9c0 swapped calldataloadWord's aligned/unaligned branches (r = 0 now selects the aligned word) but left calldataloadWord_lt_evmModulus expecting the old layout, breaking the build at FunctionBody.lean:1969. Both branches now reduce mod evmModulus, so each discharges via Nat.mod_lt. Also document two invariants raised in the PR #1943 review: - LogicalPurity: raw Yul is emitted verbatim, so the logicalAnd/logicalOr/ite operand-duplication predicate correctly returns false; fragment external calls are caught in Validation, not here. - SourceSemantics: the keccak256 arm must evaluate offset/size with evalExpr to stay definitionally equal to evalExpr, because exprTouchesUnsupportedHelperSurface treats keccak256 as a helper-surface leaf and evalExprWithHelpers_eq_evalExpr depends on it.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 085c3f1. Configure here.
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.

Summary
Extends Verity's executable source semantics with the hash/calldata
primitives the SPHINCS- C13 accept-path refinement needs. Enables the
keccak accept path to be executed (and thus proved) rather than
reverting at the first hash.
keccak256(offset,size)modeled (SourceSemantics.lean): newkeccakMemorySlice/memorySliceBytesBE/wordToBytesBEhelpers and.keccak256arms inevalExpr/evalExprWithHelpers, wired to thein-tree
KeccakEngine. Previously the first keccak madeexecStmtrevert, making the accept subdomain provably unreachable.
calldataloadWord(Calldata.lean): EVM-faithfulbyte-addressed 32-byte window for unaligned offsets (
r != 0), composinghi/lo words big-endian with zero-padding. Aligned reads (
r = 0) reduceto the prior single-word behaviour exactly. Needed for C13 auth-path
sibling reads at 16-byte-strided offsets.
Compiler/Sha256/Engine.lean),FIPS 180-4, verified against reference vectors. Infrastructure only — the
SHA-256 precompile (0x02) is deliberately NOT wired into the interpreter
yet (word-keyed memory cannot faithfully represent SLH-DSA's 16-byte
precompile-input layout).
Trust docs (
AXIOMS.md/TRUST_ASSUMPTIONS.md) updated forkeccak256_memory_slice_matches_evm. No newsorry; keccak engine iscross-checked against the EVM engine.
Test plan
lake buildofSourceSemantics+ reverse-dep importers greenSphincsMinusVerifiersbuilds against this branchNote
Medium Risk
Changes core executable semantics and calldata/hash modeling used by proofs, plus validation/CEI behavior for raw Yul; trust assumptions on word-aligned keccak preimages are explicit but correctness-sensitive.
Overview
Executable source semantics now evaluates
Expr.keccak256via word-aligned memory slicing and the in-treeKeccakEngine(previously alwaysnone/revert). Helper-aware evaluation andSupportedSpecsurface scans treatkeccak256as supported and recurse into offset/size operands. Trust docs documentkeccak256_memory_slice_matches_evm.calldataloadWordis updated for EVM-faithful unaligned 32-byte reads (hi/lo composition); aligned reads stay behavior-identical. Proof tweaks inFunctionBody.leanfollow the new branches.New kernel-computable SHA-256 engine (
Compiler/Sha256/Engine.lean) with FIPS reference-vector tests, wired intoCompiler.leanbuild — not hooked into the source interpreter yet.Raw Yul validation gains AST scans for
call/staticcall/delegatecallso CEI, external-call detection, andmayContainExternalCallcatch under-declared mechanics;unsafeYulstops false positives in logical-purity checks. Feature tests cover raw-call CEI propagation.Reviewed by Cursor Bugbot for commit fc265c3. Bugbot is set up for automated code reviews on this repo. Configure here.