Skip to content

Commit 02fff86

Browse files
committed
fix: 🐛 fix usage of authorization list throughout the codebase
1 parent 464cad8 commit 02fff86

File tree

10 files changed

+206
-19
lines changed

10 files changed

+206
-19
lines changed

client/rpc/src/eth/execute.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ where
9393
data,
9494
nonce,
9595
access_list,
96+
authorization_list,
9697
..
9798
} = request;
9899

@@ -387,6 +388,37 @@ where
387388
} else if api_version == 5 {
388389
// Post-london + access list support
389390
let access_list = access_list.unwrap_or_default();
391+
let info = api
392+
.create_before_version_6(
393+
substrate_hash,
394+
from.unwrap_or_default(),
395+
data,
396+
value.unwrap_or_default(),
397+
gas_limit,
398+
max_fee_per_gas,
399+
max_priority_fee_per_gas,
400+
nonce,
401+
false,
402+
Some(
403+
access_list
404+
.into_iter()
405+
.map(|item| (item.address, item.storage_keys))
406+
.collect(),
407+
),
408+
)
409+
.map_err(|err| internal_err(format!("runtime error: {err}")))?
410+
.map_err(|err| internal_err(format!("execution fatal: {err:?}")))?;
411+
412+
error_on_execution_failure(&info.exit_reason, &[])?;
413+
414+
let code = api
415+
.account_code_at(substrate_hash, info.value)
416+
.map_err(|err| internal_err(format!("runtime error: {err}")))?;
417+
Ok(Bytes(code))
418+
} else if api_version == 6 {
419+
// Pectra EIP-7702 support
420+
let access_list = access_list.unwrap_or_default();
421+
let authorization_list = authorization_list.unwrap_or_default();
390422
let info = api
391423
.create(
392424
substrate_hash,
@@ -404,6 +436,19 @@ where
404436
.map(|item| (item.address, item.storage_keys))
405437
.collect(),
406438
),
439+
Some(
440+
authorization_list
441+
.iter()
442+
.map(|d| {
443+
(
444+
U256::from(d.chain_id),
445+
d.address,
446+
d.nonce,
447+
d.authorizing_address(),
448+
)
449+
})
450+
.collect(),
451+
),
407452
)
408453
.map_err(|err| internal_err(format!("runtime error: {err}")))?
409454
.map_err(|err| internal_err(format!("execution fatal: {err:?}")))?;

