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

Commit

Permalink
Fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fishseabowl committed May 31, 2024
1 parent cdc64f7 commit 90d2dd0
Showing 1 changed file with 66 additions and 43 deletions.
109 changes: 66 additions & 43 deletions crates/primitives/transactions/src/compute_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@ 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()
}
}
Expand All @@ -84,10 +89,16 @@ 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()
}
}
Expand Down Expand Up @@ -154,10 +165,16 @@ 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()
}

Expand All @@ -172,20 +189,17 @@ 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()
}
}
Expand Down Expand Up @@ -265,10 +279,16 @@ 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()
}
}
Expand All @@ -290,7 +310,7 @@ impl ComputeTransactionHash for DeployAccountTransactionV3 {
)
.into();
let nonce = Felt252Wrapper::from(self.nonce.0).into();
let constructor_calldata_hash = PoseidonHasher::compute_hash_on_elements(constructor_calldata.into_iter());
let constructor_calldata_hash = PoseidonHasher::compute_hash_on_elements(constructor_calldata);

compute_transaction_hash_common_v3(
prefix,
Expand Down Expand Up @@ -321,9 +341,15 @@ 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()
}
}
Expand All @@ -342,14 +368,11 @@ 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 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),
]);
let paymaster_hash =
PoseidonHasher::compute_hash_on_elements(paymaster_data.0.iter().map(|f| Felt252Wrapper::from(*f).into()));
let data_availability_modes =
Expand All @@ -365,7 +388,7 @@ fn compute_transaction_hash_common_v3(
data_availability_modes,
];
data_to_hash.extend(additional_data);
Felt252Wrapper(PoseidonHasher::compute_hash_on_elements(data_to_hash.into_iter())).into()
Felt252Wrapper(PoseidonHasher::compute_hash_on_elements(data_to_hash)).into()
}

#[cfg(test)]
Expand Down

0 comments on commit 90d2dd0

Please sign in to comment.