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

feat(public->private): create commitments in public contexts (in noir) #810

Merged
merged 14 commits into from
Jun 14, 2023

Conversation

Maddiaa0
Copy link
Member

@Maddiaa0 Maddiaa0 commented Jun 12, 2023

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:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • The branch has been merged or rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.

Base automatically changed from md/commitments-in-public to master June 12, 2023 16:26
@Maddiaa0 Maddiaa0 marked this pull request as ready for review June 13, 2023 14:39
Copy link
Contributor

@LHerskind LHerskind left a 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) {
Copy link
Contributor

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(
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

1+1+1

Copy link
Member Author

Choose a reason for hiding this comment

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

image

}

// 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?
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Contributor

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"?

Copy link
Member Author

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
Copy link
Contributor

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!

Copy link
Member Author

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());
Copy link
Contributor

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?

Copy link
Member Author

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);
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

nittiest of all nit: extra empty line?
image

pedersen([self.amount, self.secretHash])[0]
}

fn consume_in_private(self: Self, mut context: PrivateFunctionContext, root: Field, secret: Field) -> PrivateFunctionContext {
Copy link
Contributor

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?

Copy link
Member Author

@Maddiaa0 Maddiaa0 Jun 14, 2023

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
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

ibid

}


fn mintFromPublicMessage(
Copy link
Contributor

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?

Copy link
Member Author

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

@Maddiaa0 Maddiaa0 enabled auto-merge (squash) June 14, 2023 12:14
@Maddiaa0 Maddiaa0 merged commit 27dc70f into master Jun 14, 2023
@Maddiaa0 Maddiaa0 deleted the md/com-pub branch June 14, 2023 12:19
@ludamad
Copy link
Collaborator

ludamad commented Jun 14, 2023

image

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.

4 participants