Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Mar 31, 2024
1 parent 4d4cfe6 commit 636afdd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 59 deletions.
29 changes: 4 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions crates/katana/primitives/src/utils/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,40 +308,6 @@ fn encode_da_mode(
FieldElement::from(nonce + fee)
}

fn encode_gas_bound(name: &[u8], bound: &ResourceBounds) -> FieldElement {
let mut buffer = [0u8; 32];
let (remainder, max_price) = buffer.split_at_mut(128 / 8);
let (gas_kind, max_amount) = remainder.split_at_mut(64 / 8);

let padding = gas_kind.len() - name.len();
gas_kind[padding..].copy_from_slice(name);
max_amount.copy_from_slice(&bound.max_amount.to_be_bytes());
max_price.copy_from_slice(&bound.max_price_per_unit.to_be_bytes());

FieldElement::from_bytes_be(&buffer).expect("Packed resource should fit into felt")
}

fn hash_fee_fields(
tip: u64,
l1_gas_bounds: &ResourceBounds,
l2_gas_bounds: &ResourceBounds,
) -> FieldElement {
poseidon_hash_many(&[
tip.into(),
encode_gas_bound(b"L1_GAS", l1_gas_bounds),
encode_gas_bound(b"L2_GAS", l2_gas_bounds),
])
}

fn encode_da_mode(
nonce_da_mode: &DataAvailabilityMode,
fee_da_mode: &DataAvailabilityMode,
) -> FieldElement {
let nonce = (*nonce_da_mode as u64) << 32;
let fee = *fee_da_mode as u64;
FieldElement::from(nonce + fee)
}

#[cfg(test)]
mod tests {
use starknet::core::chain_id;
Expand Down

0 comments on commit 636afdd

Please sign in to comment.