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 felt #143

Merged
merged 20 commits into from
Jun 10, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
fixed hashes
  • Loading branch information
antiyro committed Jun 10, 2024
commit 7bceff83bde423547e8e8fd78b0e732540652a46
13 changes: 8 additions & 5 deletions crates/client/sync/src/commitments/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn calculate_transaction_hash_with_signature(
transaction: &Transaction,
chain_id: Felt252Wrapper,
block_number: u64,
) -> Felt {
) -> (Felt, Felt) {
let include_signature = block_number >= 61394;

let (signature_hash, tx_hash) = rayon::join(
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn calculate_transaction_hash_with_signature(
|| Felt252Wrapper::from(transaction.compute_hash(chain_id, false, Some(block_number)).0).into(),
);

Pedersen::hash(&tx_hash, &signature_hash)
(Pedersen::hash(&tx_hash, &signature_hash), tx_hash)
}

/// Calculate the transaction commitment in memory using HashMapDb (which is more efficient for this
Expand Down Expand Up @@ -98,11 +98,14 @@ pub fn memory_transaction_commitment(
.map(|tx| calculate_transaction_hash_with_signature(tx, chain_id, block_number))
.collect::<Vec<_>>();

let mut tx_hashes: Vec<Felt> = Vec::with_capacity(txs.len());

// once transaction hashes have finished computing, they are inserted into the local Bonsai db
for (i, &tx_hash) in txs.iter().enumerate() {
for (i, &(tx_hash_signature, tx_hash)) in txs.iter().enumerate() {
let key = BitVec::from_vec(i.to_be_bytes().to_vec());
let value = tx_hash;
let value = tx_hash_signature;
bonsai_storage.insert(identifier, key.as_bitslice(), &value).expect("Failed to insert into bonsai storage");
tx_hashes.push(tx_hash);
}

let mut id_builder = BasicIdBuilder::new();
Expand All @@ -111,5 +114,5 @@ pub fn memory_transaction_commitment(
bonsai_storage.commit(id).expect("Failed to commit to bonsai storage");
let root_hash = bonsai_storage.root_hash(identifier).expect("Failed to get root hash");

Ok((root_hash, txs))
Ok((root_hash, tx_hashes))
}