-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation for the initial contract instance deployer contract. Skips validations for class id and eth address for now. Pending to listen to these events on the node. Builds on #4429 Fixes #4071
- Loading branch information
1 parent
3966e7b
commit c2f4f11
Showing
10 changed files
with
156 additions
and
2 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
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
8 changes: 8 additions & 0 deletions
8
yarn-project/noir-contracts/contracts/contract_instance_deployer_contract/Nargo.toml
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,8 @@ | ||
[package] | ||
name = "contract_instance_deployer_contract" | ||
authors = [""] | ||
compiler_version = ">=0.18.0" | ||
type = "contract" | ||
|
||
[dependencies] | ||
aztec = { path = "../../../aztec-nr/aztec" } |
1 change: 1 addition & 0 deletions
1
yarn-project/noir-contracts/contracts/contract_instance_deployer_contract/src/events.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 @@ | ||
mod instance_deployed; |
36 changes: 36 additions & 0 deletions
36
...r-contracts/contracts/contract_instance_deployer_contract/src/events/instance_deployed.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,36 @@ | ||
use dep::aztec::protocol_types::{ | ||
contract_class::ContractClassId, | ||
address::{ AztecAddress, EthAddress, PublicKeysHash, PartialAddress }, | ||
constants::{DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE}, | ||
traits::{Serialize} | ||
}; | ||
|
||
// #[event] | ||
struct ContractInstanceDeployed { | ||
address: AztecAddress, | ||
version: u8, | ||
salt: Field, | ||
contract_class_id: ContractClassId, | ||
initialization_hash: Field, | ||
portal_contract_address: EthAddress, | ||
public_keys_hash: PublicKeysHash, | ||
universal_deploy: bool, | ||
} | ||
|
||
global CONTRACT_INSTANCE_DEPLOYED_SERIALIZED_SIZE: Field = 9; | ||
|
||
impl Serialize<CONTRACT_INSTANCE_DEPLOYED_SERIALIZED_SIZE> for ContractInstanceDeployed { | ||
fn serialize(self: Self) -> [Field; CONTRACT_INSTANCE_DEPLOYED_SERIALIZED_SIZE] { | ||
[ | ||
DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE, | ||
self.address.to_field(), | ||
self.version as Field, | ||
self.salt, | ||
self.contract_class_id.to_field(), | ||
self.initialization_hash, | ||
self.portal_contract_address.to_field(), | ||
self.public_keys_hash.to_field(), | ||
self.universal_deploy as Field, | ||
] | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
yarn-project/noir-contracts/contracts/contract_instance_deployer_contract/src/main.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,63 @@ | ||
mod events; | ||
|
||
contract ContractInstanceDeployer { | ||
use dep::std::option::Option; | ||
use dep::aztec::protocol_types::{ | ||
address::{ AztecAddress, EthAddress, PublicKeysHash, PartialAddress }, | ||
contract_class::ContractClassId, | ||
constants::{DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE}, | ||
traits::{Serialize} | ||
}; | ||
|
||
use dep::aztec::log::{ emit_unencrypted_log, emit_unencrypted_log_from_private}; | ||
|
||
use crate::events::{ | ||
instance_deployed::ContractInstanceDeployed, | ||
}; | ||
|
||
#[aztec(private)] | ||
fn constructor() {} | ||
|
||
#[aztec(private)] | ||
fn deploy( | ||
salt: Field, | ||
contract_class_id: ContractClassId, | ||
initialization_hash: Field, | ||
portal_contract_address: EthAddress, | ||
public_keys_hash: PublicKeysHash, | ||
universal_deploy: bool | ||
) { | ||
// TODO(@spalladino): assert nullifier_exists silo(contract_class_id, ContractClassRegisterer) | ||
// TODO(@spalladino): assert is_valid_eth_address(portal_contract_address) | ||
|
||
// TODO(#4434) Add deployer field to instance calculation | ||
// let deployer = if universal_deploy { Field::zero() } else { context.msg_sender() }; | ||
|
||
let partial_address = PartialAddress::compute( | ||
contract_class_id, | ||
salt, | ||
initialization_hash, | ||
portal_contract_address | ||
); | ||
|
||
let address = AztecAddress::compute(public_keys_hash, partial_address); | ||
|
||
// Emit the address as a nullifier to be able to prove that this instance has been (not) deployed | ||
context.push_new_nullifier(address.to_field(), 0); | ||
|
||
// Broadcast the event | ||
let event = ContractInstanceDeployed { | ||
contract_class_id, | ||
address, | ||
public_keys_hash, | ||
portal_contract_address, | ||
initialization_hash, | ||
salt, | ||
universal_deploy, | ||
version: 1 | ||
}; | ||
let event_payload = event.serialize(); | ||
dep::aztec::oracle::debug_log::debug_log_array_with_prefix("ContractInstanceDeployed", event_payload); | ||
emit_unencrypted_log_from_private(&mut context, event_payload); | ||
} | ||
} |
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