Skip to content

Commit

Permalink
using traits
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Feb 2, 2024
1 parent 56cd2d1 commit 034920f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use crate::{
side_effect::{SideEffect, SideEffectLinkedToNoteHash},
},
contrakt::deployment_data::ContractDeploymentData,
hash::{
pedersen_hash,
},
hash::pedersen_hash,
header::Header,
};
use crate::constants::{
Expand All @@ -23,7 +21,7 @@ use crate::constants::{
PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH,
GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS,
};
use crate::traits::{Hash, Serialize, Deserialize};
use crate::traits::{Hash, Serialize};

struct PrivateCircuitPublicInputs {
call_context: CallContext,
Expand Down Expand Up @@ -61,12 +59,6 @@ struct PrivateCircuitPublicInputs {
version: Field,
}

impl Hash for PrivateCircuitPublicInputs {
fn hash(self) -> Field {
pedersen_hash(self.serialize(), GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS)
}
}

impl Serialize<PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH> for PrivateCircuitPublicInputs {
fn serialize(self) -> [Field; PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH] {
let mut fields: BoundedVec<Field, PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH> = BoundedVec::new(0);
Expand Down Expand Up @@ -102,6 +94,12 @@ impl Serialize<PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH> for PrivateCircuitPublicInp
}
}

impl Hash for PrivateCircuitPublicInputs {
fn hash(self) -> Field {
pedersen_hash(self.serialize(), GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS)
}
}

#[test]
fn serialization_smoke() {
let pcpi: PrivateCircuitPublicInputs = dep::std::unsafe::zeroed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
hash::pedersen_hash,
header::Header,
};
use crate::traits::{Hash, Serialize, Deserialize};

struct PublicCircuitPublicInputs{
call_context: CallContext,
Expand Down Expand Up @@ -52,8 +53,8 @@ struct PublicCircuitPublicInputs{
prover_address: AztecAddress,
}

impl PublicCircuitPublicInputs{
pub fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] {
impl Serialize<PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH> for PublicCircuitPublicInputs {
fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] {
let mut fields: BoundedVec<Field, PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH> = BoundedVec::new(0);
fields.extend_from_array(self.call_context.serialize());
fields.push(self.args_hash);
Expand All @@ -79,8 +80,22 @@ impl PublicCircuitPublicInputs{
fields.push(self.prover_address.to_field());
fields.storage
}
}

fn hash(self) -> Field {
impl Hash for PublicCircuitPublicInputs {
fn hash(self) -> Field {
pedersen_hash(self.serialize(), GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS)
}
}

#[test]
fn serialization_smoke() {
let pcpi: PublicCircuitPublicInputs = dep::std::unsafe::zeroed();
let _serialized = pcpi.serialize();
}

#[test]
fn hash_smoke() {
let pcpi: PublicCircuitPublicInputs = dep::std::unsafe::zeroed();
let _hashed = pcpi.hash();
}

0 comments on commit 034920f

Please sign in to comment.