Skip to content

w.i.p refactor for deltagen modules#469

Draft
jonaprieto wants to merge 11 commits intomainfrom
jonaprieto/refactor-code-related-deltagen
Draft

w.i.p refactor for deltagen modules#469
jonaprieto wants to merge 11 commits intomainfrom
jonaprieto/refactor-code-related-deltagen

Conversation

@jonaprieto
Copy link
Collaborator

@jonaprieto jonaprieto commented Jan 30, 2026

TODO: this is mostly done, but I want to make sure the CI status is for each commit. This requires redoing the history. Pending work.

@jonaprieto jonaprieto added the enhancement New feature or request label Feb 24, 2026
- Fix @param lhs -> @param rhs for the second parameter in add() and sub()
- Fix double space in struct documentation
@jonaprieto jonaprieto force-pushed the jonaprieto/refactor-code-related-deltagen branch from 247ef27 to d7b1fcb Compare February 25, 2026 20:28
Add MagnitudeOverflow error and check before adding magnitudes
when both numbers have the same sign. This prevents silent overflow
when lhs.magnitude + rhs.magnitude exceeds uint128.max.
- Use @param instead of @notice for ProofInputs struct fields
- Fix typo: "module" -> "modulo" in modOrder function
- Add documentation for computePreDelta function
Add validateValueCommitmentRandomness() and validateKind() helper
functions to reduce code duplication in generateInstance(),
generateProof(), and createBalancedDeltaInputArray().

These helpers normalize values with modOrder() and validate non-zero
in a single call.
- normalize(): Normalizes kind and valueCommitmentRandomness fields
  of an InstanceInputs struct with modOrder()
- isValid(): Checks if InstanceInputs will produce a valid (non-zero)
  preDelta without reverting

These helpers are useful for fuzz tests to prepare and validate inputs
before using them.
Add a new createBalancedPairs() function that creates balanced delta
pairs by construction:
- Takes n inputs and produces 2n outputs
- First half are positive (created), second half are negative (consumed)
- Each positive input is paired with a matching negative input
- Quantities are guaranteed to sum to zero

This is simpler and more predictable than the existing
createBalancedDeltaInputArray(), which uses complex overflow
adjustment logic. The old function is now marked as deprecated.
Add testFuzz_verify_balanced_pairs_succeeds which demonstrates the
simpler approach using createBalancedPairs(). This test:
- Uses createBalancedPairs() which guarantees balance by construction
- No manual adjustment of the last element needed
- Cleaner and more straightforward than the old approach

The old testFuzz_verify_balanced_delta_succeeds is kept for backwards
compatibility and comparison.
- Remove unused normalize() function from DeltaGen (confusing API)
- Use isValid() helper in test to replace multiple vm.assume calls
- Improve comments in testFuzz_verify_balanced_pairs_succeeds
- Rename variable valueCommitmentRandomness -> totalRandomness for clarity
- Remove the complex createBalancedDeltaInputArray function entirely
- Remove unused SignMagnitude import from DeltaGen
- Replace old testFuzz_verify_balanced_delta_succeeds with cleaner
  testFuzz_verify_balanced_pairs_succeeds (already added)
- Simplify testFuzz_verify_imbalanced_delta_fails to test a single
  imbalanced delta instead of relying on the old function's quirks

The old function had complex overflow adjustment logic that was hard
to reason about. The new createBalancedPairs() is simpler and guarantees
balance by construction.
Extract intermediate variable to reduce stack depth when accessing
nested struct properties, fixing IR compilation failure in forge bind.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant