Skip to content

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

Merged
Maddiaa0 merged 14 commits into
masterfrom
md/com-pub
Jun 14, 2023
Merged

feat(public->private): create commitments in public contexts (in noir)#810
Maddiaa0 merged 14 commits into
masterfrom
md/com-pub

Conversation

@Maddiaa0

@Maddiaa0 Maddiaa0 commented Jun 12, 2023

Copy link
Copy Markdown
Member

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

@LHerskind LHerskind left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

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
Copy Markdown
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
Copy Markdown
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

return [toACVMField(newValue)];
},
createCommitment: async ([commitment]) => {
this.log('Creating commitment: ' + commitment.toString());

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

await expectBalance(accounts[0], initialBalance);
logger('Successfully deployed contracts and initialized portal');
}, 40_000);
}, 60_000);

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

@Maddiaa0 Maddiaa0 Jun 14, 2023

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

ludamad commented Jun 14, 2023

Copy link
Copy Markdown
Collaborator

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