Draft
Conversation
247ef27 to
d7b1fcb
Compare
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.
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.
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.
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.