refactor: remove selector from public call request#12828
Conversation
|
|
||
| public async getContractAddressPreimage(address: AztecAddress) { | ||
| const instance = await this.contractDataProvider.getContractInstance(address); | ||
| if (!instance) { |
There was a problem hiding this comment.
The functions in contractDataProvider behaved differently: some threw when the value was not found and some returned undefined. I've changed them all to be returning value | undefined, and check the result and throw specific error elsewhere.
| public async getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector) { | ||
| const tree = await this.getTreeForAddress(contractAddress); | ||
| const { name: contractName } = tree.getArtifact(); | ||
| const { name: functionName } = await tree.getFunctionArtifact(selector); |
There was a problem hiding this comment.
Moving artifact out of the PrivateFunctionsTree as it was confusing to fetch public functions from a component dealing with private functions. And the above didn't work for public functions except for the public dispatch.
| feePaymentMethod: | ||
| // needsSetup? then we pay through a fee payment contract | ||
| this.data.forPublic?.needsSetup | ||
| ? // if the first call is to `approve_public_authwit`, then it's a public payment |
There was a problem hiding this comment.
This function doesn't exist anymore. Changing the displayed text to be either 'fee_juice' or fpc as there's no reliable way to check what kind of fpc it is.
a090a63 to
b85fb0b
Compare
|
Hell of a PR, One thing that worries me: whose responsibility is to call |
Currently it's called by pxe when registering a contract. Think it makes sense for testing!
I don't think so 😞 On the public side, the data provided by calling this function is only used to show real function names in logs. Originally I wanted to remove it in this pr, but others think it's useful to keep it around. To solve callstacks should rely on the public dispatch function's debug metadata, and we don't have it in public right now. But maybe we can change this api to provide it! |
fcarreiro
left a comment
There was a problem hiding this comment.
Amazing work, thanks! LGTM for AVM. Left a few comments, the most important one being about making sure that we don't over-enforce the aztec (public) calling convention in places we shouldn't (outside aztec{nr,js}).
| } | ||
| } | ||
|
|
||
| pub fn hash_calldata(calldata: [Field]) -> Field { |
There was a problem hiding this comment.
Does this make us free to change the hash for public independent of private? I know we might need to change it to something more avm-friendly soon (cc @IlyasRidhuan )
There was a problem hiding this comment.
Yes! Just need to update this and the corresponding computeCalldataHash in ts :)
| } | ||
| } | ||
|
|
||
| pub fn hash_calldata_array<let N: u32>(calldata: [Field; N]) -> Field { | ||
| if calldata.len() == 0 { | ||
| 0 | ||
| } else { | ||
| poseidon2_hash_with_separator(calldata, GENERATOR_INDEX__PUBLIC_CALLDATA) | ||
| } | ||
| } | ||
|
|
||
| pub fn hash_calldata(calldata: [Field]) -> Field { |
There was a problem hiding this comment.
[Re: lines +92 to +108]
Could you maybe add a comment to the hash_{args,array,calldata,etc} functions? Basically IIUC saying which one is used for private and which one for public.
See this comment inline on Graphite.
| ) { | ||
| const callStack = err.getCallStack(); | ||
| const originalFailingFunction = callStack[callStack.length - 1]; | ||
| // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Properly fix this. |
| const calldata = [fnSelector.toField(), ...encodedArgs]; | ||
| const calldataHash = await computeCalldataHash(calldata); | ||
| const isStaticCall = call.isStaticCall ?? false; | ||
| const request = new PublicCallRequest(sender, address, isStaticCall, calldataHash); |
There was a problem hiding this comment.
You could consider having a static factory method in PublicCallRequest that takes the calldata, and internally computes the hash (then the choice of hash etc would be just in one place).
There was a problem hiding this comment.
Good idea! Will do :)
| static async fromArgs(args: Fr[]) { | ||
| return new HashedValues(args, await computeVarArgsHash(args)); | ||
| } | ||
|
|
||
| static async fromCalldata(calldata: Fr[]) { | ||
| return new HashedValues(calldata, await computeCalldataHash(calldata)); | ||
| } |
There was a problem hiding this comment.
Could you add a comment that one is for private and the other one for public?
|
|
||
| // Public functions get routed through the dispatch function, whose first argument is the target function selector. | ||
| get functionSelector(): FunctionSelector { | ||
| return FunctionSelector.fromField(this.calldata[0]); |
There was a problem hiding this comment.
Just one comment here but it applies to the whole PR: while the aztec{nr,js} calling convention is to have the funcion selector first, args after that, in principle someone could craft a transaction that doesn't follow this.
Also, there could be contracts that don't follow this. That is, execution of a public contract should just receive the whole calldata that was sent in the TX and in principle nothing should prevent that. As extreme examples, the calldata could be empty, and I think our nodes/tx processing/validation should not fail (debugging and logs might not be able to display things but shouldn't crash). Another example is when there IS a first field, but the semantic is not that of a function selector (because eg the contract was written in asm and while it does have a public_dispatch it is not really dispatching).
There was a problem hiding this comment.
I was going to remove any reference of function selector in public land. It's only used for debug logs and in the tests for fetching bytecode of individual public function. But decided to leave it as people think it's still useful to see the actual function name 😅
Regarding the tests, Alvaro mentioned that it's the plan running the tests with public dispatch function?
There was a problem hiding this comment.
Alvaro mentioned that it's the plan running the tests with public dispatch function?
Hmm. For most tests that's completely true. The only case where this is undesirable is the avm_simulator.test.ts tests that test single opcodes. Right now they really test contract code that is basically JUST that opcode. If we use public_dispatch there, they will be testing many more opcodes from the dispatch itself. So the tests become less "unit". Not a blocker though.
dd5a267 to
5b19387
Compare
5b19387 to
b0ead53
Compare
🤖 I have created a new Aztec Packages release --- ## [0.82.1](v0.82.0...v0.82.1) (2025-03-24) ### Features * **avm:** Port field gt to vm2 ([#12883](#12883)) ([0ae6891](0ae6891)) * use msgpack for ClientIvc::Proof in API ([#12911](#12911)) ([1a01602](1a01602)) ### Bug Fixes * disable proving on vite box ([#12971](#12971)) ([69a0fb6](69a0fb6)) * no hardcoded versions in bbup ([#12944](#12944)) ([397144f](397144f)) * pull CRS data ahead of time ([#12945](#12945)) ([43155d6](43155d6)) * Remove workaround ([#12952](#12952)) ([c3337af](c3337af)) * set the correct env var ([#12959](#12959)) ([bd0f4b2](bd0f4b2)) * yolo add bunch of test flakes ([13c19da](13c19da)) * yolo e2e_p2p tests now fully skipped due to huge speed regression ([9141410](9141410)) * yolo txe binds just to localhost by default. ([3933b35](3933b35)) ### Miscellaneous * Change `/bin/bash` shebang to be env based ([#12834](#12834)) ([7843a67](7843a67)) * clean up avm codeowners ([#12860](#12860)) ([35a8f46](35a8f46)) * deflake the kind smoke test ([#12955](#12955)) ([1a37d6d](1a37d6d)), closes [#11177](#11177) * fee cleanup ([#12941](#12941)) ([fdf1da4](fdf1da4)) * Increase bot count ([#12963](#12963)) ([16edd06](16edd06)) * L2 chain config for alpha testnet ([#12962](#12962)) ([e13edb8](e13edb8)) * Reduce bots ([#12953](#12953)) ([4bbc5da](4bbc5da)) * remove selector from public call request ([#12828](#12828)) ([18bcc1b](18bcc1b)) * replace relative paths to noir-protocol-circuits ([61cf4b6](61cf4b6)) * replace relative paths to noir-protocol-circuits ([4356c17](4356c17)) * replace relative paths to noir-protocol-circuits ([f73f47d](f73f47d)) * Set default proving config to true ([#12964](#12964)) ([75c1549](75c1549)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Revert change from #12828 Unclear how this made tests pass
- Remove `function_selector` from `PublicCallRequest` as it is no longer used. - Remove `public_functions` from `ContractClass`. - `ContractClass` checks that there's at most 1 public function in the artifact. - Rename `args` to `calldata` when it's public calldata that includes the function selector. - Use different generator indexes for calldata and regular args. ### aztec-nr - Rename oracle calls `enqueue_public_function_call_internal ` to `notify_enqueued_public_function_call `, and `set_public_teardown_function_call_internal` to `notify_set_public_teardown_function_call `, to be consistent with other oracle calls. - Storing data to execution cache will need to provide the hash in addition to the preimage, making it possible to use it for different types of data. Currently it's used for calldata and args. ### node - Rename `getContractFunctionName` to `getDebugFunctionName`, as the function name won't always be available. It's set by explicitly calling `registerContractFunctionSignatures` for debugging purpose. - Remove `ExecutionRequest[]` in `Tx` and replace it with `calldata[]`. We now loop through the `publicCallRequests` in the public inputs and pair each with an entry in `calldata[]`. - `DataValidator` checks that calldata are provided for all the non-empty public call requests, and the hash is correct.
🤖 I have created a new Aztec Packages release --- ## [0.82.1](v0.82.0...v0.82.1) (2025-03-24) ### Features * **avm:** Port field gt to vm2 ([#12883](#12883)) ([0ae6891](0ae6891)) * use msgpack for ClientIvc::Proof in API ([#12911](#12911)) ([1a01602](1a01602)) ### Bug Fixes * disable proving on vite box ([#12971](#12971)) ([69a0fb6](69a0fb6)) * no hardcoded versions in bbup ([#12944](#12944)) ([397144f](397144f)) * pull CRS data ahead of time ([#12945](#12945)) ([43155d6](43155d6)) * Remove workaround ([#12952](#12952)) ([c3337af](c3337af)) * set the correct env var ([#12959](#12959)) ([bd0f4b2](bd0f4b2)) * yolo add bunch of test flakes ([13c19da](13c19da)) * yolo e2e_p2p tests now fully skipped due to huge speed regression ([9141410](9141410)) * yolo txe binds just to localhost by default. ([3933b35](3933b35)) ### Miscellaneous * Change `/bin/bash` shebang to be env based ([#12834](#12834)) ([7843a67](7843a67)) * clean up avm codeowners ([#12860](#12860)) ([35a8f46](35a8f46)) * deflake the kind smoke test ([#12955](#12955)) ([1a37d6d](1a37d6d)), closes [#11177](#11177) * fee cleanup ([#12941](#12941)) ([fdf1da4](fdf1da4)) * Increase bot count ([#12963](#12963)) ([16edd06](16edd06)) * L2 chain config for alpha testnet ([#12962](#12962)) ([e13edb8](e13edb8)) * Reduce bots ([#12953](#12953)) ([4bbc5da](4bbc5da)) * remove selector from public call request ([#12828](#12828)) ([18bcc1b](18bcc1b)) * replace relative paths to noir-protocol-circuits ([61cf4b6](61cf4b6)) * replace relative paths to noir-protocol-circuits ([4356c17](4356c17)) * replace relative paths to noir-protocol-circuits ([f73f47d](f73f47d)) * Set default proving config to true ([#12964](#12964)) ([75c1549](75c1549)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
- Remove `function_selector` from `PublicCallRequest` as it is no longer used. - Remove `public_functions` from `ContractClass`. - `ContractClass` checks that there's at most 1 public function in the artifact. - Rename `args` to `calldata` when it's public calldata that includes the function selector. - Use different generator indexes for calldata and regular args. ### aztec-nr - Rename oracle calls `enqueue_public_function_call_internal ` to `notify_enqueued_public_function_call `, and `set_public_teardown_function_call_internal` to `notify_set_public_teardown_function_call `, to be consistent with other oracle calls. - Storing data to execution cache will need to provide the hash in addition to the preimage, making it possible to use it for different types of data. Currently it's used for calldata and args. ### node - Rename `getContractFunctionName` to `getDebugFunctionName`, as the function name won't always be available. It's set by explicitly calling `registerContractFunctionSignatures` for debugging purpose. - Remove `ExecutionRequest[]` in `Tx` and replace it with `calldata[]`. We now loop through the `publicCallRequests` in the public inputs and pair each with an entry in `calldata[]`. - `DataValidator` checks that calldata are provided for all the non-empty public call requests, and the hash is correct.
🤖 I have created a new Aztec Packages release --- ## [0.82.1](v0.82.0...v0.82.1) (2025-03-24) ### Features * **avm:** Port field gt to vm2 ([#12883](#12883)) ([0ae6891](0ae6891)) * use msgpack for ClientIvc::Proof in API ([#12911](#12911)) ([1a01602](1a01602)) ### Bug Fixes * disable proving on vite box ([#12971](#12971)) ([69a0fb6](69a0fb6)) * no hardcoded versions in bbup ([#12944](#12944)) ([397144f](397144f)) * pull CRS data ahead of time ([#12945](#12945)) ([43155d6](43155d6)) * Remove workaround ([#12952](#12952)) ([c3337af](c3337af)) * set the correct env var ([#12959](#12959)) ([bd0f4b2](bd0f4b2)) * yolo add bunch of test flakes ([13c19da](13c19da)) * yolo e2e_p2p tests now fully skipped due to huge speed regression ([9141410](9141410)) * yolo txe binds just to localhost by default. ([3933b35](3933b35)) ### Miscellaneous * Change `/bin/bash` shebang to be env based ([#12834](#12834)) ([7843a67](7843a67)) * clean up avm codeowners ([#12860](#12860)) ([35a8f46](35a8f46)) * deflake the kind smoke test ([#12955](#12955)) ([1a37d6d](1a37d6d)), closes [#11177](#11177) * fee cleanup ([#12941](#12941)) ([fdf1da4](fdf1da4)) * Increase bot count ([#12963](#12963)) ([16edd06](16edd06)) * L2 chain config for alpha testnet ([#12962](#12962)) ([e13edb8](e13edb8)) * Reduce bots ([#12953](#12953)) ([4bbc5da](4bbc5da)) * remove selector from public call request ([#12828](#12828)) ([18bcc1b](18bcc1b)) * replace relative paths to noir-protocol-circuits ([61cf4b6](61cf4b6)) * replace relative paths to noir-protocol-circuits ([4356c17](4356c17)) * replace relative paths to noir-protocol-circuits ([f73f47d](f73f47d)) * Set default proving config to true ([#12964](#12964)) ([75c1549](75c1549)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
function_selectorfromPublicCallRequestas it is no longer used.public_functionsfromContractClass.ContractClasschecks that there's at most 1 public function in the artifact.argstocalldatawhen it's public calldata that includes the function selector.aztec-nr
enqueue_public_function_call_internaltonotify_enqueued_public_function_call, andset_public_teardown_function_call_internaltonotify_set_public_teardown_function_call, to be consistent with other oracle calls.node
getContractFunctionNametogetDebugFunctionName, as the function name won't always be available. It's set by explicitly callingregisterContractFunctionSignaturesfor debugging purpose.ExecutionRequest[]inTxand replace it withcalldata[]. We now loop through thepublicCallRequestsin the public inputs and pair each with an entry incalldata[].DataValidatorchecks that calldata are provided for all the non-empty public call requests, and the hash is correct.