Skip to content

Commit

Permalink
Format, typecheck, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamWilsn committed Oct 2, 2024
1 parent 5ee9725 commit a6f5239
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
41 changes: 25 additions & 16 deletions src/ethereum/prague/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
state_root,
)
from .transactions import (
FLOOR_CALLDATA_COST,
STANDARD_CALLDATA_TOKEN_COST,
TX_ACCESS_LIST_ADDRESS_COST,
TX_ACCESS_LIST_STORAGE_KEY_COST,
TX_BASE_COST,
TX_CREATE_COST,
STANDARD_CALLDATA_TOKEN_COST,
FLOOR_CALLDATA_COST,
AccessListTransaction,
BlobTransaction,
FeeMarketTransaction,
Expand Down Expand Up @@ -922,11 +922,11 @@ def process_transaction(
effective_gas_fee = tx.gas * env.gas_price

intrinsic_gas, tokens_in_calldata = calculate_intrinsic_cost(tx)

floor = Uint(tokens_in_calldata * FLOOR_CALLDATA_COST + TX_BASE_COST)
if floor > tx.gas:
raise InvalidBlock

gas = tx.gas - intrinsic_gas
increment_nonce(env.state, sender)

Expand Down Expand Up @@ -970,17 +970,18 @@ def process_transaction(

output = process_message_call(message, env)

# For EIP-7623 gas_used includes the intrinsic costs with the floor price for calldata
# For EIP-7623 gas_used includes the intrinsic costs with the floor price
# for calldata.
gas_used = tx.gas - output.gas_left

# EIP-7623 floor price (note: no EVM costs)

# Transactions with less gas used than the floor pay at the floor cost.
if gas_used < floor:
gas_used = floor

output.gas_left = tx.gas - gas_used

gas_refund = min(gas_used // 5, output.refund_counter)
gas_refund_amount = (output.gas_left + gas_refund) * env.gas_price

Expand Down Expand Up @@ -1044,13 +1045,13 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]:
"""
data_cost = 0

zerobytes = 0
zero_bytes = 0
for byte in tx.data:
if byte == 0:
zerobytes += 1
zero_bytes += 1

tokens_in_calldata = zero_bytes + (len(tx.data) - zero_bytes) * 4

tokens_in_calldata = zerobytes + (len(tx.data) - zerobytes) * 4

data_cost = tokens_in_calldata * STANDARD_CALLDATA_TOKEN_COST

if tx.to == Bytes0(b""):
Expand All @@ -1076,9 +1077,17 @@ def calculate_intrinsic_cost(tx: Transaction) -> Tuple[Uint, Uint]:
if isinstance(tx, SetCodeTransaction):
auth_cost += PER_EMPTY_ACCOUNT_COST * len(tx.authorizations)

return Uint(TX_BASE_COST +
data_cost +
create_cost + access_list_cost + auth_cost), tokens_in_calldata
return (
Uint(
TX_BASE_COST
+ data_cost
+ create_cost
+ access_list_cost
+ auth_cost
),
Uint(tokens_in_calldata),
)


def recover_sender(chain_id: U64, tx: Transaction) -> Address:
"""
Expand Down
4 changes: 3 additions & 1 deletion whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ Bytes64
Bytes8
Bytes256
Bytes0
calldata
copyreg
copytree
coinbase
coincurve
crypto
E501
EIP
encodings
endian
eth
Expand Down Expand Up @@ -459,4 +461,4 @@ exponentiate
monomial
impl

eoa
eoa

0 comments on commit a6f5239

Please sign in to comment.