Skip to content

Commit

Permalink
feat!: contract interfaces and better function calls (AztecProtocol/a…
Browse files Browse the repository at this point in the history
…ztec-packages#5687)

Closes AztecProtocol/aztec-packages#5081

This PR introduces autogenerated contract interfaces for easy intra and
inter contract interactions. The `aztec-macro` crate is used to stub
every non-internal private and public function and inject them into a
ghost struct which has the same name as the contract that generated
them. After that, they can be called like this:

```rust

contract ImportTest {

  use dep::my_imported_contract::MyImportedContract;

  #[aztec(private)]
  fn a_private_fn() {
    let deserialized_return = MyImportedContract::at(some_address).another_private_fn(arg1, arg2).call(&mut context);
    MyImportedContract::at(some_address).a_public_fn(arg1).enqueue(&mut context);
  }

  #[aztec(public)]
  fn a_public_fn() {
    let deserialized_return = MyImportedContract::at(some_address).a_public_fn(arg1).call(&mut context);
  }

  #[aztec(private)]
  fn calling_my_own_fns() {
    ImportTest::at(context.this_address).a_private_fn().call(&mut context);
    ImportTest::at(context.this_address).a_public_fn().enqueue(&mut context);
  }

}
```

Return values are `deserialized_into()` automatically, providing "real"
return values thanks to
AztecProtocol/aztec-packages#5633

Also, some general cleanup was required to allow importing contracts in
another contracts. Main changes:

- `HirContext.fully_qualified_struct_path` now uses BFS to avoid
returning the longest path when looking for a struct in a crate. This is
required to avoid pulling structs usually imported in top-level
dependencies (usually notes from our main contract) from other imported
contracts.
- `pack_args_oracle` now has a slice mode in addition to its usual array
mode.

PENDING:

~~AvmContext. The AVM team is discussing supporting args as slices. In
case it's decided not to do that, a workaround could possibly be
implemented using the macro, but it would be fairly complex.~~

Thanks to @fcarreiro and the amazing AVM team, this is now supported for
the AvmContext!

---------

Co-authored-by: esau <[email protected]>
Co-authored-by: Álvaro Rodríguez <[email protected]>
  • Loading branch information
3 people committed Apr 17, 2024
1 parent 5b352d6 commit 4f32473
Show file tree
Hide file tree
Showing 150 changed files with 2,374 additions and 2,969 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1dfbe7bc3bf3c455d8fb6c8b5fe6a96c1edf7af9
274f7d935230ce21d062644f6ec5f7cd0f58ae62
132 changes: 18 additions & 114 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions acvm-repo/acir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ thiserror.workspace = true
flate2.workspace = true
bincode.workspace = true
base64.workspace = true
serde-big-array = "0.5.1"

[dev-dependencies]
serde_json = "1.0"
Expand Down
Loading

0 comments on commit 4f32473

Please sign in to comment.