-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(noir): autogenerate contract interface for calling from external…
… contracts (#1487) Builds on @iAmMichaelConnor work to generate a contract interface for simplifying calling function in other contracts. Uses only information present in the ABI. For each function in the target contract, creates a wrapper function that receives the same arguments, serialises them based on the standard ABI encoding format (see [here](https://github.com/AztecProtocol/aztec-packages/blob/49d272159f1b27521ad34081c7f1622ccac19dff/yarn-project/foundation/src/abi/encoder.ts)), and uses the `call_private_function` from the `context` to call into them. To handle custom structs, we're re-defining them in the contract interface. Until we get struct type names in the ABI (see noir-lang/noir#2238), we are autogenerating the name as well, based on the function name and param name where they are used. Serialisation is done manually in the code, but we may want to replace it with a Noir intrinsic when available (see noir-lang/noir#2240). See [this file](https://github.com/AztecProtocol/aztec-packages/blob/49d272159f1b27521ad34081c7f1622ccac19dff/yarn-project/noir-contracts/src/contracts/test_contract/src/test_contract_interface.nr) for example output. Fixes #1237 --------- Co-authored-by: iAmMichaelConnor <[email protected]>
- Loading branch information
1 parent
bfc019f
commit 201072b
Showing
10 changed files
with
63 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
mod immutable_singleton; | ||
mod map; | ||
mod public_state; | ||
mod type_serialisation; | ||
mod set; | ||
mod singleton; |
2 changes: 1 addition & 1 deletion
2
yarn-project/noir-libs/noir-aztec/src/state_vars/public_state.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod option; // This can/should be moved out into an official noir library | ||
mod point; | ||
mod vec; // This can/should be moved out into an official noir library | ||
mod option; // This can/should be moved out into an official noir library | ||
mod type_serialisation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...ztec/src/state_vars/type_serialisation.nr → ...oir-aztec/src/types/type_serialisation.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod bool_serialisation; | ||
mod field_serialisation; | ||
mod u32_serialisation; | ||
|
||
|
16 changes: 16 additions & 0 deletions
16
yarn-project/noir-libs/noir-aztec/src/types/type_serialisation/bool_serialisation.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::types::type_serialisation::TypeSerialisationInterface; | ||
|
||
global BOOL_SERIALISED_LEN: Field = 1; | ||
|
||
fn deserialiseBool(fields: [Field; BOOL_SERIALISED_LEN]) -> bool { | ||
fields[0] as bool | ||
} | ||
|
||
fn serialiseBool(value: bool) -> [Field; BOOL_SERIALISED_LEN] { | ||
[value as Field] | ||
} | ||
|
||
global BoolSerialisationMethods = TypeSerialisationInterface { | ||
deserialise: deserialiseBool, | ||
serialise: serialiseBool, | ||
}; |
2 changes: 1 addition & 1 deletion
2
...type_serialisation/field_serialisation.nr → ...type_serialisation/field_serialisation.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/type_serialisation/u32_serialisation.nr → ...s/type_serialisation/u32_serialisation.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters