Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Fix fmt issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fishseabowl committed May 31, 2024
1 parent 8825202 commit cdc64f7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 74 deletions.
2 changes: 1 addition & 1 deletion crates/primitives/hashers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait HasherT {
// Default implementation
let hash = Self::compute_hash_on_elements(
data.into_iter() // Convert the data into an iterator
.map(|x| x.0) // Map each Felt252Wrapper to its inner FieldElement
.map(|x| x.0), // Map each Felt252Wrapper to its inner FieldElement
);

// Wrap the computed hash in a Felt252Wrapper and return it
Expand Down
5 changes: 2 additions & 3 deletions crates/primitives/hashers/src/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl HasherT for PedersenHasher {

Felt252Wrapper(hash_value)
}

#[inline(always)]
fn hash_elements(a: FieldElement, b: FieldElement) -> FieldElement {
pedersen_hash(&a, &b)
Expand All @@ -60,12 +60,11 @@ impl HasherT for PedersenHasher {
#[inline]
fn compute_hash_on_elements<I>(elements: I) -> FieldElement
where
I: IntoIterator<Item = FieldElement>
I: IntoIterator<Item = FieldElement>,
{
let elements_vec: Vec<FieldElement> = elements.into_iter().collect();
compute_hash_on_elements(&elements_vec)
}

}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/hashers/src/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl HasherT for PoseidonHasher {

fn compute_hash_on_elements<I>(elements: I) -> FieldElement
where
I: IntoIterator<Item = FieldElement>
I: IntoIterator<Item = FieldElement>,
{
let elements_vec: Vec<FieldElement> = elements.into_iter().collect();
poseidon_hash_many(&elements_vec)
Expand Down
113 changes: 44 additions & 69 deletions crates/primitives/transactions/src/compute_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,10 @@ impl ComputeTransactionHash for InvokeTransactionV0 {
let calldata_hash = compute_hash_on_elements(&convert_calldata(self.calldata.clone()));
let max_fee = FieldElement::from(self.max_fee.0);

Felt252Wrapper(PedersenHasher::compute_hash_on_elements([
prefix,
version,
contract_address,
entrypoint_selector,
calldata_hash,
max_fee,
chain_id.into(),
].into_iter()))
Felt252Wrapper(PedersenHasher::compute_hash_on_elements(
[prefix, version, contract_address, entrypoint_selector, calldata_hash, max_fee, chain_id.into()]
.into_iter(),
))
.into()
}
}
Expand All @@ -89,16 +84,10 @@ impl ComputeTransactionHash for InvokeTransactionV1 {
let max_fee = FieldElement::from(self.max_fee.0);
let nonce = Felt252Wrapper::from(self.nonce.0).into();

Felt252Wrapper(PedersenHasher::compute_hash_on_elements([
prefix,
version,
sender_address,
entrypoint_selector,
calldata_hash,
max_fee,
chain_id.into(),
nonce,
].into_iter()))
Felt252Wrapper(PedersenHasher::compute_hash_on_elements(
[prefix, version, sender_address, entrypoint_selector, calldata_hash, max_fee, chain_id.into(), nonce]
.into_iter(),
))
.into()
}
}
Expand All @@ -113,9 +102,8 @@ impl ComputeTransactionHash for InvokeTransactionV3 {
let account_deployment_data_hash = PoseidonHasher::compute_hash_on_elements(
self.account_deployment_data.0.iter().map(|f| Felt252Wrapper::from(*f).into()),
);
let calldata_hash = PoseidonHasher::compute_hash_on_elements(
self.calldata.0.iter().map(|f| Felt252Wrapper::from(*f).into()),
);
let calldata_hash =
PoseidonHasher::compute_hash_on_elements(self.calldata.0.iter().map(|f| Felt252Wrapper::from(*f).into()));

compute_transaction_hash_common_v3(
prefix,
Expand Down Expand Up @@ -166,16 +154,10 @@ fn compute_hash_declare_v0_or_v1(
FieldElement::from(version)
};

Felt252Wrapper(PedersenHasher::compute_hash_on_elements([
prefix,
version,
sender_address,
zero,
class_or_nothing_hash,
max_fee,
chain_id.into(),
nonce_or_class_hash,
].into_iter()))
Felt252Wrapper(PedersenHasher::compute_hash_on_elements(
[prefix, version, sender_address, zero, class_or_nothing_hash, max_fee, chain_id.into(), nonce_or_class_hash]
.into_iter(),
))
.into()
}

Expand All @@ -190,17 +172,20 @@ impl ComputeTransactionHash for DeclareTransactionV2 {
let nonce = Felt252Wrapper::from(self.nonce).into();
let compiled_class_hash = Felt252Wrapper::from(self.compiled_class_hash).into();

Felt252Wrapper(PedersenHasher::compute_hash_on_elements([
prefix,
version,
sender_address,
entrypoint_selector,
calldata,
max_fee,
chain_id.into(),
nonce,
compiled_class_hash,
].into_iter()))
Felt252Wrapper(PedersenHasher::compute_hash_on_elements(
[
prefix,
version,
sender_address,
entrypoint_selector,
calldata,
max_fee,
chain_id.into(),
nonce,
compiled_class_hash,
]
.into_iter(),
))
.into()
}
}
Expand Down Expand Up @@ -280,16 +265,10 @@ impl ComputeTransactionHash for DeployAccountTransactionV1 {
let max_fee = FieldElement::from(self.max_fee.0);
let nonce = Felt252Wrapper::from(self.nonce).into();

Felt252Wrapper(PedersenHasher::compute_hash_on_elements([
prefix,
version,
contract_address,
entrypoint_selector,
calldata_hash,
max_fee,
chain_id.into(),
nonce,
].into_iter()))
Felt252Wrapper(PedersenHasher::compute_hash_on_elements(
[prefix, version, contract_address, entrypoint_selector, calldata_hash, max_fee, chain_id.into(), nonce]
.into_iter(),
))
.into()
}
}
Expand Down Expand Up @@ -342,15 +321,9 @@ impl ComputeTransactionHash for L1HandlerTransaction {
let calldata_hash = compute_hash_on_elements(&convert_calldata(self.calldata.clone()));
let nonce = Felt252Wrapper::from(self.nonce).into();

Felt252Wrapper(PedersenHasher::compute_hash_on_elements([
prefix,
version,
contract_address,
entrypoint_selector,
calldata_hash,
chain_id.into(),
nonce,
].into_iter()))
Felt252Wrapper(PedersenHasher::compute_hash_on_elements(
[prefix, version, contract_address, entrypoint_selector, calldata_hash, chain_id.into(), nonce].into_iter(),
))
.into()
}
}
Expand All @@ -369,14 +342,16 @@ fn compute_transaction_hash_common_v3(
resource_bounds: &ResourceBoundsMapping,
additional_data: Vec<FieldElement>,
) -> TransactionHash {
let gas_hash = PoseidonHasher::compute_hash_on_elements([
FieldElement::from(tip.0),
prepare_resource_bound_value(resource_bounds, Resource::L1Gas),
prepare_resource_bound_value(resource_bounds, Resource::L2Gas),
].into_iter());
let paymaster_hash = PoseidonHasher::compute_hash_on_elements(
paymaster_data.0.iter().map(|f| Felt252Wrapper::from(*f).into()),
let gas_hash = PoseidonHasher::compute_hash_on_elements(
[
FieldElement::from(tip.0),
prepare_resource_bound_value(resource_bounds, Resource::L1Gas),
prepare_resource_bound_value(resource_bounds, Resource::L2Gas),
]
.into_iter(),
);
let paymaster_hash =
PoseidonHasher::compute_hash_on_elements(paymaster_data.0.iter().map(|f| Felt252Wrapper::from(*f).into()));
let data_availability_modes =
prepare_data_availability_modes(nonce_data_availability_mode, fee_data_availability_mode);
let mut data_to_hash = vec![
Expand Down

0 comments on commit cdc64f7

Please sign in to comment.