Skip to content

Model keccak256 opcode, unaligned calldata, and SHA-256 engine in executable semantics#1943

Open
Th0rgal wants to merge 20 commits into
mainfrom
sphincs-raw-revert-support
Open

Model keccak256 opcode, unaligned calldata, and SHA-256 engine in executable semantics#1943
Th0rgal wants to merge 20 commits into
mainfrom
sphincs-raw-revert-support

Conversation

@Th0rgal
Copy link
Copy Markdown
Member

@Th0rgal Th0rgal commented Jun 1, 2026

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): new
    keccakMemorySlice / memorySliceBytesBE / wordToBytesBE helpers and
    .keccak256 arms in evalExpr / evalExprWithHelpers, wired to the
    in-tree KeccakEngine. Previously the first keccak made execStmt
    revert, making the accept subdomain provably unreachable.
  • Unaligned calldataloadWord (Calldata.lean): EVM-faithful
    byte-addressed 32-byte window for unaligned offsets (r != 0), composing
    hi/lo words big-endian with zero-padding. Aligned reads (r = 0) reduce
    to the prior single-word behaviour exactly. Needed for C13 auth-path
    sibling reads at 16-byte-strided offsets.
  • Kernel-computable SHA-256 engine (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 for
keccak256_memory_slice_matches_evm. No new sorry; keccak engine is
cross-checked against the EVM engine.

Test plan

  • lake build of SourceSemantics + reverse-dep importers green
  • SHA-256 engine reference-vector tests pass (incl. 56-byte padding boundary)
  • Downstream SphincsMinusVerifiers builds against this branch

Note

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.keccak256 via word-aligned memory slicing and the in-tree KeccakEngine (previously always none/revert). Helper-aware evaluation and SupportedSpec surface scans treat keccak256 as supported and recurse into offset/size operands. Trust docs document keccak256_memory_slice_matches_evm.

calldataloadWord is updated for EVM-faithful unaligned 32-byte reads (hi/lo composition); aligned reads stay behavior-identical. Proof tweaks in FunctionBody.lean follow the new branches.

New kernel-computable SHA-256 engine (Compiler/Sha256/Engine.lean) with FIPS reference-vector tests, wired into Compiler.lean build — not hooked into the source interpreter yet.

Raw Yul validation gains AST scans for call/staticcall/delegatecall so CEI, external-call detection, and mayContainExternalCall catch under-declared mechanics; unsafeYul stops 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.

Th0rgal added 14 commits May 28, 2026 12:30
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.
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
verity Ready Ready Preview, Comment Jun 1, 2026 9:22pm

Request Review

@Th0rgal
Copy link
Copy Markdown
Member Author

Th0rgal commented Jun 1, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

Comment thread Compiler/CompilationModel/Validation.lean Outdated
Comment thread Compiler/CompilationModel/LogicalPurity.lean
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

\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```

Comment thread Compiler/CompilationModel/LogicalPurity.lean Outdated
Th0rgal added 2 commits June 1, 2026 15:00
…pport

# Conflicts:
#	Compiler/CompilationModel/Types.lean
#	Compiler/CompilationModel/Validation.lean
#	Compiler/CompilationModelFeatureTest.lean
Comment thread Compiler/Proofs/IRGeneration/SourceSemantics.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.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread Compiler/Sha256/Engine.lean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant