-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: introduce UnconstrainedContext (#6752)
Continuing the work from AztecProtocol/aztec-packages#6442, this PR further formalizes the notion of a top-level unconstrained execution context by introducing a struct that represents it (instead of relying on the unit type). Not only is this less cryptic, it also provides access to data previously unavailable such as the current block number and contract address, which we'll need for some unconstrained getters like `SharedMutable`'s. The macro functions could potentially be refactored somewhat now that private, public and unconstrained are more similar, but I'm not sure we want to invest much effort there so I made the change as small as possible.
- Loading branch information
Showing
9 changed files
with
63 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use dep::protocol_types::address::AztecAddress; | ||
|
||
struct UnconstrainedContext { | ||
block_number: u32, | ||
contract_address: AztecAddress, | ||
} | ||
|
||
impl UnconstrainedContext { | ||
fn new() -> Self { | ||
// We could call these oracles on the getters instead of at creation, which makes sense given that they might | ||
// not even be accessed. However any performance gains are minimal, and we'd rather fail early if a user | ||
// incorrectly attempts to create an UnconstrainedContext in an environment in which these oracles are not | ||
// available. | ||
let block_number = block_number_oracle(); | ||
let contract_address = contract_address_oracle(); | ||
Self { block_number, contract_address } | ||
} | ||
|
||
fn block_number(self) -> u32 { | ||
self.block_number | ||
} | ||
|
||
fn contract_address(self) -> AztecAddress { | ||
self.contract_address | ||
} | ||
} | ||
|
||
#[oracle(getContractAddress)] | ||
fn contract_address_oracle() -> AztecAddress {} | ||
|
||
#[oracle(getBlockNumber)] | ||
fn block_number_oracle() -> u32 {} |
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
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
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