-
Notifications
You must be signed in to change notification settings - Fork 266
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: Migrate accounts to auth witness #2281
Conversation
yarn-project/noir-contracts/src/contracts/schnorr_auth_witness_account_contract/src/main.nr
Outdated
Show resolved
Hide resolved
5db62dc
to
54e42ff
Compare
8814c9e
to
cf3a745
Compare
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.
@@ -73,7 +73,9 @@ export class PrivateFunctionExecution { | |||
return toACVMField(await this.context.packedArgsCache.pack(args.map(fromACVMField))); | |||
}, | |||
getAuthWitness: async ([messageHash]) => { | |||
return (await this.context.db.getAuthWitness(fromACVMField(messageHash))).map(toACVMField); | |||
const witness = await this.context.getAuthWitness(fromACVMField(messageHash)); |
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.
} | ||
|
||
// TODO: See if we can remove this function. Maybe we can have the entrypoint call directly into internal_set_is_valid_storage..? | ||
fn set_is_valid_storage(self, message_hash: Field, value: Field) { |
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.
Let value
be a bool instead.
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.
If the function is internal this should be fine for us to do. Should also make it pretty straightforward for us to make multiple insertions and sandwich our own tx with a set and unset (unsure if this actually save us gas, because we went from "nothing -> true -> false".
actions = [
set_is_valid_storage(A, true),
execute_action(A),
set_is_valid_storage(A, false),
]
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.
nothing -> true -> false
I guess it'll depend on whether we differentiate empty from zero in public state? Are we making that distinction now?
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.
initially 0, but I think it might get a little weird because of the larger storage tree that we are using 🤔 essentially inserting into it, and a removal would normally be to set the value to zero, but that value is still in the tree and it is different from nothing. I'm not fully sure at what point in public execution the database will actually be updated, @iAmMichaelConnor or @dbanks12 might know a bit here? Ideally the squashing should mean that there is nothing in the tx but I'm not completely sure when the first change is insertion.
let _void = private_context.call_public_function(private_context.this_address(), selector, [message_hash, value]); | ||
} | ||
|
||
fn internal_set_is_valid_storage(self, message_hash: Field, value: Field) { |
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.
Let value
be a bool instead.
} | ||
|
||
#[aztec(private)] | ||
fn set_is_valid_storage(message_hash: Field, value: Field) { |
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.
Following the note from earlier. I think we should be able to just have the internal and then use the entry-point to enter it. Would be pretty clean I think 👀. But let us look into that in a separate pr to not delay this one to run into merge hell.
@@ -26,8 +26,8 @@ export function getEcdsaAccount( | |||
encryptionPrivateKey: GrumpkinPrivateKey, | |||
signingPrivateKey: Buffer, | |||
saltOrAddress?: Salt | CompleteAddress, | |||
): Account { | |||
return new Account(rpc, encryptionPrivateKey, new EcdsaAccountContract(signingPrivateKey), saltOrAddress); | |||
): AccountManager { |
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 the function name convey that it is an account manager. I think it is fine as it is, just wanted to point it out.
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.
I had tried that change and reverted it. I agree it should be a manager, but I also like it more as it is.
|
||
// docs:start:account-interface | ||
/** Creates authorisation witnesses. */ | ||
export interface AuthWitnessProvider { |
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 of the file pains me a little since it is unclear that there are multiple interfaces in here etc 😬 I kinda like the IName
but this is just my preference really.
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.
I wanted to avoid IName
for consistency, since we're not using it across the codebase, even though it reminds me of my good old C# days. As for the name, agree, it's nasty calling something "Interface" when it's not referring to a language interface
. I asked ChatGPT for ideas and it suggested Handler
as an alternative, but I don't find it very clear either.
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.
Lets leave it be for now then.
|
||
/** | ||
* Returns a function interaction to set a message hash as authorised in this account. | ||
* Public calls can then consume this authorisation. |
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.
Being a pain here. But, should we not use authorize
for the American spelling similar to changes made to serialize
and deserialize
? Not sure I did that myself actually, but for consistency 😅
} | ||
|
||
#[aztec(public)] | ||
internal fn internal_set_is_valid_storage(message_hash: Field, value: Field) { |
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.
As mentioned earlier, with newest aztec noir version should be good to use bools for the value
|
||
// docs:start:account-interface | ||
/** Creates authorisation witnesses. */ | ||
export interface AuthWitnessProvider { |
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.
Lets leave it be for now then.
@@ -62,16 +62,6 @@ impl AccountActions { | |||
} | |||
} | |||
|
|||
// TODO: See if we can remove this function. Maybe we can have the entrypoint call directly into internal_set_is_valid_storage..? |
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.
🤖 I have created a release *beep* *boop* --- <details><summary>aztec-packages: 0.7.4</summary> ## [0.7.4](aztec-packages-v0.7.3...aztec-packages-v0.7.4) (2023-09-15) ### Features * Elliptic Curve Virtual Machine Circuit ([#1268](#1268)) ([f85ecd9](f85ecd9)) * Exposing nargo version via `NodeInfo` ([#2333](#2333)) ([1c2669c](1c2669c)), closes [#2332](#2332) * Migrate accounts to auth witness ([#2281](#2281)) ([91152af](91152af)), closes [#2043](#2043) ### Bug Fixes * Aztec-nr mirror url ([#2321](#2321)) ([aaf7f67](aaf7f67)) * **build:** Fixed paths on s3 deployments ([#2335](#2335)) ([38c7979](38c7979)) ### Miscellaneous * Do not format boxes with global format ([#2326](#2326)) ([2fe845f](2fe845f)) * Remove native token ([#2280](#2280)) ([4032d01](4032d01)) * Rename getAccounts to getRegisteredAccounts ([#2330](#2330)) ([c7f3776](c7f3776)) </details> <details><summary>barretenberg.js: 0.7.4</summary> ## [0.7.4](barretenberg.js-v0.7.3...barretenberg.js-v0.7.4) (2023-09-15) ### Miscellaneous * **barretenberg.js:** Synchronize aztec-packages versions </details> <details><summary>barretenberg: 0.7.4</summary> ## [0.7.4](barretenberg-v0.7.3...barretenberg-v0.7.4) (2023-09-15) ### Features * Elliptic Curve Virtual Machine Circuit ([#1268](#1268)) ([f85ecd9](f85ecd9)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Changes all account contracts to use auth witnesses for authentication
Noir
AccountActions
module in Noir that abstracts most of the account contract requirements, leaving onlyis_valid
to be implemented by the developer.AccountInterface
helper in Noir in favor of twoassert_valid
functions.Accounts
BaseAccountContract
in ts, such that an account dev only needs to provide the abi, deploy args, and anAuthWitnessProvider
that is basically a signer. Removes all the different entrypoint implementations, since we now have just a single one.AuthWitness
es to aTxExecutionRequest
, which is used by the simulator during that tx run, so it doesn't need to be persisted in the local db.Account
toAccountManager
.Entrypoint
toAccountInterface
.Wallet
createAuthWitness
method to theWallet
interface that creates and registers the witness.setPublicAuth
to theAccountWallet
implementation for crafting the tx that sets a public auth (I think we can do better here though, it should be easy for the dev to create an action where they also include several public auths as part of a batch, but we can push that for later).EntrypointWallet
andAuthWitnessEntrypointWallet
in favor of a singleAccountWallet
.Docs
Fixes #2043