Skip to content

Work Contract Language 2: arithmetic and aggregates (WVP RFC 0008) - #61

Open
SrishtiCode wants to merge 4 commits into
mainfrom
feat/wcl2-arithmetic-aggregates
Open

SrishtiCode wants to merge 4 commits into
mainfrom
feat/wcl2-arithmetic-aggregates

Conversation

@SrishtiCode

Copy link
Copy Markdown
Collaborator

Implements Work Contract Language 2 as WVP RFC 0008 proposes it (dekrops/wvp#47): exact integer arithmetic on terms, plus count, count with distinct, and sum over the records of a closed kind. This is step 1 of productizing the F007 invoice-to-payment model, which needs arithmetic.

What changes

verified-contract:

  • Language and Contract::read_as(json, Language). Contract::read still reads Language 1 only, so the verifier and WVP v0.2 packages are unchanged: a package whose contract names work-contract-2 is still refused, as RFC 0008's compatibility section requires. Versions are never interchanged. Read as Language 2, a work-contract-1 contract is CONTRACT_ILL_FORMED (v2 case 27), and Language 2's forms are not forms of Language 1 (CONTRACT_MALFORMED).
  • Terms: add, sub, scale and abs, typed as the RFC says:
    • both operands of one numeric type, with that type;
    • time − time gives int seconds;
    • a scale factor out of range is CONTRACT_ILL_FORMED (case 281).
  • Aggregates: { aggregate, of, in, where, cmp, than }, with field for sum and distinct for count.
    • The variable is bound in the body only.
    • An aggregate counts toward the quantifier depth of 3.
    • It has a value only over a closed kind with every body settled.
  • Node count: arithmetic nodes count toward the 512-node limit and the work bound. The read depth of 64 counts them too.
  • Evaluation: every term is evaluated under every binding, whatever the predicates around it (no short-circuit), and only on the records step 5 keeps.
    • Each arithmetic node with a value, and each aggregate value, must lie strictly between −2⁶³ and 2⁶³, or the evaluation refuses with the new Refusal::ArithmeticRange (ARITHMETIC_RANGE).
    • Arithmetic is done in i128. A sum's running total is exact, and only the total is checked.
  • Language 1 behaviour is unchanged. Its terms never refuse, so evaluating everything changes no Language 1 outcome.

Tests

  • tests/conformance.rs now also runs work-contract/v2 when VERIFIED_CONFORMANCE_DIR holds it (RFC 0008's proposed vectors, from wvp branch rfc/wcl2-amounts-aggregates), and skips it otherwise.
  • Local result, with the v1 corpus from wvp main and the v2 vectors from that branch:
    • work-contract-1: 641 cases reproduced;
    • work-contract-2: 697 cases reproduced. That's every case except 72-scale-not-whole, which uses a fractional JSON number and can't be represented in verified-json-v1, the same as in v1.
  • Mutation check: three deliberate bugs each make the v2 test fail:
    • an aggregate ignoring closure;
    • no range check;
    • a short-circuiting and.
  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace and cargo doc pass.

To run the corpora locally:

mkdir -p /tmp/conf/work-contract
git -C ../wvp archive origin/main test-vectors/work-contract/v1 | tar -x -C /tmp/conf --strip-components=1
git -C ../wvp archive origin/rfc/wcl2-amounts-aggregates rfcs/0008/vectors/work-contract/v2 | tar -x -C /tmp/conf/work-contract --strip-components=4
VERIFIED_CONFORMANCE_DIR=/tmp/conf cargo test -p verified-contract --test conformance -- --nocapture

Breaking change and version bump

Adding Refusal::ArithmeticRange to the public, exhaustive Refusal enum is a breaking API change for cargo-semver-checks. Following docs/development/releasing.md, this PR bumps the workspace from 0.2.0 to 0.3.0 ([workspace.package] and each [workspace.dependencies] entry, then cargo update --workspace).

What a consumer changes: an exhaustive match on verified_contract::Refusal needs an arm for ArithmeticRange. Nothing in this workspace has one.

While the API is breaking anyway, Refusal could be made #[non_exhaustive], so the next language feature doesn't need another bump. I left that out; it's your call.

Not in this PR

  • Packages carrying Language 2. That needs a WVP package version, RFC 0003 or its own, as RFC 0008 says.
  • A conformance report in wvp/conformance. That waits until the vectors are published on RFC 0008's acceptance.
  • The F007 contracts and the cross-check against F007's Lean evaluator. Those are the next steps.

🤖 Generated with Claude Code

Contract::read_as reads a contract as Language 1 or 2; Contract::read stays Language 1. Adds add/sub/scale/abs, count/distinct/sum over closed kinds, full evaluation and ARITHMETIC_RANGE. Reproduces all 697 proposed v2 vectors. Bumps the workspace to 0.3.0 for the new Refusal variant.
@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Claude Code Review — WCL2 arithmetic and aggregates

Reviewing in progress.

  • Read repo context (CLAUDE.md, CONTRIBUTING, architecture, threat-model, compatibility, relevant DRs)
  • Review crates/verified-contract/src/read.rs (Language enum, L2 forms, limits)
  • Review crates/verified-contract/src/check.rs (static check: ranges, aggregate rules, depth)
  • Review crates/verified-contract/src/evaluate.rs (arithmetic, aggregates, i128, closure)
  • Review crates/verified-contract/src/model.rs and lib.rs (Refusal, public API)
  • Review tests and docs
  • Post inline findings and summary

View job run · branch: feat/wcl2-arithmetic-aggregates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Claude finished @SrishtiCode's task in 8m 6s —— View job


Claude Code Review — WCL2 arithmetic and aggregates

  • Read repo context (CLAUDE.md, CONTRIBUTING, architecture, threat-model, compatibility, relevant DRs)
  • Review crates/verified-contract/src/read.rs (Language enum, L2 forms, limits)
  • Review crates/verified-contract/src/check.rs (static check: ranges, aggregate rules, depth)
  • Review crates/verified-contract/src/evaluate.rs (arithmetic, aggregates, i128, closure)
  • Review crates/verified-contract/src/model.rs and lib.rs (Refusal, public API)
  • Review tests and docs
  • Post findings and summary

Claude review: no actionable issues found.

PR summary

Adds Work Contract Language 2 (RFC 0008, under review) as a library path via Contract::read_as: exact integer arithmetic (add/sub/scale/abs), aggregates (count, count distinct, sum) over closed kinds, and a new Refusal::ArithmeticRange. Contract::read still only reads Language 1, so packages continue to refuse work-contract-2, matching RFC 0008's compatibility section. The workspace version is bumped to 0.3.0 because adding to the exhaustive Refusal enum is a breaking API change.

Key changes reviewed

  • read.rs: new Language enum plumbed through; arithmetic terms and aggregate predicate form added as Language 2-only; arithmetic nodes count toward MAX_PREDICATE_DEPTH = 64; scale factor out of i64 range reads as None for the static check to refuse.
  • check.rs: term_type extended for Add/Sub (same numeric type; time − time → int), Scale, Abs; aggregate_type restricts count (optional distinct non-optional field, any type) and sum (non-optional numeric field); no shadowing; aggregate's than is typed in enclosing scope (variable bound in body only).
  • evaluate.rs: arithmetic in i128 with per-node in_range check against (−2⁶³, 2⁶³) that excludes i64::MIN; aggregates computed only over a closed kind with every body settled, over step-5 kept records; pred/preds/bodies restructured so sibling predicates are fully evaluated (no short-circuit through And/Or) before all/any reduce.
  • model.rs: Term::{Add,Sub,Scale,Abs}, Pred::Aggregate, Function, Aggregation; Pred::nodes and Pred::quantifier_depth now include arithmetic nodes and aggregates respectively; Type::is_numeric added.
  • lib.rs: Language::{One, Two}, LANGUAGE_2, and Refusal::ArithmeticRange with stable code ARITHMETIC_RANGE.
  • Tests: tests/conformance.rs runs work-contract/v2 when the env dir holds it and skips otherwise; expected outcomes read from the corpus. Docs (compatibility.md, architecture/overview.md, README.md) note Language 2 is library-only.

Areas reviewed

  • Static rules: typing of arithmetic and aggregates; non-optional and numeric constraints; no variable shadowing; depth/node/quantifier bounds including arithmetic.
  • Runtime safety of i128 arithmetic: with MAX_FACTS = 10_000 and i64 operands, no overflow in sum (bounded ≈ 2⁷⁷), a + b/a − b (≤ 2⁶⁴), v * factor (≤ 2¹²⁶), or abs (operand never i128::MIN). in_range rejects both i64::MIN and |x| ≥ 2⁶³.
  • Language separation: Contract::read only accepts Language 1; verifier and issue/work_contract paths call Contract::read, so work-contract-2 packages remain refused. Reading as Language 2 refuses a Language 1 contract as CONTRACT_ILL_FORMED and a Language 2 form inside a Language 1 read as CONTRACT_MALFORMED via read_term's language gate.
  • Aggregate closure and conflicts: aggregate evaluates to a value only when self.closed.contains(kind) AND every body is settled; records come from Settled.records, which is the step-5 kept map, so conflicts, ignored sources, and nonconforming facts are properly excluded.
  • Refusal ordering: ARITHMETIC_RANGE is surfaced at steps 7–8, after WORK_LIMIT (step 4) and ENVIRONMENT_NONCONFORMING (steps 1/3/6), matching the specification's first-failure rule.
  • Reader forms: read_pred's aggregate branch runs only(…) on allowed members before accepting, so stray or wrong-shape members are CONTRACT_MALFORMED; aggregate form doesn't collide with other predicate shapes.
  • Distinctness semantics: BTreeSet<Val>-based distinct count aligns with the language's eq, since all records of a kind share the field's declared Type (no cross-currency, cross-scale, or cross-variant comparisons).
  • Boundaries: no I/O, clock, env, randomness, or unsafe added; crate is still library-only and additions respect the documented crate boundaries.
  • Docs: docs/protocol/compatibility.md and docs/architecture/overview.md correctly describe Language 2 as library-only; no claim about packages carrying Language 2 is introduced.

Areas skipped

  • Cargo.lock / fuzz/Cargo.lock version-bump mechanics (lockfile update only).
  • The conformance corpus itself, which lives outside the repository.

Findings

  • Severity totals: Critical 0, High 0, Medium 0, Low 0.
  • Inline references: none.

Residual risks

  • None identified against the changed lines. Agreement with the published Language 2 vectors (once RFC 0008 lands) is the remaining external check; the local 697/698 reproduction reported in the PR description, and the three mutation checks (closure ignored, no range check, short-circuiting and), are consistent with the implementation.
    · branch: feat/wcl2-arithmetic-aggregates

@claude

claude Bot commented Nov 17, 2026

Copy link
Copy Markdown

Ponytail · complexity review

Tag Location Finding
shrink crates/verified-contract/src/evaluate.rs:L403 Combined `Term::Add(a, b)
shrink crates/verified-contract/src/read.rs:L806 const MEMBERS: [&str; 6] is declared only to be immediately consumed in a .concat() call building the slice for only(). Inline the full eight-element slice literal directly into the only() call and repeat the five required-key names in the guard; MEMBERS and the heap allocation disappear. ~2 lines shorter.

net: -5 lines possible.

@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Claude finished @SrishtiCode's task in 4m 19s —— View job


Claude Code Review — WCL2 arithmetic and aggregates (synchronize)

  • Read repo context (CLAUDE.md, CONTRIBUTING, compatibility, threat-model)
  • Review read.rs (Language enum, L2 forms, limits)
  • Review check.rs (static check: ranges, aggregate rules, depth)
  • Review evaluate.rs (arithmetic, aggregates, i128, closure)
  • Review model.rs and lib.rs (Refusal, public API)
  • Review tests and docs
  • Post findings and summary

Claude review: no actionable issues found.

PR summary

Adds Work Contract Language 2 (RFC 0008, under review) as a library path via Contract::read_as: exact integer arithmetic (add/sub/scale/abs), aggregates (count, count distinct, sum) over closed kinds, and a new Refusal::ArithmeticRange (code ARITHMETIC_RANGE). Contract::read still only reads Language 1, so verified-verifier's verify, issue and work_contract paths continue to refuse work-contract-2 packages, matching RFC 0008's compatibility clause. The newest commit on this branch adds a RUSTSEC-2026-0543 advisory ignore to deny.toml and fuzz/deny.toml for chrono (unmaintained, not vulnerable; pulled in only by cedar-policy-core via verified-derivation). Workspace is bumped to 0.3.0 because adding to the exhaustive Refusal enum is a breaking API change.

Key changes reviewed

  • read.rs: Language enum and read_as(json, language) plumbed through; arithmetic terms and aggregate predicate are Language 2-only and gated by read_term's language check; arithmetic depth counts toward MAX_PREDICATE_DEPTH = 64; scale factor outside i64 (and i64::MIN) reads as None for the static check to refuse; read_aggregate runs only(…) over the allowed set {aggregate, of, in, where, cmp, than, field, distinct} before accepting.
  • check.rs: term_type extended for Add/Sub (same numeric type; time − time → int), Scale, Abs; aggregate_type restricts count (no field, or non-optional field for distinct, type int) and sum (non-optional numeric field, the field's type); no shadowing (scope.iter().any(|(bound, _)| bound == variable)); aggregate's than is typed in enclosing scope before the aggregate's variable is pushed.
  • evaluate.rs: arithmetic in i128 with per-node in_range check against (−2⁶³, 2⁶³) that excludes i64::MIN; aggregates computed only when self.closed.contains(kind) AND every body is settled; records come from Settled.records (the step-5 kept map, so ignored sources and unresolved conflicts are excluded); pred/preds/bodies restructured so sibling predicates are fully evaluated (no short-circuit through And/Or) before all/any reduce; than in Pred::Aggregate is evaluated with the enclosing scope.
  • model.rs: Term::{Add, Sub, Scale, Abs}, Pred::Aggregate, Function, Aggregation; Term::arithmetic_nodes and Pred::nodes fold arithmetic nodes into the 512-node bound; Pred::quantifier_depth counts aggregates toward the depth of 3; Type::is_numeric added.
  • lib.rs: Language::{One, Two}, LANGUAGE_2, Refusal::ArithmeticRange with stable code ARITHMETIC_RANGE.
  • Tests: tests/conformance.rs runs work-contract/v2 under Language::Two when present and skips otherwise; corpus expectations never adjusted here. Docs (compatibility.md, architecture/overview.md, README.md) correctly describe Language 2 as library-only. deny.toml/fuzz/deny.toml ignore RUSTSEC-2026-0543 with a documented rationale.

Areas reviewed

  • Static rules: typing of arithmetic and aggregates; non-optional/numeric constraints for distinct/sum; no variable shadowing; nodes/quantifier bounds including arithmetic nodes.
  • Runtime arithmetic safety of i128: with MAX_FACTS = 10_000 and all operands derived from i64, sum is bounded by ≈ 2⁷⁷, a + b/a − b ≤ 2⁶⁴, v * factor ≤ 2¹²⁶, i128::abs is never called on i128::MIN (operand magnitude ≤ 2⁶³). in_range rejects i64::MIN and any |x| ≥ 2⁶³.
  • Language separation: Contract::read only accepts Language 1; verified-verifier (work_contract.rs:206, issue.rs:262) and verified-derivation (lib.rs:408) all call Contract::read, so work-contract-2 packages still refuse as CONTRACT_ILL_FORMED via is_well_formed's self.language == language.id() check. Reading a Language 2 form inside a Language 1 read is CONTRACT_MALFORMED via read_term's language gate.
  • Aggregate closure and conflicts: aggregate evaluates to a value only when kind is closed AND all body values are settled; closed kinds come from a source the contract accepts (self.accepts(c.kind, c.source)) and exclude kinds with unresolved conflicts (!open.contains(kind)), and Settled.records is the step-5 kept map. Trust still comes from the contract's declared sources, not the package's words.
  • Refusal ordering: ARITHMETIC_RANGE is surfaced at steps 7–8, after WORK_LIMIT (step 4) and ENVIRONMENT_NONCONFORMING (steps 1/3/6), matching the "first failure must agree" rule.
  • Reader forms: read_pred's aggregate branch runs only(…) on allowed members before accepting, so stray or wrong-shape members are CONTRACT_MALFORMED; aggregate form doesn't collide with Compare (which uses exactly for {cmp, left, right}).
  • Distinctness semantics: BTreeSet<Val>-based distinct count matches the language's eq, since all records of a kind share the declared Type (no cross-currency/scale/variant comparisons).
  • Boundaries: no new I/O, clock, env, randomness, or unsafe; verified-contract stays library-only. The only std::fs/std::env additions are in the tests/conformance.rs harness.
  • Advisory ignore: RUSTSEC-2026-0543 is for chrono (unmaintained, no replacement); rationale is specific and documented in deny.toml and fuzz/deny.toml; chrono enters only via cedar-policy-core, which the compatibility notes already position outside the promise (ADR 0016).
  • Docs: compatibility.md and overview.md state Language 2 is library-only; no claim about packages carrying Language 2 is added.

Areas skipped

  • Cargo.lock / fuzz/Cargo.lock version-bump mechanics (lockfile updates only).
  • The Language 2 conformance corpus itself, which lives outside this repository.

Findings

  • Severity totals: Critical 0, High 0, Medium 0, Low 0.
  • Inline references: none.

Residual risks

  • None identified against the changed lines. The remaining external check is agreement with the published Language 2 vectors (once RFC 0008 lands); the local 697/698 reproduction reported in the PR description, the three mutation checks (closure ignored, no range check, short-circuiting and), and the unchanged Language 1 reproduction (641 cases) are consistent with the implementation.
    · branch: feat/wcl2-arithmetic-aggregates

@claude

claude Bot commented Nov 17, 2026

Copy link
Copy Markdown

Ponytail · complexity review

Tag Location Finding
shrink crates/verified-contract/src/read.rs:L117-121 spelled bool accumulates four guard conditions then immediately if !spelled { return Err(MALFORMED) }. The intermediate bool buys nothing; invert to a direct early-return guard.
shrink crates/verified-contract/src/read.rs:L254-255 const MEMBERS + [&MEMBERS[..], &["field", "distinct"]].concat() allocates a Vec on every call just to pass to only(). Inline the full eight-key slice literal directly in only() and restate the six-key required slice in the all() check; removes the const and the heap alloc.

net: -3 lines possible.

@SrishtiCode

Copy link
Copy Markdown
Collaborator Author

Ponytail: applied the add/sub split. Kept read.rs as is: inlining the eight-element slice makes rustfmt spread it over ten lines, so the change comes out longer, not shorter.

@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Claude finished @SrishtiCode's task in 5m 24s —— View job


Claude Code Review — WCL2 arithmetic and aggregates (synchronize)

  • Read repo context (CLAUDE.md, CONTRIBUTING, architecture, threat-model, compatibility, relevant DRs)
  • Review read.rs (Language enum, L2 forms, limits)
  • Review check.rs (static check: ranges, aggregate rules, depth)
  • Review evaluate.rs (arithmetic, aggregates, i128, closure)
  • Review model.rs and lib.rs (Refusal, public API)
  • Review tests and docs
  • Post findings and summary

Claude review: no actionable issues found.

PR summary

Adds Work Contract Language 2 (WVP RFC 0008, under review) as a library-only path via Contract::read_as: exact integer arithmetic (add/sub/scale/abs), aggregates (count, count distinct, sum) over closed kinds, plus the new Refusal::ArithmeticRange (stable code ARITHMETIC_RANGE). Contract::read still only reads Language 1, so verified-verifier's verify, issue, work_contract and verified-derivation paths continue to refuse work-contract-2 packages, as RFC 0008's compatibility clause requires. The branch also adds an advisory ignore for RUSTSEC-2026-0543 (chrono unmaintained, not vulnerable, only via cedar-policy-core). Workspace is bumped to 0.3.0 because the exhaustive Refusal enum gains a variant.

Key changes reviewed

  • read.rs: Language enum and read_as(json, language) plumbed through; arithmetic terms and aggregate predicate are Language 2-only and gated by read_term's language check; arithmetic depth counts toward MAX_PREDICATE_DEPTH = 64; scale factor outside i64 (and i64::MIN) reads as None for the static check to refuse; read_pred's aggregate branch runs only(…) over {aggregate, of, in, where, cmp, than, field, distinct} and requires the six mandatory members, falling through to CONTRACT_MALFORMED otherwise.
  • check.rs: term_type extended for Add/Sub (same numeric type; time − time → int), Scale, Abs; aggregate_type restricts count (no field, or non-optional field for distinct, type int) and sum (non-optional numeric field, the field's type); no variable shadowing; than typed in enclosing scope before the aggregate variable is pushed.
  • evaluate.rs: arithmetic in i128 with per-node in_range check against (−2⁶³, 2⁶³) that excludes i64::MIN; aggregates computed only when self.closed.contains(kind) AND every body is settled; records come from Settled.records (the step-5 kept map); pred/preds/bodies restructured so sibling predicates are fully evaluated (no short-circuit through And/Or) before all/any reduce; than evaluated with the enclosing scope.
  • model.rs: Term::{Add, Sub, Scale, Abs}, Pred::Aggregate, Function, Aggregation; Term::arithmetic_nodes and Pred::nodes fold arithmetic nodes into the 512-node bound; Pred::quantifier_depth counts aggregates toward the depth of 3; Type::is_numeric added.
  • lib.rs: Language::{One, Two}, LANGUAGE_2, Refusal::ArithmeticRange.
  • Tests and docs: tests/conformance.rs runs work-contract/v2 under Language::Two when present and skips otherwise; corpus expectations never adjusted here. compatibility.md, architecture/overview.md, and README.md correctly describe Language 2 as library-only. deny.toml/fuzz/deny.toml ignore RUSTSEC-2026-0543 with a documented, specific rationale.

Areas reviewed

  • Static rules: typing of arithmetic and aggregates; non-optional/numeric constraints for distinct/sum; no variable shadowing; node/quantifier bounds including arithmetic nodes.
  • Runtime arithmetic safety: with MAX_FACTS = 10_000 and all operands derived from i64, sum is bounded by ≈ 2⁷⁷, a + b/a − b ≤ 2⁶⁴, v * factor ≤ 2¹²⁶, i128::abs is never called on i128::MIN (operand magnitude ≤ 2⁶³). in_range rejects i64::MIN and any |x| ≥ 2⁶³.
  • Language separation: Contract::read only accepts Language 1; verified-verifier (work_contract.rs:206, issue.rs:262) and verified-derivation (lib.rs:408) all call Contract::read, so work-contract-2 packages still refuse as CONTRACT_ILL_FORMED via is_well_formed's self.language == language.id() check. A Language 2 form inside a Language 1 read is CONTRACT_MALFORMED via read_term's language gate.
  • Aggregate closure and conflicts: aggregate yields a value only when the kind is closed AND all body values are settled; closed kinds come from a source the contract accepts (self.accepts(c.kind, c.source)), filter the cutoff, and exclude kinds with unresolved conflicts (!open.contains(kind)); Settled.records is the step-5 kept map. Trust still comes from the contract's declared sources, not the package's words.
  • Refusal ordering: ARITHMETIC_RANGE is surfaced at steps 7–8, after WORK_LIMIT (step 4) and ENVIRONMENT_NONCONFORMING (steps 1/3/6), matching the "first failure must agree" rule.
  • Reader forms: read_pred's aggregate branch runs only(…) on allowed members and then verifies all six required members are present before accepting, so stray or wrong-shape members are CONTRACT_MALFORMED; the aggregate form doesn't collide with Compare (exactly with {cmp, left, right}).
  • Distinctness semantics: BTreeSet<Val>-based distinct count matches the language's eq, since all records of a kind share the declared Type (no cross-currency/scale/variant comparisons).
  • Boundaries: no new I/O, clock, env, randomness, or unsafe; verified-contract stays library-only. The only std::fs/std::env additions are in tests/conformance.rs and skip gracefully if VERIFIED_CONFORMANCE_DIR is unset.
  • Advisory ignore: RUSTSEC-2026-0543 is chrono (unmaintained, no replacement release); the rationale is specific and documented in both deny.toml and fuzz/deny.toml; chrono enters only via cedar-policy-core, which the compatibility notes position outside the promise (ADR 0016).
  • Docs: compatibility.md and overview.md state Language 2 is library-only; no claim about packages carrying Language 2 is added.

Areas skipped

  • Cargo.lock / fuzz/Cargo.lock version-bump mechanics (lockfile updates only).
  • The Language 2 conformance corpus itself, which lives outside this repository.

Findings

  • Severity totals: Critical 0, High 0, Medium 0, Low 0.
  • Inline references: none.

Residual risks

  • None identified against the changed lines. Agreement with the published Language 2 vectors (once RFC 0008 lands) is the remaining external check; the local 697/698 reproduction reported in the PR description, the three mutation checks (closure ignored, no range check, short-circuiting and), and the unchanged Language 1 reproduction (641 cases) are consistent with the implementation.
    · branch: feat/wcl2-arithmetic-aggregates

@claude

claude Bot commented Nov 17, 2026

Copy link
Copy Markdown

Ponytail · complexity review

Tag Location Finding
shrink crates/verified-contract/src/read.rs:L254–258 const MEMBERS builds an allocated Vec via .concat() and gates read_aggregate with an all() presence check that is redundant — every required key is already demanded by need() inside read_aggregate, which returns MALFORMED on the first missing one. Replace the five-line block with two lines: only(value, &["aggregate", "of", "in", "where", "cmp", "than", "field", "distinct"])?; return read_aggregate(o, depth, language);

net: -3 lines possible.

@zy4 zy4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed: technically sound. I'll approve once RFC 0008 is accepted.

Checked

  • Reproduced the conformance locally: work-contract-1 641 cases, work-contract-2 697 cases, plus the one known case not representable in verified-json-v1 (72-scale-not-whole).
  • The review decisions on RFC 0008 are all here: a range check on every arithmetic node with a value and on each aggregate value; an exact running total in i128 inside sum, checked only at the end; no short-circuit, so ARITHMETIC_RANGE never depends on evaluation order; time not numeric, only time − time → int; sum only over non-optional numeric fields; count/distinct over a non-optional field; the aggregate's variable bound in its body only, than typed in the enclosing scope.
  • An aggregate has a value only over a closed kind with every body settled, otherwise UNKNOWN.
  • Contract::read stays Language 1, so WVP v0.2 packages are unchanged.
  • No overflow is possible in i128 (sums ≤ 10,000 × 2⁶³, products ≤ 2⁶³ × 2⁶³).

Before merging

  1. Wait for RFC 0008's acceptance (review period until at least 2026-11-24). Then write the decision into the RFC and move the vectors to test-vectors/work-contract/v2, then merge this.
  2. Yes to #[non_exhaustive] on Refusal in this PR. The API breaks anyway at 0.3.0, and the next language feature won't need another major bump.
  3. Merge #62 first and rebase, so the chrono ignore isn't in this PR twice.

Not blocking: values are cloned per evaluation now, text included. That's fine under the work bound; borrowing again (Cow) can come later.

For the RFC, not this PR: aggregates are predicates, not terms, so Σ(net + tax) = gross can't be written directly (your F007 finding). I'll decide on #47 whether that goes into 0008 before acceptance, which would restart the period, or into a follow-up.

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.

2 participants