Skip to content

feat: prove and execute balance aggregation - #9

Merged
adust09 merged 2 commits into
mainfrom
feat/aggregate-balances
Nov 12, 2026
Merged

adust09 merged 2 commits into
mainfrom
feat/aggregate-balances

Conversation

@adust09

@adust09 adust09 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Complete the standalone balance aggregation used by the pinned caller of weigh_justification_and_finalization.

  • Compute total active, previous-target, and current-target balances from validator records and participation flags, with the official max(10^9, sum) floor.
  • Prove the 78-instruction modeled RV64 routine's result, input-array and frame preservation, and return within 52 * N + 24 steps. Include a satisfiable concrete calling witness and the transitive axiom audit.
  • Emit aggregate.elf (312 code bytes), add a JSON-lines runner with strict admission and ELF validation, and provide a checked host-interpreter benchmark.
  • Fix the loop back jump to -208, own every used register in the contract, preserve consumed cells through induction, and add LUI/SUB emission and independent encoding checks.
  • Add contract/runner documentation and update the roadmap. weigh and its ZisK wrapper are unchanged.

Validation

  • lake --no-cache --wfail build: pass without warnings.
  • lake env lean scripts/CheckAxioms.lean: pass; 4,848 declarations, only Classical.choice, Quot.sound, and propext.
  • .lake/build/bin/cl-asm build and .lake/build/bin/cl-asm-test build: pass, including preservation corruption, non-return, and unaligned-access rejection.
  • .venv/bin/python -m unittest discover -s tests -v: 32 tests pass, including CLI usage diagnostics (verified failing before the fix).
  • 793 deterministic official aggregation differential cases; all 256 participation flags, epoch/eligibility boundaries, slashing, floors, and overflow rejection.
  • 32,768-validator capacity boundary executes successfully; the runner rejects 32,769.
  • Independent ELF bytes, branch destinations, image mutation rejection, and benchmark checksum/count checks pass.
  • Existing weigh regression: 4,796 official differential cases, 99–147 steps.

The local interpreter executes 21 + 52 * N + e steps, where e counts the raw sums at least 10^9 (0–3). The proved upper bound is 52 * N + 24.

Boundaries

Lean proves the modeled instruction sequence, not the ELF itself. Assembly/linking/loading, interpreter conversion, JSON admission, and agreement with the pinned Python operation are tested. The layout is internal, not SSZ. Aggregation ZisK integration and proof-generation benchmarks remain separate work.

Review and finding dispositions

The required implementation_done gate reviewed the complete 31-file candidate in 10 chunks. gpt-oss-120b responded to every chunk; bonsai2, glm5.3, and qwen-flash timed out and are not counted as approvals. Six responding chunk reviews reported findings. This is not unanimous panel approval.

One issue was fixed. A second implementation_done run reviewed the resulting two-file, 11-line follow-up against the exact first reviewed tree. Its sole responding reviewer alleged an undefined usage; this is declined because AggregateMain.lean:5 defines it, and the rebuilt executable passes the regression test and --help check. The other three reviewers remained unavailable, not approving. No source edits followed that review.

All other first-round findings were checked and explicitly declined as follows; none is silently deferred. IDs refer to the chunk and its numbered finding (or severity section).

