-
Notifications
You must be signed in to change notification settings - Fork 234
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(AztecMacro): Calling Functions #5081
Comments
Open
Thunkar
added a commit
that referenced
this issue
Apr 17, 2024
Closes #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 #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 <152162806+sklppy88@users.noreply.github.com> Co-authored-by: Álvaro Rodríguez <sirasistant@gmail.com>
AztecBot
added a commit
to noir-lang/noir
that referenced
this issue
Apr 17, 2024
…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 <152162806+sklppy88@users.noreply.github.com> Co-authored-by: Álvaro Rodríguez <sirasistant@gmail.com>
AztecBot
added a commit
to noir-lang/noir
that referenced
this issue
Apr 17, 2024
…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 <152162806+sklppy88@users.noreply.github.com> Co-authored-by: Álvaro Rodríguez <sirasistant@gmail.com>
AztecBot
pushed a commit
to AztecProtocol/aztec-nr
that referenced
this issue
Apr 19, 2024
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 <152162806+sklppy88@users.noreply.github.com> Co-authored-by: Álvaro Rodríguez <sirasistant@gmail.com>
superstar0402
added a commit
to superstar0402/aztec-nr
that referenced
this issue
Aug 16, 2024
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 <152162806+sklppy88@users.noreply.github.com> Co-authored-by: Álvaro Rodríguez <sirasistant@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is currently quite annoying to call functions in other contracts. Either you have to generate interfaces, or you end up writing calls like:
The ux here is not acceptable at the moment, it is error prone as invalid selector or number of arguments is just fine during compilation and will only fail at run-time. Also some cases, such as the
target
being the contract itself cannot be generated from the interfaces.Since our calls are behaving similarly to solidity calls, and we don't support inlining as easily as internal functions etc can be inlined in the evm, it seems like a use like:
Would be the best that we can achieve. This would be a major improvement over what we have currently 👀
I'm not sure how we would completely be doing this. But my thought is that we similarly to the ts going on atm could generate a struct "behind the scenes" as part of a macro and then use it.
This might work for the calls to self, I'm not fully sure how we would do it for external contracts, but the back of my mind telling me that we could do something like.
and then "replace" it with structs
ContractNamePrivate
andContractNamePublic
that we can insert at the calls usingContractName
depending on the#[aztec(private)]
or#[aztec(public)]
The text was updated successfully, but these errors were encountered: