Skip to content
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

refactor: enforce only 1 trait impl #11041

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ impl Empty for BlobPublicInputs {
}
}

impl Serialize<BLOB_PUBLIC_INPUTS> for BlobPublicInputs {
fn serialize(self) -> [Field; BLOB_PUBLIC_INPUTS] {
impl Serialize for BlobPublicInputs {
let N = BLOB_PUBLIC_INPUTS;

fn serialize(self) -> [Field; Self::N] {
[
self.z,
self.y.limbs[0],
Expand Down Expand Up @@ -95,9 +97,11 @@ impl Empty for BlockBlobPublicInputs {
}
}

impl Serialize<BLOB_PUBLIC_INPUTS * BLOBS_PER_BLOCK> for BlockBlobPublicInputs {
fn serialize(self) -> [Field; BLOB_PUBLIC_INPUTS * BLOBS_PER_BLOCK] {
let mut fields: BoundedVec<Field, BLOB_PUBLIC_INPUTS * BLOBS_PER_BLOCK> = BoundedVec::new();
impl Serialize for BlockBlobPublicInputs {
let N = BLOB_PUBLIC_INPUTS * BLOBS_PER_BLOCK;

fn serialize(self) -> [Field; Self::N] {
let mut fields: BoundedVec<Field, Self::N> = BoundedVec::new();
for i in 0..BLOBS_PER_BLOCK {
fields.extend_from_array(self.inner[i].serialize());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ impl Empty for ParityPublicInputs {
}
}

impl Serialize<3> for ParityPublicInputs {
fn serialize(self) -> [Field; 3] {
let mut fields = [0; 3];
impl Serialize for ParityPublicInputs {
let N = 3;

fn serialize(self) -> [Field; Self::N] {
let mut fields = [0; Self::N];
fields[0] = self.sha_root;
fields[1] = self.converted_root;
fields[2] = self.vk_tree_root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ impl Eq for BaseOrMergeRollupPublicInputs {
}
}

impl Serialize<BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH> for BaseOrMergeRollupPublicInputs {
fn serialize(self) -> [Field; BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH] {
let mut fields: BoundedVec<Field, BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH> = BoundedVec::new();
impl Serialize for BaseOrMergeRollupPublicInputs {
let N = BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH;

fn serialize(self) -> [Field; Self::N] {
let mut fields: BoundedVec<Field, Self::N> = BoundedVec::new();

fields.push(self.rollup_type as Field);
fields.push(self.num_txs as Field);
Expand All @@ -80,7 +82,7 @@ impl Serialize<BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH> for BaseOrMergeRollupPublicIn
fields.push(self.out_hash as Field);
fields.push(self.accumulated_fees as Field);
fields.push(self.accumulated_mana_used as Field);
assert_eq(fields.len(), BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH);
assert_eq(fields.len(), Self::N);

fields.storage()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ impl Empty for FeeRecipient {
}
}

impl Serialize<FEE_RECIPIENT_LENGTH> for FeeRecipient {
fn serialize(self) -> [Field; FEE_RECIPIENT_LENGTH] {
impl Serialize for FeeRecipient {
let N = FEE_RECIPIENT_LENGTH;

fn serialize(self) -> [Field; Self::N] {
[self.recipient.to_field(), self.value]
}
}
Expand Down Expand Up @@ -99,10 +101,11 @@ impl Eq for BlockRootOrBlockMergePublicInputs {
}
}

impl Serialize<BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH> for BlockRootOrBlockMergePublicInputs {
fn serialize(self) -> [Field; BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH] {
let mut fields: BoundedVec<Field, BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH> =
BoundedVec::new();
impl Serialize for BlockRootOrBlockMergePublicInputs {
let N = BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH;

fn serialize(self) -> [Field; Self::N] {
let mut fields: BoundedVec<Field, Self::N> = BoundedVec::new();

fields.extend_from_array(self.previous_archive.serialize());
fields.extend_from_array(self.new_archive.serialize());
Expand All @@ -120,7 +123,7 @@ impl Serialize<BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH> for BlockRootOrBl
for i in 0..AZTEC_MAX_EPOCH_DURATION {
fields.extend_from_array(self.blob_public_inputs[i].serialize());
}
assert_eq(fields.len(), BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH);
assert_eq(fields.len(), Self::N);

fields.storage()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ impl Empty for AvmAccumulatedData {
}
}

impl Serialize<AVM_ACCUMULATED_DATA_LENGTH> for AvmAccumulatedData {
fn serialize(self) -> [Field; AVM_ACCUMULATED_DATA_LENGTH] {
let mut fields: BoundedVec<Field, AVM_ACCUMULATED_DATA_LENGTH> = BoundedVec::new();
impl Serialize for AvmAccumulatedData {
let N = AVM_ACCUMULATED_DATA_LENGTH;

fn serialize(self) -> [Field; Self::N] {
let mut fields: BoundedVec<Field, Self::N> = BoundedVec::new();

for i in 0..self.note_hashes.len() {
fields.extend_from_array(self.note_hashes[i].serialize());
Expand All @@ -62,7 +64,7 @@ impl Serialize<AVM_ACCUMULATED_DATA_LENGTH> for AvmAccumulatedData {
fields.extend_from_array(self.public_data_writes[i].serialize());
}

assert_eq(fields.len(), AVM_ACCUMULATED_DATA_LENGTH);
assert_eq(fields.len(), Self::N);

fields.storage()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ pub struct PrivateAccumulatedData {
pub private_call_stack: [PrivateCallRequest; MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX],
}

impl Serialize<PRIVATE_ACCUMULATED_DATA_LENGTH> for PrivateAccumulatedData {
fn serialize(self) -> [Field; PRIVATE_ACCUMULATED_DATA_LENGTH] {
let mut fields: BoundedVec<Field, PRIVATE_ACCUMULATED_DATA_LENGTH> = BoundedVec::new();
impl Serialize for PrivateAccumulatedData {
let N = PRIVATE_ACCUMULATED_DATA_LENGTH;

fn serialize(self) -> [Field; Self::N] {
let mut fields: BoundedVec<Field, Self::N> = BoundedVec::new();

for i in 0..MAX_NOTE_HASHES_PER_TX {
fields.extend_from_array(self.note_hashes[i].serialize());
Expand Down Expand Up @@ -62,7 +64,7 @@ impl Serialize<PRIVATE_ACCUMULATED_DATA_LENGTH> for PrivateAccumulatedData {
fields.extend_from_array(self.private_call_stack[i].serialize());
}

assert_eq(fields.len(), PRIVATE_ACCUMULATED_DATA_LENGTH);
assert_eq(fields.len(), Self::N);

fields.storage()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@ impl Eq for PrivateToAvmAccumulatedData {
}
}

impl Serialize<PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH> for PrivateToAvmAccumulatedData {
fn serialize(self) -> [Field; PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH] {
let mut fields: BoundedVec<Field, PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH> =
BoundedVec::new();
impl Serialize for PrivateToAvmAccumulatedData {
let N = PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH;

fn serialize(self) -> [Field; Self::N] {
let mut fields: BoundedVec<Field, Self::N> = BoundedVec::new();

fields.extend_from_array(self.note_hashes);
fields.extend_from_array(self.nullifiers);
for i in 0..self.l2_to_l1_msgs.len() {
fields.extend_from_array(self.l2_to_l1_msgs[i].serialize());
}

assert_eq(fields.len(), PRIVATE_TO_AVM_ACCUMULATED_DATA_LENGTH);
assert_eq(fields.len(), Self::N);

fields.storage()
}
Expand Down Expand Up @@ -98,10 +99,11 @@ impl Eq for PrivateToAvmAccumulatedDataArrayLengths {
}
}

impl Serialize<NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS> for PrivateToAvmAccumulatedDataArrayLengths {
fn serialize(self) -> [Field; NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS] {
let mut fields: BoundedVec<Field, NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS> =
BoundedVec::new();
impl Serialize for PrivateToAvmAccumulatedDataArrayLengths {
let N = NUM_PRIVATE_TO_AVM_ACCUMULATED_DATA_ARRAYS;

fn serialize(self) -> [Field; Self::N] {
let mut fields: BoundedVec<Field, Self::N> = BoundedVec::new();

fields.push(self.note_hashes as Field);
fields.push(self.nullifiers as Field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ impl Eq for PrivateToPublicAccumulatedData {
}
}

impl Serialize<PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH> for PrivateToPublicAccumulatedData {
fn serialize(self) -> [Field; PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH] {
let mut fields: BoundedVec<Field, PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH> =
BoundedVec::new();
impl Serialize for PrivateToPublicAccumulatedData {
let N = PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH;

fn serialize(self) -> [Field; Self::N] {
let mut fields: BoundedVec<Field, Self::N> = BoundedVec::new();

fields.extend_from_array(self.note_hashes);
fields.extend_from_array(self.nullifiers);
Expand All @@ -65,7 +66,7 @@ impl Serialize<PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH> for PrivateToPublicAcc
fields.extend_from_array(self.public_call_requests[i].serialize());
}

assert_eq(fields.len(), PRIVATE_TO_PUBLIC_ACCUMULATED_DATA_LENGTH);
assert_eq(fields.len(), Self::N);

fields.storage()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ impl Eq for AvmCircuitPublicInputs {
}
}

impl Serialize<AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH> for AvmCircuitPublicInputs {
fn serialize(self) -> [Field; AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH] {
let mut fields: BoundedVec<Field, AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH> = BoundedVec::new();
impl Serialize for AvmCircuitPublicInputs {
let N = AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH;

fn serialize(self) -> [Field; Self::N] {
let mut fields: BoundedVec<Field, Self::N> = BoundedVec::new();

fields.extend_from_array(self.global_variables.serialize());
fields.extend_from_array(self.start_tree_snapshots.serialize());
Expand All @@ -135,7 +137,7 @@ impl Serialize<AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH> for AvmCircuitPublicInputs {
fields.push(self.transaction_fee);
fields.push(self.reverted as Field);

assert_eq(fields.len(), AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH);
assert_eq(fields.len(), Self::N);

fields.storage()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ impl Eq for CallContext {
}
}

impl Serialize<CALL_CONTEXT_LENGTH> for CallContext {
fn serialize(self) -> [Field; CALL_CONTEXT_LENGTH] {
let mut serialized: BoundedVec<Field, CALL_CONTEXT_LENGTH> = BoundedVec::new();
impl Serialize for CallContext {
let N = CALL_CONTEXT_LENGTH;

fn serialize(self) -> [Field; Self::N] {
let mut serialized: BoundedVec<Field, Self::N> = BoundedVec::new();

serialized.push(self.msg_sender.to_field());
serialized.push(self.contract_address.to_field());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ impl Empty for CombinedConstantData {
}
}

impl Serialize<COMBINED_CONSTANT_DATA_LENGTH> for CombinedConstantData {
fn serialize(self) -> [Field; COMBINED_CONSTANT_DATA_LENGTH] {
let mut fields: BoundedVec<Field, COMBINED_CONSTANT_DATA_LENGTH> = BoundedVec::new();
impl Serialize for CombinedConstantData {
let N = COMBINED_CONSTANT_DATA_LENGTH;

fn serialize(self) -> [Field; Self::N] {
let mut fields: BoundedVec<Field, Self::N> = BoundedVec::new();

fields.extend_from_array(self.historical_header.serialize());
fields.extend_from_array(self.tx_context.serialize());
fields.push(self.vk_tree_root);
fields.push(self.protocol_contract_tree_root);
fields.extend_from_array(self.global_variables.serialize());

assert_eq(fields.len(), COMBINED_CONSTANT_DATA_LENGTH);
assert_eq(fields.len(), Self::N);

fields.storage()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ impl Empty for ConstantRollupData {
}
}

impl Serialize<CONSTANT_ROLLUP_DATA_LENGTH> for ConstantRollupData {
fn serialize(self) -> [Field; CONSTANT_ROLLUP_DATA_LENGTH] {
let mut fields: BoundedVec<Field, CONSTANT_ROLLUP_DATA_LENGTH> = BoundedVec::new();
impl Serialize for ConstantRollupData {
let N = CONSTANT_ROLLUP_DATA_LENGTH;

fn serialize(self) -> [Field; Self::N] {
let mut fields: BoundedVec<Field, Self::N> = BoundedVec::new();

fields.extend_from_array(self.last_archive.serialize());
fields.push(self.vk_tree_root);
fields.push(self.protocol_contract_tree_root);
fields.extend_from_array(self.global_variables.serialize());

assert_eq(fields.len(), CONSTANT_ROLLUP_DATA_LENGTH);
assert_eq(fields.len(), Self::N);

fields.storage()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ impl Eq for EventSelector {
}
}

impl Serialize<1> for EventSelector {
fn serialize(self: Self) -> [Field; 1] {
impl Serialize for EventSelector {
let N = 1;

fn serialize(self: Self) -> [Field; Self::N] {
[self.inner as Field]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ impl Eq for FunctionData {
}
}

impl Serialize<FUNCTION_DATA_LENGTH> for FunctionData {
impl Serialize for FunctionData {
let N = FUNCTION_DATA_LENGTH;

// A field is ~256 bits
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/3057): Since, function data can fit into a Field,
// This method will simply return a bit packed Field instead of hashing
fn serialize(self) -> [Field; FUNCTION_DATA_LENGTH] {
fn serialize(self) -> [Field; Self::N] {
[self.selector.to_field(), self.is_private as Field]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ impl Eq for FunctionSelector {
}
}

impl Serialize<1> for FunctionSelector {
fn serialize(self: Self) -> [Field; 1] {
impl Serialize for FunctionSelector {
let N = 1;

fn serialize(self: Self) -> [Field; Self::N] {
[self.inner as Field]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ impl Sub for Gas {
}
}

impl Serialize<GAS_LENGTH> for Gas {
fn serialize(self) -> [Field; GAS_LENGTH] {
impl Serialize for Gas {
let N = GAS_LENGTH;

fn serialize(self) -> [Field; Self::N] {
[self.da_gas as Field, self.l2_gas as Field]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ impl GasFees {
}
}

impl Serialize<GAS_FEES_LENGTH> for GasFees {
fn serialize(self) -> [Field; GAS_FEES_LENGTH] {
impl Serialize for GasFees {
let N = GAS_FEES_LENGTH;

fn serialize(self) -> [Field; Self::N] {
[self.fee_per_da_gas, self.fee_per_l2_gas]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ impl Empty for GasSettings {
}
}

impl Serialize<GAS_SETTINGS_LENGTH> for GasSettings {
fn serialize(self) -> [Field; GAS_SETTINGS_LENGTH] {
let mut serialized: BoundedVec<Field, GAS_SETTINGS_LENGTH> = BoundedVec::new();
impl Serialize for GasSettings {
let N = GAS_SETTINGS_LENGTH;

fn serialize(self) -> [Field; Self::N] {
let mut serialized: BoundedVec<Field, Self::N> = BoundedVec::new();

serialized.extend_from_array(self.gas_limits.serialize());
serialized.extend_from_array(self.teardown_gas_limits.serialize());
Expand Down
Loading
Loading