Skip to content

Commit

Permalink
eth/tx: only enforce block gas limit on mainnet (#299)
Browse files Browse the repository at this point in the history
* eth/tx: only enforce block gas limit on mainnet

* eth/tx: only enforce block gas limit on mainnet
  • Loading branch information
q9f authored Dec 17, 2024
1 parent d6e5177 commit 33fbd3b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/eth/tx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ def validate_params(fields)
if fields[:nonce].nil? or fields[:nonce] < 0
raise ParameterError, "Invalid signer nonce #{fields[:nonce]}!"
end
if fields[:gas_limit].nil? or fields[:gas_limit] < DEFAULT_GAS_LIMIT or fields[:gas_limit] > BLOCK_GAS_LIMIT
if fields[:gas_limit].nil? or
fields[:gas_limit] < DEFAULT_GAS_LIMIT or
(fields[:gas_limit] > BLOCK_GAS_LIMIT and fields[:chain_id] == Chain::ETHEREUM)
raise ParameterError, "Invalid gas limit #{fields[:gas_limit]}!"
end
unless fields[:value] >= 0
Expand Down
1 change: 1 addition & 0 deletions spec/eth/tx/eip1559_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
priority_fee: 0,
max_gas_fee: Unit::GWEI,
gas_limit: Tx::BLOCK_GAS_LIMIT + 1,
chain_id: Chain::ETHEREUM,
})
}.to raise_error Tx::ParameterError, "Invalid gas limit 30000001!"
expect {
Expand Down
1 change: 1 addition & 0 deletions spec/eth/tx/eip2930_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
nonce: 0,
gas_price: Unit::GWEI,
gas_limit: Tx::BLOCK_GAS_LIMIT + 1,
chain_id: Chain::ETHEREUM,
})
}.to raise_error Tx::ParameterError, "Invalid gas limit 30000001!"
expect {
Expand Down
9 changes: 9 additions & 0 deletions spec/eth/tx/legacy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,17 @@
nonce: 0,
gas_price: Unit::GWEI,
gas_limit: Tx::BLOCK_GAS_LIMIT + 1,
chain_id: Chain::ETHEREUM,
})
}.to raise_error Tx::ParameterError, "Invalid gas limit 30000001!"
expect {
Tx.new({
nonce: 0,
gas_price: Unit::GWEI,
gas_limit: Tx::BLOCK_GAS_LIMIT + 1,
chain_id: Chain::OPTIMISM,
})
}.not_to raise_error # Block gas limit is only enforced in Ethereum mainnet
expect {
Tx.new({
nonce: -1,
Expand Down

0 comments on commit 33fbd3b

Please sign in to comment.