-
Notifications
You must be signed in to change notification settings - Fork 583
feat: refactor getContractMetadata and getContractClassMetadata in Wallet
#19457
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
Conversation
9ed5b8f to
0b94a99
Compare
getContractMetadata and getContractClassMetadata from WalletgetContractMetadata and getContractClassMetadata in Wallet
Flakey Tests🤖 says: This CI run detected 4 tests that failed, but were tolerated due to a .test_patterns.yml entry. |
benesjan
left a comment
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.
Overall looks great and would approve if it was for the duplicate code between builder and aztec.js.
BTW any reasons why the protocol contract generation could not be in a separate PR? It seems quite independent from the other changes in this PR and it makes the change somewhat hidden (it's not in the PR title) and the PR harder to review.
| : undefined, | ||
| ); | ||
| await Promise.all(classIds.map(classId => (classId ? wallet.getContractArtifact(classId) : undefined))) | ||
| ).map((artifact, index) => (artifact ? { ...artifact, classId: classIds[index] } : undefined)); |
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.
This transformation is quite hard to grok.
Why not first filter out the undefineds so that we don't need to do classId ? ... and artifact ? ...?
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.
Because we would lose the indexing information, and the classId assignment would get messed up. TBH I'm still very much in favor of killing this command...
yarn-project/aztec.js/src/scripts/generate_protocol_contract_types.ts
Outdated
Show resolved
Hide resolved
The main objective was to unblock the removal of |
2c2d7dc to
4e46222
Compare
…n `Wallet` This PR aims to improve `getContractMetadata` and `getContractClassMetadata` in the `Wallet` interface, avoiding the expensive back-and-forth of sending artifacts and classes. Main change is that there was a weird roundabout thing when accessing protocol contracts. These are preloaded in PXE and fixed for a given aztec version, so pulling them from the wallet just to compute the ABI was incredibly wasteful. This PR pregenerates the ABI for them because we can count on the contracts being available inside PXE. It does add a `generate` step to `aztec.js` but I think the tradeoff is well worth it. It also hints that we should separate bytecode and ABI soon. It also removes `getContractMetadata` and `getContractClassMetadata` from PXE. These are from a time when PXE was accessed directly by apps and it obscured information, you could never be sure if you were pulling from PXE's internal storage or were asking the node directly. They are replaced by simple instance artifact getters, and it's the wallet's job to assemble the metadata. This metadata has been refactored: ## `ContractMetadata` * `instance`: very lightweight, essentially tells you about the "version" of the contract PXE has registered if at all. An undefined value would mean PXE does not know about it (no node proxying nonsense). This is a potential privacy leak, however: - Wallets need a comprehensive authorization framework anyways: "do you want to let app X know information about stored contract Y?" - A malicious app could always attempt to simulate an see if it gets a "contract not registered in PXE" error * `isContractInitialized` : even if PXE does not know about the contract, we can compute the initialization nullifier and check if it's published. Not leaky, public info. * `isContractPublished`: does the contract exist in the node? * `isContractUpdated`: Since updates are forcibly public, we can get the contract from the node and check its currentContractClassId and originalContractClassId. If mismatched, the contract has been updated. * `updatedContractClassId`: If the previous is true, we put nodeContract.currentContractClassId here, allowing the app to see if instance.currentContractClassId matches and creating a convenient way to know if it's necessary to `registerContract(instance, newArtifact)` ## `ContractClassMetadata` * `isContractClassPubliclyRegistered`: This makes deployments extremely convenient, as we can know in the TS wrapper for the contract with just the wallet whether we need to include class registration in the payload or not. * `isArtifactRegistered`: Does PXE know about this artifact?
4e46222 to
cb46a9d
Compare
mverzilli
left a comment
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.
Always nice to see some code go away from PXE :D
Allows ALL methods in the wallet to be batched (because why not). Initially I was going for allowing them on a case-by-case basis, but integrating the Wallet SDK has made apparent apps can have many interaction flows and this extra flexibility is nice. Updated the migration notes and in the process realized I missed exporting some artifacts in #19457, so here they are (protocol contract wrappers) Co-authored-by: thunkar <gregojquiros@gmail.com>
Allows ALL methods in the wallet to be batched (because why not). Initially I was going for allowing them on a case-by-case basis, but integrating the Wallet SDK has made apparent apps can have many interaction flows and this extra flexibility is nice. Updated the migration notes and in the process realized I missed exporting some artifacts in #19457, so here they are (protocol contract wrappers)
Allows ALL methods in the wallet to be batched (because why not). Initially I was going for allowing them on a case-by-case basis, but integrating the Wallet SDK has made apparent apps can have many interaction flows and this extra flexibility is nice. Updated the migration notes and in the process realized I missed exporting some artifacts in #19457, so here they are (protocol contract wrappers) Co-authored-by: thunkar <gregojquiros@gmail.com>
This PR aims to improve
getContractMetadataandgetContractClassMetadatain theWalletinterface, avoiding the expensive back-and-forth of sending artifacts and classes.Main change is that there was a weird roundabout thing when accessing protocol contracts. These are preloaded in PXE and fixed for a given aztec version, so pulling them from the wallet just to compute the ABI was incredibly wasteful.
This PR pregenerates the ABI for them because we can count on the contracts being available inside PXE. It does add a
generatestep toaztec.jsbut I think the tradeoff is well worth it. It also hints that we should separate bytecode and ABI soon.It also removes
getContractMetadataandgetContractClassMetadatafrom PXE. These are from a time when PXE was accessed directly by apps and it obscured information, you could never be sure if you were pulling from PXE's internal storage or were asking the node directly. They are replaced by simple instance artifact getters, and it's the wallet's job to assemble the metadata. This metadata has been refactored:ContractMetadatainstance: very lightweight, essentially tells you about the "version" of the contract PXE has registered if at all. An undefined value would mean PXE does not know about it (no node proxying nonsense). This is a potential privacy leak, however:isContractInitialized: even if PXE does not know about the contract, we can compute the initialization nullifier and check if it's published. Not leaky, public info.isContractPublished: does the contract exist in the node?isContractUpdated: Since updates are forcibly public, we can get the contract from the node and check its currentContractClassId and originalContractClassId. If mismatched, the contract has been updated.updatedContractClassId: If the previous is true, we put nodeContract.currentContractClassId here, allowing the app to see if instance.currentContractClassId matches and creating a convenient way to know if it's necessary toregisterContract(instance, newArtifact)ContractClassMetadataisContractClassPubliclyRegistered: This makes deployments extremely convenient, as we can know in the TS wrapper for the contract with just the wallet whether we need to include class registration in the payload or not.isArtifactRegistered: Does PXE know about this artifact?