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

Switch public execution to public dispatch function #8985

Open
3 of 5 tasks
fcarreiro opened this issue Oct 3, 2024 · 0 comments
Open
3 of 5 tasks

Switch public execution to public dispatch function #8985

fcarreiro opened this issue Oct 3, 2024 · 0 comments
Assignees
Labels
C-avm Component: AVM related tickets (aka public VM) C-aztec.js Component: aztec.js client library C-aztec.nr Component: Aztec smart contract framework C-protocol-specs Component: docs.aztec.network/protocol-specs T-tracking Type: Tracking Issue. This contains tasklists.

Comments

@fcarreiro
Copy link
Contributor

fcarreiro commented Oct 3, 2024

The concept of function selector in public will only stay in Aztec-nr and be deshrined from protocol/avm.

  • Create macro for public dispatch
  • Reroute public execution through public dispatch
  • Only register/deploy public dispatch
  • Fix stack trace (see this)
  • Deshrine function selector from protocol-public
@fcarreiro fcarreiro added T-tracking Type: Tracking Issue. This contains tasklists. C-aztec.nr Component: Aztec smart contract framework C-aztec.js Component: aztec.js client library C-avm Component: AVM related tickets (aka public VM) C-protocol-specs Component: docs.aztec.network/protocol-specs labels Oct 3, 2024
@fcarreiro fcarreiro self-assigned this Oct 3, 2024
@github-project-automation github-project-automation bot moved this to Todo in A3 Oct 3, 2024
fcarreiro added a commit that referenced this issue Oct 3, 2024
The objective of this PR is to make all public execution go through the
recently included `public_dispatch` function. In a follow up PR I'll
make it so that the `public_dispatch` function is the only bytecode
registered for a contract.

The end goal is that, for public, the concept of function selector will
only be an AztecNR concept, and the protocol (/avm etc) should not
include that concept in public. This PR works towards that.

The approach for this PR is to redirect public function calling at the
lowest aztecnr level: the contexts. This was easy for the PublicContext,
but the PrivateContext is more challenging because of how it packs
arguments. The latter was solved with a hack, suggested by Palla and
Nico.

Something notable is that I didn't have to change anything from authwit
and contract initialization. This is a massive pro, and something that
did not happen during my first PoC. The key is to make this change
"transparent" for public functions, the key is
* `context.get_args_hash()` will still return the hash of the args _of
the original function_ (and not of the dispatch function)
* `context.selector()` will still return the selector _of the original
function_, which is `calldata[0]`.
Both of these together mean that authwit and init hashes are still
computed as before = `[selector, args_hash]`.
Since function selector, authwit and the way init hashes are computed is
an aztec-nr/aztec-js concept, this makes sense. Very happy about it and
I hope it lasts once I completely deshrine selectors from public.

Part of #8985.
fcarreiro added a commit that referenced this issue Oct 4, 2024
Part of #8985.

This PR unblocks bytecode hashing in the AVM.
fcarreiro added a commit that referenced this issue Oct 4, 2024
Fixes the public stack trace, to unblock releases.

BEFORE
```
    Simulation error: Assertion failed: Not implemented 'false'

      248 |     on_behalf_of: AztecAddress
      249 | ) {
    > 250 |     assert(false, "Not implemented");
          |            ^
      251 |     let inner_hash = compute_inner_authwit_hash(
      252 |         [(*context).msg_sender().to_field(), (*context).selector().to_field(), (*context).get_args_hash()]
      253 |     );

      at false (../../../noir-projects/aztec-nr/authwit/src/auth.nr:250:12)
      at assert_current_call_valid_authwit_public(&mut context, from) (../../../noir-projects/noir-contracts/contracts/token_contract/src/main.nr:243:13)
      at aztec (../../../noir-projects/noir-contracts/contracts/token_contract/src/main.nr:14:3)
      at Token.public_dispatch
      at Uniswap.public_dispatch
```

AFTER
```
    Simulation error: Assertion failed: Not implemented 'false'

      248 |     on_behalf_of: AztecAddress
      249 | ) {
    > 250 |     assert(false, "Not implemented");
          |            ^
      251 |     let inner_hash = compute_inner_authwit_hash(
      252 |         [(*context).msg_sender().to_field(), (*context).selector().to_field(), (*context).get_args_hash()]
      253 |     );

  at false (../../../noir-projects/aztec-nr/authwit/src/auth.nr:250:12)
  at assert_current_call_valid_authwit_public(&mut context, from) (../../../noir-projects/noir-contracts/contracts/token_contract/src/main.nr:259:13)
  at aztec (../../../noir-projects/noir-contracts/contracts/token_contract/src/main.nr:14:3)
  at Token.burn_public
  at TokenBridge.exit_to_l1_public
  at Uniswap._approve_bridge_and_exit_input_asset_to_L1
```

Part of #8985.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-avm Component: AVM related tickets (aka public VM) C-aztec.js Component: aztec.js client library C-aztec.nr Component: Aztec smart contract framework C-protocol-specs Component: docs.aztec.network/protocol-specs T-tracking Type: Tracking Issue. This contains tasklists.
Projects
Status: Todo
Development

No branches or pull requests

1 participant