Skip to content

Commit

Permalink
refactor: purge portal addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Apr 19, 2024
1 parent 99694b9 commit 01bb109
Show file tree
Hide file tree
Showing 74 changed files with 79 additions and 362 deletions.
2 changes: 0 additions & 2 deletions avm-transpiler/src/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub enum AvmOpcode {
ADDRESS,
STORAGEADDRESS,
SENDER,
PORTAL,
FEEPERL1GAS,
FEEPERL2GAS,
FEEPERDAGAS,
Expand Down Expand Up @@ -102,7 +101,6 @@ impl AvmOpcode {
AvmOpcode::ADDRESS => "ADDRESS",
AvmOpcode::STORAGEADDRESS => "STORAGEADDRESS",
AvmOpcode::SENDER => "SENDER",
AvmOpcode::PORTAL => "PORTAL",
AvmOpcode::FEEPERL1GAS => "FEEPERL1GAS",
AvmOpcode::FEEPERL2GAS => "FEEPERL2GAS",
AvmOpcode::FEEPERDAGAS => "FEEPERDAGAS",
Expand Down
1 change: 0 additions & 1 deletion avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,6 @@ fn handle_getter_instruction(
"avmOpcodeAddress" => AvmOpcode::ADDRESS,
"avmOpcodeStorageAddress" => AvmOpcode::STORAGEADDRESS,
"avmOpcodeSender" => AvmOpcode::SENDER,
"avmOpcodePortal" => AvmOpcode::PORTAL,
"avmOpcodeFeePerL1Gas" => AvmOpcode::FEEPERL1GAS,
"avmOpcodeFeePerL2Gas" => AvmOpcode::FEEPERL2GAS,
"avmOpcodeFeePerDaGas" => AvmOpcode::FEEPERDAGAS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ enum class OpCode : uint8_t {
ADDRESS,
STORAGEADDRESS,
SENDER,
PORTAL,
FEEPERL1GAS,
FEEPERL2GAS,
FEEPERDAGAS,
Expand Down
18 changes: 0 additions & 18 deletions docs/src/preprocess/InstructionSet/InstructionSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,24 +547,6 @@ const INSTRUCTION_SET_RAW = [
"Tag checks": "",
"Tag updates": "`T[dstOffset] = u32`",
},
{
id: "portal",
Name: "`PORTAL`",
Category: "Execution Environment",
Flags: [{ name: "indirect", description: INDIRECT_FLAG_DESCRIPTION }],
Args: [
{
name: "dstOffset",
description:
"memory offset specifying where to store operation's result",
},
],
Expression: "`M[dstOffset] = context.environment.portal`",
Summary: "Get the address of the l1 portal contract",
Details: "",
"Tag checks": "",
"Tag updates": "`T[dstOffset] = u32`",
},
{
id: "feeperl1gas",
Name: "`FEEPERL1GAS`",
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ library Constants {
uint256 internal constant DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE =
0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631;
uint256 internal constant DEPLOYER_CONTRACT_ADDRESS =
0x123e80d90c7ceeedcc20d96e564fe2b8977ccb1d49bf9e1160c211dbe3dec13d;
0x190b899400f7304c1fe5882a9fcda869e33e576e5343e07d60a907931da095bb;
uint256 internal constant AZTEC_ADDRESS_LENGTH = 1;
uint256 internal constant DIMENSION_GAS_SETTINGS_LENGTH = 3;
uint256 internal constant GAS_FEES_LENGTH = 3;
Expand Down
5 changes: 2 additions & 3 deletions noir-projects/aztec-nr/aztec/src/deploy.nr
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ pub fn deploy_contract(context: &mut PrivateContext, target: AztecAddress) {
serialized_args[0] = instance.salt;
serialized_args[1] = instance.contract_class_id.to_field();
serialized_args[2] = instance.initialization_hash;
serialized_args[3] = instance.portal_contract_address.to_field();
serialized_args[4] = instance.public_keys_hash.to_field();
serialized_args[5] = universal_deploy as Field;
serialized_args[3] = instance.public_keys_hash.to_field();
serialized_args[4] = universal_deploy as Field;

let _call_result = context.call_private_function(
AztecAddress::from_field(DEPLOYER_CONTRACT_ADDRESS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ contract AvmTest {
global big_field_136_bits: Field = 0x991234567890abcdef1234567890abcdef;

// Libs
use dep::aztec::protocol_types::constants::CONTRACT_INSTANCE_LENGTH;
use dep::aztec::prelude::{Map, Deserialize};
use dep::aztec::state_vars::PublicMutable;
use dep::aztec::protocol_types::{address::{AztecAddress, EthAddress}, constants::L1_TO_L2_MESSAGE_LENGTH};
Expand Down Expand Up @@ -172,14 +173,14 @@ contract AvmTest {
#[aztec(public-vm)]
fn test_get_contract_instance_raw() {
let fields = get_contract_instance_internal_avm(context.this_address());
assert(fields.len() == 7);
// The values here should match those in `avm_simulator.test.ts>Contract>GETCONTRACTINSTANCE deserializes correctly`
assert(fields.len() == CONTRACT_INSTANCE_LENGTH + 1);
assert(fields[0] == 0x1);
assert(fields[1] == 0x123);
assert(fields[2] == 0x456);
assert(fields[3] == 0x789);
assert(fields[4] == 0x101112);
assert(fields[5] == 0x131415);
assert(fields[6] == 0x161718);
assert(fields[5] == 0x161718);
}

#[aztec(public-vm)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ struct ContractInstanceDeployed {
salt: Field,
contract_class_id: ContractClassId,
initialization_hash: Field,
portal_contract_address: EthAddress,
public_keys_hash: PublicKeysHash,
deployer: AztecAddress,
}

global CONTRACT_INSTANCE_DEPLOYED_SERIALIZED_SIZE: Field = 9;
global CONTRACT_INSTANCE_DEPLOYED_SERIALIZED_SIZE: Field = 8;

impl Serialize<CONTRACT_INSTANCE_DEPLOYED_SERIALIZED_SIZE> for ContractInstanceDeployed {
fn serialize(self: Self) -> [Field; CONTRACT_INSTANCE_DEPLOYED_SERIALIZED_SIZE] {
Expand All @@ -27,7 +26,6 @@ impl Serialize<CONTRACT_INSTANCE_DEPLOYED_SERIALIZED_SIZE> for ContractInstanceD
self.salt,
self.contract_class_id.to_field(),
self.initialization_hash,
self.portal_contract_address.to_field(),
self.public_keys_hash.to_field(),
self.deployer.to_field(),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ contract ContractInstanceDeployer {
salt: Field,
contract_class_id: ContractClassId,
initialization_hash: Field,
portal_contract_address: EthAddress,
public_keys_hash: PublicKeysHash,
universal_deploy: bool
) {
Expand All @@ -28,30 +27,15 @@ contract ContractInstanceDeployer {
context.msg_sender()
};

let partial_address = PartialAddress::compute(
contract_class_id,
salt,
initialization_hash,
portal_contract_address,
deployer
);
let partial_address = PartialAddress::compute(contract_class_id, salt, initialization_hash, deployer);

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,
deployer,
version: 1
};
let event = ContractInstanceDeployed { contract_class_id, address, public_keys_hash, initialization_hash, salt, deployer, 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ mod tests {
let mut builder = PublicKernelAppLogicCircuitPrivateInputsBuilder::new();

let contract_address = builder.public_call.contract_address;
let portal_contract_address = builder.public_call.portal_contract_address;
let portal_contract_address = EthAddress::from_field(0xdead);
// Setup 1 new l2 to l1 message on the previous kernel.
let previous = [12345];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::{
struct CallContext {
msg_sender : AztecAddress,
storage_contract_address : AztecAddress,
portal_contract_address : EthAddress,
function_selector : FunctionSelector,
gas_left: Gas,

Expand Down Expand Up @@ -51,7 +50,6 @@ impl Serialize<CALL_CONTEXT_LENGTH> for CallContext {

serialized.push(self.msg_sender.to_field());
serialized.push(self.storage_contract_address.to_field());
serialized.push(self.portal_contract_address.to_field());
serialized.push(self.function_selector.to_field());
serialized.extend_from_array(self.gas_left.serialize());
serialized.push(self.is_delegate_call as Field);
Expand All @@ -70,7 +68,6 @@ impl Deserialize<CALL_CONTEXT_LENGTH> for CallContext {
CallContext {
msg_sender: AztecAddress::from_field(reader.read()),
storage_contract_address: AztecAddress::from_field(reader.read()),
portal_contract_address: EthAddress::from_field(reader.read()),
function_selector: FunctionSelector::from_field(reader.read()),
gas_left: reader.read_struct(Gas::deserialize),
is_delegate_call: reader.read() as bool,
Expand All @@ -87,7 +84,6 @@ impl Empty for CallContext {
CallContext {
msg_sender: AztecAddress::empty(),
storage_contract_address: AztecAddress::empty(),
portal_contract_address: EthAddress::empty(),
function_selector: FunctionSelector::empty(),
gas_left: Gas::empty(),
is_delegate_call: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ struct PrivateCallData {

note_hash_read_request_membership_witnesses: [NoteHashReadRequestMembershipWitness; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL],

portal_contract_address: EthAddress,
acir_hash: Field,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ struct PublicCallData {
call_stack_item: PublicCallStackItem,
public_call_stack: [CallRequest; MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL],
proof: Proof,
portal_contract_address: EthAddress,
bytecode_hash: Field,
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,11 @@ impl AztecAddress {
contract_class_id: ContractClassId,
salt: Field,
initialization_hash: Field,
portal_contract_address: EthAddress,
deployer: AztecAddress
) -> AztecAddress {
AztecAddress::compute(
PublicKeysHash::compute(pub_key),
PartialAddress::compute(
contract_class_id,
salt,
initialization_hash,
portal_contract_address,
deployer
)
PartialAddress::compute(contract_class_id, salt, initialization_hash, deployer)
)
}

Expand Down Expand Up @@ -102,15 +95,13 @@ fn compute_address() {
let contract_address_salt = 3;
let contract_class_id = ContractClassId::from_field(4);
let initialization_hash = 5;
let portal_contract_address = EthAddress::from_field(6);
let deployer = AztecAddress::from_field(7);
let deployer = AztecAddress::from_field(6);

let address = AztecAddress::compute_from_public_key(
point,
contract_class_id,
contract_address_salt,
initialization_hash,
portal_contract_address,
deployer
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ impl PartialAddress {
contract_class_id: ContractClassId,
salt: Field,
initialization_hash: Field,
portal_contract_address: EthAddress,
deployer: AztecAddress
) -> Self {
PartialAddress::compute_from_salted_initialization_hash(
contract_class_id,
SaltedInitializationHash::compute(salt, initialization_hash, portal_contract_address, deployer)
SaltedInitializationHash::compute(salt, initialization_hash, deployer)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@ impl SaltedInitializationHash {
Self { inner: field }
}

pub fn compute(
salt: Field,
initialization_hash: Field,
portal_contract_address: EthAddress,
deployer: AztecAddress
) -> Self {
pub fn compute(salt: Field, initialization_hash: Field, deployer: AztecAddress) -> Self {
SaltedInitializationHash::from_field(
pedersen_hash(
[
salt,
initialization_hash,
deployer.to_field(),
portal_contract_address.to_field()
deployer.to_field()
],
GENERATOR_INDEX__PARTIAL_ADDRESS
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,17 @@ global REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = 0xe7af8166354
// CONTRACT INSTANCE CONSTANTS
// sha224sum 'struct ContractInstanceDeployed'
global DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631;
global DEPLOYER_CONTRACT_ADDRESS = 0x123e80d90c7ceeedcc20d96e564fe2b8977ccb1d49bf9e1160c211dbe3dec13d;
global DEPLOYER_CONTRACT_ADDRESS = 0x190b899400f7304c1fe5882a9fcda869e33e576e5343e07d60a907931da095bb;

// LENGTH OF STRUCTS SERIALIZED TO FIELDS
global AZTEC_ADDRESS_LENGTH = 1;
global DIMENSION_GAS_SETTINGS_LENGTH: u64 = 3;
global GAS_FEES_LENGTH: u64 = 3;
global GAS_LENGTH: u64 = 3;
global GAS_SETTINGS_LENGTH: u64 = 1 + 3 * DIMENSION_GAS_SETTINGS_LENGTH;
global CALL_CONTEXT_LENGTH: u64 = 8 + GAS_SETTINGS_LENGTH + GAS_LENGTH;
global CALL_CONTEXT_LENGTH: u64 = 7 + GAS_SETTINGS_LENGTH + GAS_LENGTH;
global CONTENT_COMMITMENT_LENGTH: u64 = 4;
global CONTRACT_INSTANCE_LENGTH: u64 = 6;
global CONTRACT_INSTANCE_LENGTH: u64 = 5;
global CONTRACT_STORAGE_READ_LENGTH: u64 = 2;
global CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH: u64 = 2;
global ETH_ADDRESS_LENGTH = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct ContractInstance {
deployer: AztecAddress,
contract_class_id : ContractClassId,
initialization_hash : Field,
portal_contract_address : EthAddress,
public_keys_hash : PublicKeysHash,
}

Expand All @@ -22,8 +21,7 @@ impl Eq for ContractInstance {
self.public_keys_hash.eq(other.public_keys_hash) &
self.initialization_hash.eq(other.initialization_hash) &
self.contract_class_id.eq(other.contract_class_id) &
self.salt.eq(other.salt) &
self.portal_contract_address.eq(other.portal_contract_address)
self.salt.eq(other.salt)
}
}

Expand All @@ -34,7 +32,6 @@ impl Serialize<CONTRACT_INSTANCE_LENGTH> for ContractInstance {
self.deployer.to_field(),
self.contract_class_id.to_field(),
self.initialization_hash,
self.portal_contract_address.to_field(),
self.public_keys_hash.to_field()
]
}
Expand All @@ -47,8 +44,7 @@ impl Deserialize<CONTRACT_INSTANCE_LENGTH> for ContractInstance {
deployer: AztecAddress::from_field(serialized[1]),
contract_class_id: ContractClassId::from_field(serialized[2]),
initialization_hash: serialized[3],
portal_contract_address: EthAddress::from_field(serialized[4]),
public_keys_hash: PublicKeysHash::from_field(serialized[5]),
public_keys_hash: PublicKeysHash::from_field(serialized[4]),
}
}
}
Expand All @@ -67,7 +63,6 @@ impl ContractInstance {
self.contract_class_id,
self.salt,
self.initialization_hash,
self.portal_contract_address,
self.deployer
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ struct ContractData {
artifact_hash: Field,
contract_address_salt: Field,
contract_class_id: ContractClassId,
portal_contract_address: EthAddress,
private_functions_root: Field,
public_bytecode_commitment: Field,
public_keys_hash: PublicKeysHash,
Expand All @@ -24,7 +23,6 @@ global default_contract = ContractData {
private_functions_root: 0x19a3cc0b714976fb35d58b684ba36e86f82bac8b87517904a2727e5113fb4cba,
address: AztecAddress { inner: 0x25de5f29a6d515e67d0ac85f399098acd03c5d4a4884b8c560aee68014715ef1 },
partial_address: PartialAddress { inner: 0x1420f3a4c4a589be4ea00c0a131dc00127d566725b21dcd1fb421a724710e66b },
portal_contract_address: EthAddress { inner: 0x0000000000000000000000000000000000005ba0 },
contract_class_id: ContractClassId { inner: 0x0ce2a998337b1e6da1ac1d802a8bb9e10b7d705d210e61efb9642855009814a6 },
public_keys_hash: PublicKeysHash { inner: 0x000000000000000000000000000000000000000000000000000000000000b26e },
salted_initialization_hash: SaltedInitializationHash { inner: 0x2003637d02f08887d36dc2f27dd961f51f17e0a8a43dc0268dfcefcd96efc3a4 },
Expand All @@ -39,7 +37,6 @@ global parent_contract = ContractData {
private_functions_root: 0x2c1c949cb226995de94b7b8b5aeaab440739f2dfeb06d358441f60932cf243a7,
address: AztecAddress { inner: 0x178916e52e64b3880e7f837ab30e58222b2971f0150cbc16060bb3589fd96e23 },
partial_address: PartialAddress { inner: 0x009a6e74b3cebfe0351ceec448d722aa973c1c9da63bbf9f902f1896f3fa1832 },
portal_contract_address: EthAddress { inner: 0x0000000000000000000000000000000000000913 },
contract_class_id: ContractClassId { inner: 0x1f1f963a350e2c883cc6730c19fc5d5b47a40694d805cbb0720fa76fe295df90 },
public_keys_hash: PublicKeysHash { inner: 0x00000000000000000000000000000000000000000000000000000000000011c1 },
salted_initialization_hash: SaltedInitializationHash { inner: 0x275e153c147f9cb61a5e7b354e81484696d6a54ffc251dcf4ed8276ab24868d2 },
Expand Down
Loading

0 comments on commit 01bb109

Please sign in to comment.