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

cov tx utils #710

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 16 additions & 8 deletions cairo/ethereum/cancun/fork.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@
TX_DATA_COST_PER_NON_ZERO,
TX_DATA_COST_PER_ZERO,
Transaction,
TransactionImpl,
get_transaction_type,
get_gas,
get_r,
get_s,
get_max_fee_per_gas,
get_max_priority_fee_per_gas,
get_gas_price,
get_nonce,
get_value,
TransactionType,
TupleAccessList,
TupleAccessListStruct,
Expand Down Expand Up @@ -614,21 +622,21 @@
excess_blob_gas: U64,
) -> TupleAddressUintTupleVersionedHash {
alloc_locals;
let gas = TransactionImpl.get_gas(tx);
let gas = get_gas(tx);

Check warning on line 625 in cairo/ethereum/cancun/fork.cairo

View check run for this annotation

Codecov / codecov/patch

cairo/ethereum/cancun/fork.cairo#L625

Added line #L625 was not covered by tests
let tx_gas_within_bounds = is_le(gas.value, gas_available.value);
with_attr error_message("InvalidBlock") {
assert tx_gas_within_bounds = 1;
}
let sender_address = recover_sender(chain_id, tx);
let sender_account = get_account{state=state}(sender_address);
let transaction_type = TransactionImpl.get_transaction_type(tx);
let transaction_type = get_transaction_type(tx);

Check warning on line 632 in cairo/ethereum/cancun/fork.cairo

View check run for this annotation

Codecov / codecov/patch

cairo/ethereum/cancun/fork.cairo#L632

Added line #L632 was not covered by tests
let is_not_blob_or_fee_transaction = (TransactionType.BLOB - transaction_type) * (
TransactionType.FEE_MARKET - transaction_type
);
// Case where transaction is blob or fee transaction
if (is_not_blob_or_fee_transaction == FALSE) {
let max_fee_per_gas = TransactionImpl.get_max_fee_per_gas(tx);
let max_priority_fee_per_gas = TransactionImpl.get_max_priority_fee_per_gas(tx);
let max_fee_per_gas = get_max_fee_per_gas(tx);
let max_priority_fee_per_gas = get_max_priority_fee_per_gas(tx);

Check warning on line 639 in cairo/ethereum/cancun/fork.cairo

View check run for this annotation

Codecov / codecov/patch

cairo/ethereum/cancun/fork.cairo#L638-L639

Added lines #L638 - L639 were not covered by tests
let max_fee_per_gas_valid = is_le(base_fee_per_gas.value, max_fee_per_gas.value);
let max_priority_fee_per_gas_valid = is_le(
max_priority_fee_per_gas.value, max_fee_per_gas.value
Expand All @@ -643,7 +651,7 @@
tempvar effective_gas_price = Uint(base_fee_per_gas.value + priority_fee_per_gas);
tempvar max_gas_fee = Uint(gas.value * max_fee_per_gas.value);
} else {
let gas_price = TransactionImpl.get_gas_price(tx);
let gas_price = get_gas_price(tx);

Check warning on line 654 in cairo/ethereum/cancun/fork.cairo

View check run for this annotation

Codecov / codecov/patch

cairo/ethereum/cancun/fork.cairo#L654

Added line #L654 was not covered by tests
let gas_price_valid = is_le(base_fee_per_gas.value, gas_price.value);
with_attr error_message("InvalidBlock") {
assert gas_price_valid = 1;
Expand Down Expand Up @@ -699,15 +707,15 @@

// Nonce check
let sender_account_nonce = sender_account.value.nonce;
let tx_nonce = TransactionImpl.get_nonce(tx);
let tx_nonce = get_nonce(tx);

Check warning on line 710 in cairo/ethereum/cancun/fork.cairo

View check run for this annotation

Codecov / codecov/patch

cairo/ethereum/cancun/fork.cairo#L710

Added line #L710 was not covered by tests
let tx_nonce_uint = U256_to_Uint(tx_nonce);
with_attr error_message("InvalidBlock") {
assert tx_nonce_uint.value = sender_account_nonce.value;
}

// Balance check
let sender_account_balance = sender_account.value.balance;
let tx_value = TransactionImpl.get_value(tx);
let tx_value = get_value(tx);

Check warning on line 718 in cairo/ethereum/cancun/fork.cairo

View check run for this annotation

Codecov / codecov/patch

cairo/ethereum/cancun/fork.cairo#L718

Added line #L718 was not covered by tests
let max_gas_fee_u256 = U256_from_Uint(max_gas_fee);
let (tx_total_spent, carry) = U256_add_with_carry(tx_value, max_gas_fee_u256);
with_attr error_message("InvalidBlock") {
Expand Down
7 changes: 4 additions & 3 deletions cairo/ethereum/cancun/transactions.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ from ethereum.cancun.transactions_types import (
BlobTransactionStruct,
To,
ToStruct,
TransactionImpl,
TupleAccessListStruct,
TX_BASE_COST,
TX_DATA_COST_PER_NON_ZERO,
TX_DATA_COST_PER_ZERO,
TX_CREATE_COST,
TX_ACCESS_LIST_ADDRESS_COST,
TX_ACCESS_LIST_STORAGE_KEY_COST,
get_r,
get_s,
)

from ethereum.crypto.hash import keccak256, Hash32
Expand Down Expand Up @@ -250,8 +251,8 @@ func recover_sender{
);
tempvar zero = U256(new U256Struct(low=0, high=0));

let r = TransactionImpl.get_r(tx);
let s = TransactionImpl.get_s(tx);
let r = get_r(tx);
let s = get_s(tx);

let r_is_zero = U256__eq__(r, zero);
let r_is_out_of_range = U256_le(SECP256K1N, r);
Expand Down
Loading