Skip to content

Commit 6725668

Browse files
committed
move 7702 related code to single file
1 parent 6f757b0 commit 6725668

File tree

14 files changed

+44
-49
lines changed

14 files changed

+44
-49
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/execution/executor/src/executive/fresh_executive.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ use cfx_parameters::staking::DRIPS_PER_STORAGE_COLLATERAL_UNIT;
1212

1313
use cfx_statedb::Result as DbResult;
1414
use cfx_types::{Address, AddressSpaceUtil, Space, U256, U512};
15-
use cfx_vm_types::extract_7702_payload;
16-
use primitives::{transaction::Action, SignedTransaction, Transaction};
15+
use primitives::{
16+
extract_7702_payload, transaction::Action, SignedTransaction, Transaction,
17+
};
1718

1819
macro_rules! early_return_on_err {
1920
($e:expr) => {

crates/execution/executor/src/executive/pre_checked_executive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ use cfx_types::{
2828
};
2929
use primitives::{
3030
transaction::Action, AuthorizationListItem, SignedTransaction,
31+
CODE_PREFIX_7702,
3132
};
3233
use std::{convert::TryInto, sync::Arc};
33-
use vm::CODE_PREFIX_7702;
3434

3535
pub(super) struct PreCheckedExecutive<'a, O: ExecutiveObserver> {
3636
pub context: ExecutiveContext<'a>,

crates/execution/executor/src/state/overlay_account/basic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use cfx_bytes::Bytes;
22
use cfx_types::{Address, AddressWithSpace, H256, U256};
3-
use cfx_vm_types::CODE_PREFIX_7702;
43
use keccak_hash::{keccak, KECCAK_EMPTY};
5-
use primitives::{storage::STORAGE_LAYOUT_REGULAR_V0, CodeInfo};
4+
use primitives::{
5+
storage::STORAGE_LAYOUT_REGULAR_V0, CodeInfo, CODE_PREFIX_7702,
6+
};
67
use std::sync::Arc;
78

89
use super::OverlayAccount;

crates/execution/executor/src/state/state_object/basic_fields.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use cfx_types::{
66
address_util::AddressUtil, Address, AddressSpaceUtil, AddressWithSpace,
77
Space, H256, U256,
88
};
9-
use cfx_vm_types::extract_7702_payload;
109
use keccak_hash::KECCAK_EMPTY;
10+
use primitives::extract_7702_payload;
1111
#[cfg(test)]
1212
use primitives::StorageLayout;
1313
use std::sync::Arc;

crates/execution/vm-interpreter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ malloc_size_of = { workspace = true }
1818
memory-cache = { workspace = true }
1919
parking_lot = { workspace = true }
2020
rustc-hex = { workspace = true }
21+
primitives = { workspace = true }
2122

2223
[dev-dependencies]
2324
cfx-vm-types = { workspace = true, features = ["testonly_code"] }

crates/execution/vm-interpreter/src/interpreter/gasometer.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
// Conflux is free software and distributed under GNU General Public License.
1919
// See http://www.gnu.org/licenses/
2020

21-
use cfx_types::{Address, Space, H256, U256};
21+
use cfx_types::{Space, H256, U256};
2222
use cfx_vm_types::{self as vm, Spec};
23-
use std::{cmp, sync::Arc};
24-
use vm::{BlockHashSource, CODE_PREFIX_7702};
23+
use primitives::extract_7702_payload;
24+
use std::cmp;
25+
use vm::BlockHashSource;
2526

2627
use super::{
2728
instructions::{self, Instruction, InstructionInfo},
@@ -625,7 +626,9 @@ fn calc_call_gas<Gas: CostType>(
625626
return Ok(call_gas);
626627
}
627628

628-
let Some(delegated_address) = delegated_address(context.extcode(&address)?)
629+
let maybe_code = context.extcode(&address)?;
630+
let Some(delegated_address) =
631+
maybe_code.map(|code| extract_7702_payload(&code)).flatten()
629632
else {
630633
return Ok(call_gas);
631634
};
@@ -638,21 +641,6 @@ fn calc_call_gas<Gas: CostType>(
638641
})
639642
}
640643

641-
fn delegated_address(extcode: Option<Arc<Vec<u8>>>) -> Option<Address> {
642-
let code = extcode?;
643-
if !code.starts_with(CODE_PREFIX_7702) {
644-
return None;
645-
}
646-
647-
let (_prefix, payload) = code.split_at(CODE_PREFIX_7702.len());
648-
649-
if payload.len() == Address::len_bytes() {
650-
Some(Address::from_slice(payload))
651-
} else {
652-
None
653-
}
654-
}
655-
656644
#[test]
657645
fn test_mem_gas_cost() {
658646
// given

crates/execution/vm-types/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ pub use self::{
2929
instruction_result::InstructionResult,
3030
interpreter_info::InterpreterInfo,
3131
return_data::{GasLeft, ReturnData},
32-
spec::{
33-
extract_7702_payload, CIP645Spec, ConsensusGasSpec, Spec,
34-
CODE_PREFIX_7702,
35-
},
32+
spec::{CIP645Spec, ConsensusGasSpec, Spec},
3633
};
3734

3835
/// Virtual Machine interface

crates/execution/vm-types/src/spec.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
use cfx_types::{address_util::AddressUtil, Address};
2323
use primitives::{block::BlockHeight, BlockNumber};
2424

25-
pub const CODE_PREFIX_7702: &'static [u8] = b"\xef\x01\x00";
26-
2725
/// Definition of the cost spec and other parameterisations for the VM.
2826
#[derive(Debug, Clone)]
2927
pub struct Spec {
@@ -506,16 +504,3 @@ impl ConsensusGasSpec {
506504
impl Default for Spec {
507505
fn default() -> Self { Spec::new_spec_for_test() }
508506
}
509-
510-
pub fn extract_7702_payload(code: &[u8]) -> Option<Address> {
511-
if code.starts_with(CODE_PREFIX_7702) {
512-
let (_prefix, payload) = code.split_at(CODE_PREFIX_7702.len());
513-
if payload.len() == Address::len_bytes() {
514-
Some(Address::from_slice(payload))
515-
} else {
516-
None
517-
}
518-
} else {
519-
None
520-
}
521-
}

crates/primitives/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ pub use crate::{
4242
},
4343
storage_key::*,
4444
transaction::{
45-
AccessList, AccessListItem, Action, AuthorizationList,
46-
AuthorizationListItem, SignedTransaction, Transaction,
47-
TransactionWithSignature, TransactionWithSignatureSerializePart,
48-
TxPropagateId, AUTH_MAGIC,
45+
extract_7702_payload, AccessList, AccessListItem, Action,
46+
AuthorizationList, AuthorizationListItem, SignedTransaction,
47+
Transaction, TransactionWithSignature,
48+
TransactionWithSignatureSerializePart, TxPropagateId, AUTH_MAGIC,
49+
CODE_PREFIX_7702,
4950
},
5051
transaction_index::TransactionIndex,
5152
zero::Zero,

0 commit comments

Comments
 (0)