fix(ergo-sigma): evaluator carrier/type/serialize fidelity (#215 findings 2, 4, 5) - #223
Merged
Conversation
…ng 5) Scala `Coll[A].patch` (CollsOverArrays) is generic over the element type, but the Rust impl matched only Byte/Int/Long carriers and rejected valid `Coll[Short]`, `Coll[Boolean]`, tuple, box, header, and generic-carrier receivers — a reject-valid (the node would reject a spend the reference accepts). Rewrite the carrier-specific match to the generic collection_to_values / values_to_collection path `updateMany` already uses, with a per-patched-element sigma_type_compatible check (Array[A] backing throws ArrayStoreException on a foreign element; an empty patch writes nothing and is accepted regardless of declared type, matching Scala). The oracle-verified splice-index algorithm and the Scala-anchored PerItemCost are unchanged. Tests: +Coll[Short] and +Coll[Boolean] carriers; all 12 existing CollInt/Byte/ Long splice-semantics tests still pass (identical results via the generic path). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw7uCwqmiGna8fpg6TvxGi
…eceiver (#215 finding 4) When the flatMap receiver is empty there is no inner collection to read the output shape from, so the result collapsed to Coll[Byte] even when the static result type is Coll[Long], Coll[Int], etc. — the wrong element-type tag, which serializes/dispatches differently from the reference (Scala threads RType[B]). Recover B from the mapper body's static Coll[B] type: Const{SColl(B)}, ConcreteCollection{elem_type=B}, and If-branches all determine B directly. A recovered type is always correct (it IS the body's collection element type), so this never introduces a new divergence; bodies whose type isn't statically determinable from the IR node keep the legacy Coll[Byte] fallback — a documented, strictly-smaller residual. Tests: empty receiver with a Coll[Long] Const body and a Coll[Int] ConcreteCollection body both yield the correctly-typed empty collection. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw7uCwqmiGna8fpg6TvxGi
Contributor
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe evaluator now supports context-aware box serialization, preserves collection element types for empty ChangesEvaluator updates
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…rs (#215 finding 2) value_to_typed_sigma rejected SELF / INPUTS / OUTPUTS / DATAINPUTS / Coll[Box] in its catch-all, so serialize(SELF), serialize(INPUTS), serialize(SELF.tokens) etc. failed where Scala accepts — a reject-valid. Thread an Option<&ReductionContext> through value_to_typed_sigma. On the SGlobal.serialize path (Some) the box carriers resolve via the existing resolve_box to their concrete boxes and emit OpaqueBoxBytes(raw_bytes) — the SAME canonical bytes ExtractBytes (0xC3) and the InlineBox arm already use, which is exactly what Scala DataSerializer/ErgoBox.sigmaSerializer writes, so this is correct by analogy to those oracle-verified paths (no new byte format). BoxCollection resolves to Coll[SBox]; CollBox resolves each element. On the SubstConstants path (None) behavior is unchanged — a context box as a substituted constant stays unsupported (pre-existing, narrower residual). Test: SelfBox resolves through a context to the box's canonical bytes (matching the InlineBox path); rejects without a context. ergo-sigma suite 503 -> 504. NOTE: verified against the reference by analogy to ExtractBytes/InlineBox (identical raw_bytes); a JVM-oracle differential on top-level serialize(SELF)/ serialize(INPUTS) vectors is still recommended before relying on it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw7uCwqmiGna8fpg6TvxGi
…tor fixes Adds a (scala-cli-gated, #[ignore]) reduce-surface differential that pins the #215 serialize/flatMap fixes against the sigma-state 6.0.2 reference, replacing the "verified by source-analogy" caveat with an actual oracle run: serialize(SELF)==SELF.bytes node=P:d3|142 jvm=P:d3|142 serialize(INPUTS).size>0 node=P:d3|145 jvm=P:d3|145 empty flatMap type node=P:d3|166 jvm=P:d3|166 Each tree reduces to a Bool→SigmaProp that is true (P:d3) on BOTH the node and the JVM, with matching JIT cost — confirming: - #2: serialize(SELF) equals the canonical box bytes (ErgoBox.bytes) and serialize(INPUTS) resolves the box collection, both at the JVM's cost (a pre-fix node REJECTED these → would diverge); - #4: the empty-flatMap output is tagged Coll[Long], not Coll[Byte] — its serialize bytes match an empty Coll[Long] byte-for-byte (a type mismatch would reduce to false / P:d2). Run: cargo test -p ergo-difftest --lib reduce_diff_serialize_and_flatmap -- --ignored Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kw7uCwqmiGna8fpg6TvxGi
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.
All three deferred #215 Critical evaluator findings. Each verified against sigmastate-interpreter v6.0.2 source and confirmed by a live JVM-oracle differential.
Coll.patchaccepts every element carrier (was Byte/Int/Long only → rejected validColl[Short]/Coll[Boolean]/tuple/box/header) via the genericupdateManypathBfrom the mapper body for an empty receiver instead of collapsing toColl[Byte]SGlobal.serializeresolves context-backed box carriers (SELF/INPUTS/OUTPUTS/Coll[Box]) viaresolve_box→ canonicalOpaqueBoxBytesJVM-oracle validation ✅
ergo-difftestreduce-surface differential vs sigma-state 6.0.2 (cargo test -p ergo-difftest --lib reduce_diff_serialize_and_flatmap -- --ignored), all matching node==JVM on prop and JIT cost:serialize(SELF)/serialize(INPUTS)produce the JVM's canonical bytes at the JVM's cost (a pre-fix node rejected these → would diverge).Coll[Long], serializing byte-for-byte identically to an emptyColl[Long](a type mismatch reduces tofalse/P:d2).Validation
ergo-sigmasuite 499 → 504 (+5 unit tests) + the live oracle differential; clippy-D warnings+ fmt clean.🤖 Generated with Claude Code
Summary by CodeRabbit
flatMapon empty collections to preserve the mapper’s output type.patchsupport across collection types, including Boolean and Short collections.