Skip to content

Commit 750cfbd

Browse files
committed
feat: add integration test for EIP-7702 authorization overflow scenarios
1 parent 80df39c commit 750cfbd

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import pytest
2+
from eth_account.signers.local import LocalAccount
3+
from web3 import Web3
4+
from web3.exceptions import Web3RPCError
5+
6+
from ethereum_test_tools import (
7+
Initcode,
8+
Opcodes as Op,
9+
Storage,
10+
Bytecode,
11+
Macros as Om,
12+
)
13+
from web3.types import RPCEndpoint
14+
15+
MAX_AUTH_CHAIN_ID = 2 ** 256 - 1
16+
MAX_AUTH_NONCE = 2 ** 64 - 1
17+
18+
@pytest.fixture(scope="module")
19+
def contract_address(ew3: Web3) -> str:
20+
return ew3.eth.account.create().address
21+
22+
23+
def get_new_fund_account(ew3: Web3) -> LocalAccount:
24+
new_account = ew3.eth.account.create()
25+
tx_hash = ew3.eth.send_transaction(
26+
{
27+
"to": new_account.address,
28+
"value": ew3.to_wei(1, "ether"),
29+
}
30+
)
31+
ew3.eth.wait_for_transaction_receipt(tx_hash)
32+
return new_account
33+
34+
@pytest.mark.parametrize("auth_chain_id, auth_nonce, should_overflow", [
35+
(MAX_AUTH_CHAIN_ID, MAX_AUTH_NONCE, False),
36+
(MAX_AUTH_CHAIN_ID+1, MAX_AUTH_NONCE, True),
37+
(MAX_AUTH_CHAIN_ID, MAX_AUTH_NONCE+1, True),
38+
])
39+
def test_auth_overflow_chain_id(ew3: Web3, contract_address: str, auth_chain_id: int, auth_nonce: int, should_overflow: bool):
40+
acct = get_new_fund_account(ew3)
41+
nonce = ew3.eth.get_transaction_count(acct.address)
42+
auth = ew3.eth.account.sign_authorization({
43+
"chainId": auth_chain_id,
44+
"address": contract_address,
45+
"nonce": auth_nonce,
46+
}, acct.key)
47+
raw_tx = acct.sign_transaction({
48+
"to": ew3.eth.account.create().address,
49+
"chainId": ew3.eth.chain_id,
50+
"nonce": nonce,
51+
"maxFeePerGas": ew3.to_wei(1, "gwei"),
52+
"maxPriorityFeePerGas": ew3.to_wei(1, "gwei"),
53+
"gas": 200000,
54+
"authorizationList": [auth]
55+
})
56+
if should_overflow:
57+
with pytest.raises(Web3RPCError) as e:
58+
ew3.eth.send_raw_transaction(raw_tx.raw_transaction)
59+
assert e.value.message == "{'code': -32602, 'message': 'failed to decode signed transaction'}"
60+
else:
61+
tx_hash = ew3.eth.send_raw_transaction(raw_tx.raw_transaction)
62+
ew3.eth.wait_for_transaction_receipt(tx_hash)

0 commit comments

Comments
 (0)