Finding Disposition and evidence
1/1: changed contract callers Declined: all callers compile with the new contract; the warning-free build, whole-program proof, and concrete calling witness pass.
1/2: final argument registers Declined: callRegisters a input n advances each pointer by its stride times n and sets the counter to length - n = 0; it does not restore the initial pointers.
1/3: generic exceptions Declined: rejection deliberately hides exception internals, paths, and stack traces. Nonzero exit status is preserved; usage guidance is now printed without exposing the original exception.
1/4: missing usage on invalid arguments Fixed: print usage after rejection. A regression test covers no arguments, an unknown option, and a nonnumeric benchmark count; it failed before the fix and passes afterward.
1/5: strict benchmark checksum Declined: the interpreter is deterministic; detecting changed results is the purpose of the checksum. The checked repeated-execution test passes.
2/1, 2/5, 2/9: tactic imports Declined: the required tactics are available through the imports; the warning-free Lean build checks every use. This project does not require adding Mathlib.
2/2: missing signForty095 Declined: defined in ClAsm/Aggregate/Loop.lean:33, imported by Correctness.lean.
2/3, 2/4, 2/6, 2/7, 2/8: inferred arguments and side conditions Declined: Lean checks these proof terms, offsets, branch contradictions, and inferred assertions. The full build and transitive axiom audit pass.
3/1: zero-step fuel check Declined: executeLoop checks return before fuel, so an already-returned state succeeds with zero fuel and would fail the isNone requirement rather than pass it. Validated routine entry differs from return; differential cases require at least 21 steps.
3/2: sentinel-address underflow Declined: the fixed bases are at least 0xa0000000; none can underflow when subtracting eight. Moreover, Lean Nat subtraction saturates at zero, not a huge wrapped value.
3/3: range notation Declined: [0:32] is supported Lean range notation; compilation and preservation tests pass.
3/4: proof-variable shadowing Declined: the new binding is the extended version of the previous proof term. No behavioral defect was identified; Lean checks the result.
7/severity 1: missing namespace/imports/identifiers Declined: the complete file imports Correctness on line 1 and opens the namespace on line 3. Required hypotheses are in loop_frame's signature; the chunk omitted this earlier context. The full module compiles.
7/severity 2: slashed values and arithmetic Declined: ValidInput.slashed and the explicit hslashed hypothesis require 0 or 1; the induction passes this hypothesis onward. All arithmetic proof goals are discharged by Lean.
7/severity 3: brittle proof style Declined: speculative maintenance advice, not a current failure. No unproved goals or additional axioms remain.
9/1, 9/2, 10/3: signed LUI encoding Declined: emission and the manifest both use the raw 20-bit U-immediate field; sign extension belongs to instruction execution. A GNU mnemonic-assembly experiment matches the independent encoder for 0, 1, 0x3B9AD, 0x7FFFF, 0x80000, 0xFFF00, and 0xFFFFF, plus SUB. Masking -256 gives the same encoding as 0xFFF00.
9/3: missing executable root Declined: AggregateMain.lean exists at repository root and builds the executable exercised by the tests; it appeared in an earlier review chunk.
9/4: extreme epochs Declined: even at the maximum slot, epoch + 1 <= 2^59 < 2^64. These intentionally admitted boundary cases pass the official-reference differential test.
9/5: namespace opening Declined: the existing qualified Aggregate.Test.checkHarness call compiles and runs. Hypothetical future unqualified references are not a present defect.
9/6: documentation link Declined: both docs/build.md and docs/aggregate.md exist in the same directory; the relative link is valid.
9/7: future axiom-audit failures Declined: rejecting newly introduced unauthorized axioms is intentional. The current audit passes with only the three allowed axioms.
10/1: assembly symbol injection Declined: this is an internal test helper; both callers use trusted literals/defaults (weigh and aggregate), not external input. Assembler/linker calls use argument arrays, not a shell.
10/2: undefined encoder operands Declined: a, b and c are bound before opcode dispatch. The typed generated manifests supply valid operand counts; the complete independent-encoding tests and the extra GNU experiment pass.
10/4: helper API break Declined: the optional symbol defaults to the previous literal weigh; existing two-argument calls retain their behavior. No failing caller was identified.

weigh still takes the three balances as arguments. This records the
pinned caller that computes them and the instruction sequence that
will implement that caller, before the loop proof and ELF checks.
Complete the caller-side balance aggregation so the modeled RV64 routine has a resource-preserving proof and bounded return, not just an instruction listing.

Validate emitted artifacts against the pinned official operation, reject malformed inputs and mutated images, and measure checked interpreter execution. Keep ELF validation outside the formal proof boundary and preserve the existing weigh routine.
@adust09 adust09 changed the title feat: start the balance-aggregation routine feat: prove and execute balance aggregation Nov 12, 2026
@adust09
adust09 marked this pull request as ready for review November 12, 2026 04:46
@adust09
adust09 merged commit 50ffc46 into main Nov 12, 2026
2 checks passed
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