-
Notifications
You must be signed in to change notification settings - Fork 235
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
feat(public->private): create commitments in public contexts (in noir) #810
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we handle this separately such that there were no pedersen calls directly in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
|
||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use slots similar to some of the Eips like keccak256("TransparentNote") - 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made an issue
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
somewhere in the code, can you add a comment on why it is called "silo"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in the siloCommitment function natspec
@@ -57,7 +70,19 @@ export class PublicExecutor { | |||
emitEncryptedLog: notAvailable, | |||
viewNotesPage: notAvailable, | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They've since diverged after merging read requests so this todo is stale, will remove
@@ -72,6 +97,16 @@ export class PublicExecutor { | |||
this.log(`Oracle storage write: slot=${storageSlot.toShortString()} value=${value.toString()}`); | |||
return [toACVMField(newValue)]; | |||
}, | |||
createCommitment: async ([commitment]) => { | |||
this.log('Creating commitment: ' + commitment.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to print these long numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just keeping with the style of the other oracle calls where they log what they do
@@ -70,7 +70,7 @@ describe('e2e_cross_chain_messaging', () => { | |||
tokenPortalAddress = contracts.tokenPortalAddress; | |||
await expectBalance(accounts[0], initialBalance); | |||
logger('Successfully deployed contracts and initialized portal'); | |||
}, 40_000); | |||
}, 60_000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change when nothing really changed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to return anything here at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to return anything here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ibid
} | ||
|
||
|
||
fn mintFromPublicMessage( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this not be a secret
fn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: