@@ -8,7 +8,7 @@ use crate::{
8
8
db:: Database ,
9
9
eip7702, Account , Bytecode , EVMError , Env , Spec ,
10
10
SpecId :: { CANCUN , PRAGUE , SHANGHAI } ,
11
- TxKind , BLOCKHASH_STORAGE_ADDRESS , U256 ,
11
+ TxKind , BLOCKHASH_STORAGE_ADDRESS , KECCAK_EMPTY , U256 ,
12
12
} ,
13
13
Context , ContextPrecompiles ,
14
14
} ;
@@ -114,51 +114,63 @@ pub fn apply_eip7702_auth_list<SPEC: Spec, EXT, DB: Database>(
114
114
115
115
let mut refunded_accounts = 0 ;
116
116
for authorization in authorization_list. recovered_iter ( ) {
117
- // 1. recover authority and authorized addresses.
118
- // authority = ecrecover(keccak(MAGIC || rlp([chain_id, address, nonce])), y_parity, r, s]
119
- let Some ( authority) = authorization. authority ( ) else {
120
- continue ;
121
- } ;
122
-
123
- // 2. Verify the chain id is either 0 or the chain's current ID.
117
+ // 1. Verify the chain id is either 0 or the chain's current ID.
124
118
if !authorization. chain_id ( ) . is_zero ( )
125
119
&& authorization. chain_id ( ) != U256 :: from ( context. evm . inner . env . cfg . chain_id )
126
120
{
127
121
continue ;
128
122
}
129
123
124
+ // 2. Verify the `nonce` is less than `2**64 - 1`.
125
+ if authorization. nonce ( ) == u64:: MAX {
126
+ continue ;
127
+ }
128
+
129
+ // recover authority and authorized addresses.
130
+ // 3. `authority = ecrecover(keccak(MAGIC || rlp([chain_id, address, nonce])), y_parity, r, s]`
131
+ let Some ( authority) = authorization. authority ( ) else {
132
+ continue ;
133
+ } ;
134
+
130
135
// warm authority account and check nonce.
131
- // 3 . Add authority to accessed_addresses (as defined in EIP-2929.)
136
+ // 4 . Add ` authority` to ` accessed_addresses` (as defined in [ EIP-2929](./eip-2929.md) .)
132
137
let mut authority_acc = context
133
138
. evm
134
139
. inner
135
140
. journaled_state
136
141
. load_code ( authority, & mut context. evm . inner . db ) ?;
137
142
138
- // 4 . Verify the code of authority is either empty or already delegated.
143
+ // 5 . Verify the code of ` authority` is either empty or already delegated.
139
144
if let Some ( bytecode) = & authority_acc. info . code {
140
145
// if it is not empty and it is not eip7702
141
146
if !bytecode. is_empty ( ) && !bytecode. is_eip7702 ( ) {
142
147
continue ;
143
148
}
144
149
}
145
150
146
- // 5 . Verify the nonce of authority is equal to nonce.
151
+ // 6 . Verify the nonce of ` authority` is equal to ` nonce`. In case `authority` does not exist in the trie, verify that `nonce` is equal to `0` .
147
152
if authorization. nonce ( ) != authority_acc. info . nonce {
148
153
continue ;
149
154
}
150
155
151
- // 6. Refund the sender PER_EMPTY_ACCOUNT_COST - PER_AUTH_BASE_COST gas if authority exists in the trie.
156
+ // 7. Add ` PER_EMPTY_ACCOUNT_COST - PER_AUTH_BASE_COST` gas to the global refund counter if ` authority` exists in the trie.
152
157
if !authority_acc. is_empty ( ) {
153
158
refunded_accounts += 1 ;
154
159
}
155
160
156
- // 7. Set the code of authority to be 0xef0100 || address. This is a delegation designation.
157
- let bytecode = Bytecode :: new_eip7702 ( authorization. address ) ;
158
- authority_acc. info . code_hash = bytecode. hash_slow ( ) ;
161
+ // 8. Set the code of `authority` to be `0xef0100 || address`. This is a delegation designation.
162
+ // * As a special case, if `address` is `0x0000000000000000000000000000000000000000` do not write the designation. Clear the accounts code and reset the account's code hash to the empty hash `0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470`.
163
+ let ( bytecode, hash) = if authorization. address . is_zero ( ) {
164
+ ( Bytecode :: default ( ) , KECCAK_EMPTY )
165
+ } else {
166
+ let bytecode = Bytecode :: new_eip7702 ( authorization. address ) ;
167
+ let hash = bytecode. hash_slow ( ) ;
168
+ ( bytecode, hash)
169
+ } ;
170
+ authority_acc. info . code_hash = hash;
159
171
authority_acc. info . code = Some ( bytecode) ;
160
172
161
- // 8 . Increase the nonce of authority by one.
173
+ // 9 . Increase the nonce of ` authority` by one.
162
174
authority_acc. info . nonce = authority_acc. info . nonce . saturating_add ( 1 ) ;
163
175
authority_acc. mark_touch ( ) ;
164
176
}
0 commit comments