frame/ethereum/src/lib.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,7 @@ impl<T: Config> Pallet<T> {
461461
Receipt::Legacy(d) | Receipt::EIP2930(d) | Receipt::EIP1559(d) => {
462462
(d.logs.clone(), d.used_gas)
463463
}
464-
Receipt::EIP7702(d) => {
465-
(d.logs.clone(), d.used_gas)
466-
}
464+
Receipt::EIP7702(d) => (d.logs.clone(), d.used_gas),
467465
};
468466
cumulative_gas_used = used_gas;
469467
Self::logs_bloom(logs, &mut logs_bloom);
@@ -695,9 +693,10 @@ impl<T: Config> Pallet<T> {
695693
Pending::<T>::get(transaction_index.saturating_sub(1))
696694
{
697695
match receipt {
698-
Receipt::Legacy(d) | Receipt::EIP2930(d) | Receipt::EIP1559(d) => {
699-
d.used_gas.saturating_add(used_gas.effective)
700-
}
696+
Receipt::Legacy(d)
697+
| Receipt::EIP2930(d)
698+
| Receipt::EIP1559(d)
699+
| Receipt::EIP7702(d) => d.used_gas.saturating_add(used_gas.effective),
701700
}
702701
} else {
703702
used_gas.effective
@@ -788,6 +787,7 @@ impl<T: Config> Pallet<T> {
788787
nonce,
789788
action,
790789
access_list,
790+
authorization_list,
791791
) = {
792792
match transaction {
793793
// max_fee_per_gas and max_priority_fee_per_gas in legacy and 2930 transactions is
@@ -801,6 +801,7 @@ impl<T: Config> Pallet<T> {
801801
Some(t.nonce),
802802
t.action,
803803
Vec::new(),
804+
Vec::new(),
804805
),
805806
Transaction::EIP2930(t) => {
806807
let access_list: Vec<(H160, Vec<H256>)> = t
@@ -817,6 +818,7 @@ impl<T: Config> Pallet<T> {
817818
Some(t.nonce),
818819
t.action,
819820
access_list,
821+
Vec::new(),
820822
)
821823
}
822824
Transaction::EIP1559(t) => {
@@ -834,6 +836,7 @@ impl<T: Config> Pallet<T> {
834836
Some(t.nonce),
835837
t.action,
836838
access_list,
839+
Vec::new(),
837840
)
838841
}
839842
Transaction::EIP7702(t) => {
@@ -842,6 +845,18 @@ impl<T: Config> Pallet<T> {
842845
.iter()
843846
.map(|item| (item.address, item.storage_keys.clone()))
844847
.collect();
848+
let authorization_list: Vec<(U256, H160, U256, H160)> = t
849+
.authorization_list
850+
.iter()
851+
.map(|d| {
852+
(
853+
U256::from(d.chain_id),
854+
d.address,
855+
d.nonce,
856+
d.authorizing_address(),
857+
)
858+
})
859+
.collect();
845860
(
846861
t.data.clone(),
847862
t.value,
@@ -851,6 +866,7 @@ impl<T: Config> Pallet<T> {
851866
Some(t.nonce),
852867
t.destination,
853868
access_list,
869+
authorization_list,
854870
)
855871
}
856872
}
@@ -868,6 +884,7 @@ impl<T: Config> Pallet<T> {
868884
max_priority_fee_per_gas,
869885
nonce,
870886
access_list,
887+
authorization_list,
871888
is_transactional,
872889
validate,
873890
weight_limit,
@@ -898,6 +915,7 @@ impl<T: Config> Pallet<T> {
898915
max_priority_fee_per_gas,
899916
nonce,
900917
access_list,
918+
authorization_list,
901919
is_transactional,
902920
validate,
903921
weight_limit,

frame/evm/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ pub mod pallet {
331331
max_priority_fee_per_gas: Option<U256>,
332332
nonce: Option<U256>,
333333
access_list: Vec<(H160, Vec<H256>)>,
334+
authorization_list: Vec<(U256, H160, U256, H160)>,
334335
) -> DispatchResultWithPostInfo {
335336
T::CallOrigin::ensure_address_origin(&source, origin)?;
336337

@@ -346,6 +347,7 @@ pub mod pallet {
346347
max_priority_fee_per_gas,
347348
nonce,
348349
access_list,
350+
authorization_list,
349351
is_transactional,
350352
validate,
351353
None,
@@ -407,6 +409,7 @@ pub mod pallet {
407409
max_priority_fee_per_gas: Option<U256>,
408410
nonce: Option<U256>,
409411
access_list: Vec<(H160, Vec<H256>)>,
412+
authorization_list: Vec<(U256, H160, U256, H160)>,
410413
) -> DispatchResultWithPostInfo {
411414
T::CallOrigin::ensure_address_origin(&source, origin)?;
412415

@@ -421,6 +424,7 @@ pub mod pallet {
421424
max_priority_fee_per_gas,
422425
nonce,
423426
access_list,
427+
authorization_list,
424428
is_transactional,
425429
validate,
426430
None,
@@ -494,6 +498,7 @@ pub mod pallet {
494498
max_priority_fee_per_gas: Option<U256>,
495499
nonce: Option<U256>,
496500
access_list: Vec<(H160, Vec<H256>)>,
501+
authorization_list: Vec<(U256, H160, U256, H160)>,
497502
) -> DispatchResultWithPostInfo {
498503
T::CallOrigin::ensure_address_origin(&source, origin)?;
499504

@@ -509,6 +514,7 @@ pub mod pallet {
509514
max_priority_fee_per_gas,
510515
nonce,
511516
access_list,
517+
authorization_list,
512518
is_transactional,
513519
validate,
514520
None,

frame/evm/src/runner/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub trait Runner<T: Config> {
4242
max_priority_fee_per_gas: Option<U256>,
4343
nonce: Option<U256>,
4444
access_list: Vec<(H160, Vec<H256>)>,
45+
authorization_list: Vec<(U256, H160, U256, H160)>,
4546
is_transactional: bool,
4647
weight_limit: Option<Weight>,
4748
proof_size_base_cost: Option<u64>,
@@ -58,6 +59,7 @@ pub trait Runner<T: Config> {
5859
max_priority_fee_per_gas: Option<U256>,
5960
nonce: Option<U256>,
6061
access_list: Vec<(H160, Vec<H256>)>,
62+
authorization_list: Vec<(U256, H160, U256, H160)>,
6163
is_transactional: bool,
6264
validate: bool,
6365
weight_limit: Option<Weight>,
@@ -74,6 +76,7 @@ pub trait Runner<T: Config> {
7476
max_priority_fee_per_gas: Option<U256>,
7577
nonce: Option<U256>,
7678
access_list: Vec<(H160, Vec<H256>)>,
79+
authorization_list: Vec<(U256, H160, U256, H160)>,
7780
is_transactional: bool,
7881
validate: bool,
7982
weight_limit: Option<Weight>,
@@ -91,6 +94,7 @@ pub trait Runner<T: Config> {
9194
max_priority_fee_per_gas: Option<U256>,
9295
nonce: Option<U256>,
9396
access_list: Vec<(H160, Vec<H256>)>,
97+
authorization_list: Vec<(U256, H160, U256, H160)>,
9498
is_transactional: bool,
9599
validate: bool,
96100
weight_limit: Option<Weight>,

frame/evm/src/runner/stack.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ where
467467
max_priority_fee_per_gas: Option<U256>,
468468
nonce: Option<U256>,
469469
access_list: Vec<(H160, Vec<H256>)>,
470+
authorization_list: Vec<(U256, H160, U256, H160)>,
470471
is_transactional: bool,
471472
weight_limit: Option<Weight>,
472473
proof_size_base_cost: Option<u64>,
@@ -495,7 +496,7 @@ where
495496
max_priority_fee_per_gas,
496497
value,
497498
access_list,
498-
authorization_list: vec![], // No authorizations for direct EVM calls
499+
authorization_list,
499500
},
500501
weight_limit,
501502
proof_size_base_cost,
@@ -517,6 +518,7 @@ where
517518
max_priority_fee_per_gas: Option<U256>,
518519
nonce: Option<U256>,
519520
access_list: Vec<(H160, Vec<H256>)>,
521+
authorization_list: Vec<(U256, H160, U256, H160)>,
520522
is_transactional: bool,
521523
validate: bool,
522524
weight_limit: Option<Weight>,
@@ -535,6 +537,7 @@ where
535537
max_priority_fee_per_gas,
536538
nonce,
537539
access_list.clone(),
540+
authorization_list.clone(),
538541
is_transactional,
539542
weight_limit,
540543
proof_size_base_cost,
@@ -554,7 +557,17 @@ where
554557
weight_limit,
555558
proof_size_base_cost,
556559
measured_proof_size_before,
557-
|executor| executor.transact_call(source, target, value, input, gas_limit, access_list),
560+
|executor| {
561+
executor.transact_call(
562+
source,
563+
target,
564+
value,
565+
input,
566+
gas_limit,
567+
access_list,
568+
authorization_list,
569+
)
570+
},
558571
)
559572
}
560573

@@ -567,6 +580,7 @@ where
567580
max_priority_fee_per_gas: Option<U256>,
568581
nonce: Option<U256>,
569582
access_list: Vec<(H160, Vec<H256>)>,
583+
authorization_list: Vec<(U256, H160, U256, H160)>,
570584
is_transactional: bool,
571585
validate: bool,
572586
weight_limit: Option<Weight>,
@@ -590,6 +604,7 @@ where
590604
max_priority_fee_per_gas,
591605
nonce,
592606
access_list.clone(),
607+
authorization_list.clone(),
593608
is_transactional,
594609
weight_limit,
595610
proof_size_base_cost,
@@ -612,8 +627,14 @@ where
612627
|executor| {
613628
let address = executor.create_address(evm::CreateScheme::Legacy { caller: source });
614629
T::OnCreate::on_create(source, address);
615-
let (reason, _) =
616-
executor.transact_create(source, value, init, gas_limit, access_list);
630+
let (reason, _) = executor.transact_create(
631+
source,
632+
value,
633+
init,
634+
gas_limit,
635+
access_list,
636+
authorization_list,
637+
);
617638
(reason, address)
618639
},
619640
)
@@ -629,6 +650,7 @@ where
629650
max_priority_fee_per_gas: Option<U256>,
630651
nonce: Option<U256>,
631652
access_list: Vec<(H160, Vec<H256>)>,
653+
authorization_list: Vec<(U256, H160, U256, H160)>,
632654
is_transactional: bool,
633655
validate: bool,
634656
weight_limit: Option<Weight>,
@@ -652,6 +674,7 @@ where
652674
max_priority_fee_per_gas,
653675
nonce,
654676
access_list.clone(),
677+
authorization_list.clone(),
655678
is_transactional,
656679
weight_limit,
657680
proof_size_base_cost,
@@ -679,8 +702,15 @@ where
679702
salt,
680703
});
681704
T::OnCreate::on_create(source, address);
682-
let (reason, _) =
683-
executor.transact_create2(source, value, init, salt, gas_limit, access_list);
705+
let (reason, _) = executor.transact_create2(
706+
source,
707+
value,
708+
init,
709+
salt,
710+
gas_limit,
711+
access_list,
712+
authorization_list,
713+
);
684714
(reason, address)
685715
},
686716
)
@@ -1180,6 +1210,7 @@ where
11801210
.map_err(|_| ExitError::OutOfGas)?;
11811211
}
11821212
}
1213+
ExternalOperation::DelegationResolution(_) => todo!(),
11831214
};
11841215
}
11851216
Ok(())

0 commit comments

Comments
 (0)