feat(public->private): create commitments in public contexts (in noir)#810
Conversation
LHerskind
left a comment
There was a problem hiding this comment.
Looks good, minor nits.
| * @param commitment - The commitment. | ||
| * @returns The commitment data. | ||
| */ | ||
| public async getCommitment(contractAddress: AztecAddress, commitment: Fr) { |
There was a problem hiding this comment.
Can you add the return type explicity
| // Assert the commitment was created | ||
| expect(result.newCommitments.length).toEqual(1); | ||
|
|
||
| const expectedNewCommitmentValue = pedersenCompressInputs( |
There was a problem hiding this comment.
Should we handle this separately such that there were no pedersen calls directly in here?
There was a problem hiding this comment.
In reality this calculation will be performed in noir on the other side, it is just done here in the test to prevent writing a cbind for two values. I dont think it's worth it since it is just a test.
| 1 + 1 + 1 | ||
| } | ||
|
|
||
| // TODO: 3 as const |
| } | ||
|
|
||
| // Gets the value of the commitment | ||
| // TODO(maddiaa): this will need to be hashed with a slot to keep it unique, which slot to pick? |
There was a problem hiding this comment.
We could use slots similar to some of the Eips like keccak256("TransparentNote") - 1.
| const secret = new Fr(1n); | ||
| const secretHash = computeSecretMessageHash(wasm, secret); | ||
| const commitment = Fr.fromBuffer(pedersenCompressInputs(wasm, [toBufferBE(amount, 32), secretHash.toBuffer()])); | ||
| const siloedCommitment = siloCommitment(wasm, contractAddress, commitment); |
There was a problem hiding this comment.
somewhere in the code, can you add a comment on why it is called "silo"?
There was a problem hiding this comment.
Added in the siloCommitment function natspec
| debugLog: notAvailable, | ||
| getL1ToL2Message: notAvailable, // l1 to l2 messages in public contexts TODO: https://github.com/AztecProtocol/aztec-packages/issues/616 | ||
|
|
||
| // TODO(Maddiaa): both getL1ToL2 and getCommitment share alot of code with the private conterpart? could be refactored |
There was a problem hiding this comment.
are you planning to fix it in this PR or another one? If latter feel free to create an appropriate issue!
There was a problem hiding this comment.
They've since diverged after merging read requests so this todo is stale, will remove
| return [toACVMField(newValue)]; | ||
| }, | ||
| createCommitment: async ([commitment]) => { | ||
| this.log('Creating commitment: ' + commitment.toString()); |
There was a problem hiding this comment.
do we need to print these long numbers?
There was a problem hiding this comment.
Just keeping with the style of the other oracle calls where they log what they do
| await expectBalance(accounts[0], initialBalance); | ||
| logger('Successfully deployed contracts and initialized portal'); | ||
| }, 40_000); | ||
| }, 60_000); |
There was a problem hiding this comment.
why this change when nothing really changed here?
There was a problem hiding this comment.
it just fails intermittently when running locally, increasing it to not have the pain of rerunning
| @@ -0,0 +1,12 @@ | |||
| // Oracle function to get a commitment, its sibling path and index, without getting its preimage. | |||
|
|
|||
| pedersen([self.amount, self.secretHash])[0] | ||
| } | ||
|
|
||
| fn consume_in_private(self: Self, mut context: PrivateFunctionContext, root: Field, secret: Field) -> PrivateFunctionContext { |
There was a problem hiding this comment.
idk how I feel about this naming. Noir uses "secret" because when devs think "private", they would think of internal methods. Maybe we should use that too in our names? or is that overkill?
There was a problem hiding this comment.
The name was to keep with other things being called private. Secret has stronger connotations, so ive renamed
|
|
||
| // Public oracle call to emit new commitment. | ||
| create_commitment(note.get_commitment()); | ||
| 0 |
There was a problem hiding this comment.
do we need to return anything here at all?
There was a problem hiding this comment.
originally when doing this public function required a return value, but that doesnt seem to be the case anymore! Will remove
|
|
||
| // Public oracle call to emit new commitment. | ||
| create_l2_to_l1_message(note.get_commitment()); | ||
| 0 |
There was a problem hiding this comment.
why do we need to return anything here?
| } | ||
|
|
||
|
|
||
| fn mintFromPublicMessage( |
There was a problem hiding this comment.
should this not be a secret fn?
There was a problem hiding this comment.
it is secret by default, the keyword doesnt exist in the lang yet




Description
Solves
Creates an end to end test where a public function creates a commitment which is later consumed within the private execution context.
Please provide a paragraph or two giving a summary of the change, including relevant motivation and context.
Checklist: