Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subtree update positive security exercise #387

Merged
merged 6 commits into from
Aug 5, 2023

Conversation

Sladuca
Copy link
Contributor

@Sladuca Sladuca commented Aug 3, 2023

Motivation

Want to enumerate subtree update circuit assumptions and argue subtree update circuit is "correct" given those assumptions to gain more surety that it's "correct"

Solution

Add annotations in comments listing out assumptions and arguing they're correct

Proof

unnecessary, as there are no code changes

PR Checklist

  • Added Tests
  • Updated Documentation
  • Updated CHANGELOG.md for the appropriate package
  • Tested in dev/testnet
  • Tested site with snap (we haven't automated this yet)
  • Re-built & tested circuits if any of them changed
  • Updated contracts storage layout (if contracts were updated)

@Sladuca Sladuca changed the title add positive security annotations to subtree update circuit subtree update positive security exercise Aug 3, 2023
@Sladuca Sladuca requested a review from luketchang as a code owner August 4, 2023 17:49
//@requires(2) `accumulatorHash` is the low-253 bits of the batch `accumulatorHash` from the commitment tree in `OffchainMerkleTree.sol`
//@requires(3) `2*r + 3` is less than 254 and `r > 0`
//@requires(3) `oldRoot` is the current commitment tree root
//@ensures(1) `newRoot` is the commitment tree root that results from inserting the batch with accumulator hash `accumulatorHash` (+ 3 hi-bits form `encodedPathAndHash`) into the commitment tree with root `oldRoot`
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need any requires for siblings, leaves, bitmap, etc (all the fields committed to be accumulator hash)?

Copy link
Contributor

Choose a reason for hiding this comment

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

One big requires is that the bitmap, owner fields, nonces, etc are in the exact order they occurred on chain. Idk the best way to frame this but you could mention how each field is committed to

Copy link
Contributor Author

@Sladuca Sladuca Aug 4, 2023

Choose a reason for hiding this comment

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

The circuit doesn't require this - this all comes from accumulatorHash. They're also all private witness values so we can't make any assumptions on them at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a comment to OffchainMerkleTree.sol explaining this.

@@ -35,9 +42,13 @@ template SubtreeUpdate4(r) {
signal input encodedAssetIds[4**s];
signal input values[4**s];

//@satisfies(1)
//@argument Subtreeupdate.requires(1, 2, 3) are satisfied by @requires(...),
Copy link
Contributor

Choose a reason for hiding this comment

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

//@argument Subtreeupdate.requires(1, 2, 3) are satisfied by @requires(...),

What does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

inner's require statements are satisfied by this template's require statements

//@requires(2) `accumulatorHash` is the low-253 bits of the batch `accumulatorHash` from the commitment tree in `OffchainMerkleTree.sol`
//@requires(3) `2*r + 3` is less than 254 and `r > 0`
//@requires(4) `emptySubtreeRoot` is the correct root of a depth-s subtree full of "zeros", where the "zero value" is up to the caller
//@requires(3) `oldRoot` is the current commitment tree root
Copy link
Contributor

Choose a reason for hiding this comment

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

requires 5 you mean not 3?

// this is clearly the case from this constaint in the case where bitmap[i] == 1
// in the case where it's 0, the argument goes like this:
// - due to @lemma(3), `hasher.out` is the unique, correct accumulator hash for the batch of notes,
// so, due to @requires(2), the circuit will be unsatisfiable if the batch supplied as witness to this circuit does
Copy link
Contributor

Choose a reason for hiding this comment

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

REVISIT: accumulator hash is not guaranteed to be unique (e.g. accumulator hash for 2 empty batches, though fully zero batches is not possible)? are non unique accumulator hashes a problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unique probably isn't the right word - I meant it's the only possible accumulator hash we could get from the given batch. clarified wording in newest revision.

@Sladuca Sladuca requested a review from luketchang August 4, 2023 18:26
@Sladuca Sladuca force-pushed the seb/subtree-update-positive-sec branch from a3bf881 to b68fc7b Compare August 4, 2023 22:58
@Sladuca Sladuca force-pushed the seb/subtree-update-positive-sec branch from b68fc7b to 44dafd2 Compare August 4, 2023 23:30
@Sladuca Sladuca enabled auto-merge (squash) August 4, 2023 23:32
@Sladuca Sladuca disabled auto-merge August 5, 2023 15:37
@Sladuca Sladuca merged commit 000357c into main Aug 5, 2023
@Sladuca Sladuca deleted the seb/subtree-update-positive-sec branch August 5, 2023 15:37
@luketchang luketchang restored the seb/subtree-update-positive-sec branch September 12, 2023 20:03
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