diff --git a/Dockerfile b/Dockerfile index 2c55203175..df963690d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,8 +16,8 @@ WORKDIR /opt/evm_loader ARG REVISION ENV NEON_REVISION=${REVISION} RUN cargo fmt --check && \ - cargo clippy --no-default-features --release && \ - cargo build --no-default-features --release && \ + cargo clippy --release && \ + cargo build --release && \ cargo build-bpf --features devnet && cp target/deploy/evm_loader.so target/deploy/evm_loader-devnet.so && \ cargo build-bpf --features testnet && cp target/deploy/evm_loader.so target/deploy/evm_loader-testnet.so && \ cargo build-bpf --features govertest && cp target/deploy/evm_loader.so target/deploy/evm_loader-govertest.so && \ diff --git a/evm_loader/lib/Cargo.toml b/evm_loader/lib/Cargo.toml index 61f699f71b..79a2a50157 100644 --- a/evm_loader/lib/Cargo.toml +++ b/evm_loader/lib/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" thiserror = "1.0" anyhow = "1.0" bincode = "1.3.1" -evm-loader = { path = "../program", default-features = false, features = ["log", "library"] } +evm-loader = { path = "../program", default-features = false, features = ["log", "async-trait", "serde_json"] } solana-sdk = "=1.16.14" solana-client = "=1.16.14" solana-clap-utils = "=1.16.14" diff --git a/evm_loader/program/Cargo.toml b/evm_loader/program/Cargo.toml index 7e68302c15..f1fab8ba7b 100644 --- a/evm_loader/program/Cargo.toml +++ b/evm_loader/program/Cargo.toml @@ -32,9 +32,7 @@ emergency = [] no-entrypoint = [] test-bpf = [] custom-heap = [] -default = ["custom-heap", "maybe-async/is_sync"] - -library = ["serde_json", "maybe-async", "async-trait"] +default = ["custom-heap"] [dependencies] linked_list_allocator = { version = "0.10", default-features = false } @@ -58,9 +56,13 @@ ethnum = { version = "1.4", default-features = false, features = ["serde"] } const_format = { version = "0.2.21" } cfg-if = { version = "1.0" } log = { version = "0.4", default-features = false, optional = true } -maybe-async = { version = "0.2.7", optional = true } +maybe-async = "0.2.7" async-trait = { version = "0.1.73", optional = true } +[target.'cfg(target_os = "solana")'.dependencies.maybe-async] +version = "0.2.7" +features = ["is_sync"] + [lib] crate-type = ["cdylib", "lib"] diff --git a/evm_loader/program/src/account_storage/mod.rs b/evm_loader/program/src/account_storage/mod.rs index 2b2a389573..27e8c39781 100644 --- a/evm_loader/program/src/account_storage/mod.rs +++ b/evm_loader/program/src/account_storage/mod.rs @@ -4,7 +4,7 @@ use crate::types::Address; use ethnum::U256; use maybe_async::maybe_async; use solana_program::account_info::AccountInfo; -#[cfg(not(feature = "library"))] +#[cfg(target_os = "solana")] use { crate::account::EthereumStorage, solana_program::clock::Clock, std::cell::RefCell, std::collections::HashSet, @@ -15,11 +15,11 @@ use solana_program::slot_history::Slot; use std::cmp::Ordering; use std::collections::HashMap; -#[cfg(not(feature = "library"))] +#[cfg(target_os = "solana")] mod apply; -#[cfg(not(feature = "library"))] +#[cfg(target_os = "solana")] mod backend; -#[cfg(not(feature = "library"))] +#[cfg(target_os = "solana")] mod base; #[derive(Debug)] @@ -37,7 +37,7 @@ pub enum AccountsReadiness { NeedMoreReallocations, } -#[cfg(not(feature = "library"))] +#[cfg(target_os = "solana")] pub struct ProgramAccountStorage<'a> { program_id: &'a Pubkey, operator: &'a Pubkey, diff --git a/evm_loader/program/src/evm/memory.rs b/evm_loader/program/src/evm/memory.rs index 325c367dfd..2ccb671fe7 100644 --- a/evm_loader/program/src/evm/memory.rs +++ b/evm_loader/program/src/evm/memory.rs @@ -4,7 +4,7 @@ use std::ops::Range; use solana_program::program_memory::{sol_memcpy, sol_memset}; use crate::error::Error; -#[cfg(feature = "library")] +#[cfg(not(target_os = "solana"))] use crate::evm::tracing::TracerTypeOpt; use super::utils::checked_next_multiple_of_32; @@ -20,22 +20,22 @@ pub struct Memory { data: *mut u8, capacity: usize, size: usize, - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt, } impl Memory { - pub fn new(#[cfg(feature = "library")] tracer: TracerTypeOpt) -> Self { + pub fn new(#[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt) -> Self { Self::with_capacity( MEMORY_CAPACITY, - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer, ) } pub fn with_capacity( capacity: usize, - #[cfg(feature = "library")] tracer: TracerTypeOpt, + #[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt, ) -> Self { unsafe { let layout = Layout::from_size_align_unchecked(capacity, MEMORY_ALIGN); @@ -48,7 +48,7 @@ impl Memory { data, capacity, size: 0, - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer, } } @@ -70,13 +70,13 @@ impl Memory { data, capacity, size: v.len(), - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer: None, } } } - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] pub fn to_vec(&self) -> Vec { let slice = unsafe { std::slice::from_raw_parts(self.data, self.size) }; slice.to_vec() diff --git a/evm_loader/program/src/evm/mod.rs b/evm_loader/program/src/evm/mod.rs index 9014f12a3d..9e270e81bd 100644 --- a/evm_loader/program/src/evm/mod.rs +++ b/evm_loader/program/src/evm/mod.rs @@ -11,7 +11,7 @@ use solana_program::log::sol_log_data; pub use buffer::Buffer; -#[cfg(feature = "library")] +#[cfg(not(target_os = "solana"))] use crate::evm::tracing::TracerTypeOpt; use crate::{ error::{build_revert_message, Error, Result}, @@ -28,19 +28,19 @@ mod opcode; mod opcode_table; mod precompile; mod stack; -#[cfg(feature = "library")] +#[cfg(not(target_os = "solana"))] pub mod tracing; mod utils; macro_rules! tracing_event { ($self:ident, $x:expr) => { - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] if let Some(tracer) = &$self.tracer { tracer.borrow_mut().event($x); } }; ($self:ident, $condition:expr, $x:expr) => { - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] if let Some(tracer) = &$self.tracer { if $condition { tracer.borrow_mut().event($x); @@ -51,7 +51,7 @@ macro_rules! tracing_event { macro_rules! trace_end_step { ($self:ident, $return_data:expr) => { - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] if let Some(tracer) = &$self.tracer { tracer .borrow_mut() @@ -62,7 +62,7 @@ macro_rules! trace_end_step { } }; ($self:ident, $condition:expr; $return_data_getter:expr) => { - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] if $condition { trace_end_step!($self, $return_data_getter) } @@ -153,7 +153,7 @@ pub struct Machine { #[serde(skip)] phantom: PhantomData<*const B>, - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] #[serde(skip)] tracer: TracerTypeOpt, } @@ -167,7 +167,7 @@ impl Machine { cursor.position().try_into().map_err(Error::from) } - #[cfg(not(feature = "library"))] + #[cfg(target_os = "solana")] pub fn deserialize_from(buffer: &[u8], backend: &B) -> Result { fn reinit_buffer(buffer: &mut Buffer, backend: &B) { if let Some((key, range)) = buffer.uninit_data() { @@ -200,7 +200,7 @@ impl Machine { trx: &mut Transaction, origin: Address, backend: &mut B, - #[cfg(feature = "library")] tracer: TracerTypeOpt, + #[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt, ) -> Result { let origin_nonce = backend.nonce(&origin).await?; @@ -235,7 +235,7 @@ impl Machine { trx, origin, backend, - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer, ) .await @@ -244,7 +244,7 @@ impl Machine { trx, origin, backend, - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer, ) .await @@ -256,7 +256,7 @@ impl Machine { trx: &mut Transaction, origin: Address, backend: &mut B, - #[cfg(feature = "library")] tracer: TracerTypeOpt, + #[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt, ) -> Result { assert!(trx.target().is_some()); @@ -285,11 +285,11 @@ impl Machine { return_data: Buffer::empty(), return_range: 0..0, stack: Stack::new( - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer.clone(), ), memory: Memory::new( - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer.clone(), ), pc: 0_usize, @@ -297,7 +297,7 @@ impl Machine { reason: Reason::Call, parent: None, phantom: PhantomData, - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer, }) } @@ -307,7 +307,7 @@ impl Machine { trx: &mut Transaction, origin: Address, backend: &mut B, - #[cfg(feature = "library")] tracer: TracerTypeOpt, + #[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt, ) -> Result { assert!(trx.target().is_none()); @@ -337,11 +337,11 @@ impl Machine { return_data: Buffer::empty(), return_range: 0..0, stack: Stack::new( - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer.clone(), ), memory: Memory::new( - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer.clone(), ), pc: 0_usize, @@ -351,7 +351,7 @@ impl Machine { call_data: Buffer::empty(), parent: None, phantom: PhantomData, - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer, }) } @@ -450,11 +450,11 @@ impl Machine { return_data: Buffer::empty(), return_range: 0..0, stack: Stack::new( - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] self.tracer.clone(), ), memory: Memory::new( - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] self.tracer.clone(), ), pc: 0_usize, @@ -462,7 +462,7 @@ impl Machine { reason, parent: None, phantom: PhantomData, - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer: self.tracer.clone(), }; diff --git a/evm_loader/program/src/evm/opcode_table.rs b/evm_loader/program/src/evm/opcode_table.rs index d30045e4f9..cc169efc2b 100644 --- a/evm_loader/program/src/evm/opcode_table.rs +++ b/evm_loader/program/src/evm/opcode_table.rs @@ -4,10 +4,10 @@ use super::{database::Database, opcode::Action, Machine}; macro_rules! opcode_table { ($( $opcode:literal, $opname:literal, $op:path;)*) => { - #[cfg(not(feature = "library"))] + #[cfg(target_os = "solana")] type OpCode = fn(&mut Machine, &mut B) -> Result; - #[cfg(not(feature = "library"))] + #[cfg(target_os = "solana")] impl Machine { const OPCODES: [OpCode; 256] = { let mut opcodes: [OpCode; 256] = [Self::opcode_unknown; 256]; @@ -24,7 +24,7 @@ macro_rules! opcode_table { } } - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] impl Machine { pub async fn execute_opcode(&mut self, backend: &mut B, opcode: u8) -> Result { match opcode { @@ -34,7 +34,7 @@ macro_rules! opcode_table { } } - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] pub const OPNAMES: [&str; 256] = { let mut opnames: [&str; 256] = [""; 256]; diff --git a/evm_loader/program/src/evm/stack.rs b/evm_loader/program/src/evm/stack.rs index 4906550ff6..9470e0fd09 100644 --- a/evm_loader/program/src/evm/stack.rs +++ b/evm_loader/program/src/evm/stack.rs @@ -7,7 +7,7 @@ use std::{ use ethnum::{I256, U256}; -#[cfg(feature = "library")] +#[cfg(not(target_os = "solana"))] use crate::evm::TracerTypeOpt; use crate::{error::Error, types::Address}; @@ -20,12 +20,12 @@ pub struct Stack { begin: *mut u8, end: *mut u8, top: *mut u8, - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt, } impl Stack { - pub fn new(#[cfg(feature = "library")] tracer: TracerTypeOpt) -> Self { + pub fn new(#[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt) -> Self { let (begin, end) = unsafe { let layout = Layout::from_size_align_unchecked(STACK_SIZE, ELEMENT_SIZE); let begin = crate::allocator::EVM.alloc(layout); @@ -42,12 +42,12 @@ impl Stack { begin, end, top: begin, - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] tracer, } } - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] pub fn to_vec(&self) -> Vec<[u8; 32]> { let slice = unsafe { let start = self.begin.cast::<[u8; 32]>(); @@ -316,7 +316,7 @@ impl<'de> serde::Deserialize<'de> for Stack { } let mut stack = Stack::new( - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] None, ); unsafe { diff --git a/evm_loader/program/src/executor/action.rs b/evm_loader/program/src/executor/action.rs index 360883bccb..83af0d2216 100644 --- a/evm_loader/program/src/executor/action.rs +++ b/evm_loader/program/src/executor/action.rs @@ -110,7 +110,7 @@ mod tests { let _deserialized: Action = bincode::deserialize(&serialized).unwrap(); } - #[cfg(feature = "library")] + #[cfg(not(target_os = "solana"))] #[test] fn roundtrip_json() { let action = Action::EvmSetStorage { diff --git a/evm_loader/program/src/lib.rs b/evm_loader/program/src/lib.rs index 01cc43485c..005757f81f 100644 --- a/evm_loader/program/src/lib.rs +++ b/evm_loader/program/src/lib.rs @@ -19,13 +19,13 @@ pub mod error; pub mod account; pub mod account_storage; pub mod config; -#[cfg(not(feature = "library"))] +#[cfg(target_os = "solana")] pub mod entrypoint; pub mod evm; pub mod executor; pub mod external_programs; pub mod gasometer; -#[cfg(not(feature = "library"))] +#[cfg(target_os = "solana")] pub mod instruction; pub mod state_account; pub mod types; diff --git a/evm_loader/program/src/state_account.rs b/evm_loader/program/src/state_account.rs index 3b8b44a25b..7e4c520c7a 100644 --- a/evm_loader/program/src/state_account.rs +++ b/evm_loader/program/src/state_account.rs @@ -1,4 +1,4 @@ -#[cfg(not(feature = "library"))] +#[cfg(target_os = "solana")] use { crate::account::program, crate::types::{Address, Transaction}, @@ -42,7 +42,7 @@ impl<'a> FinalizedState<'a> { } impl<'a> State<'a> { - #[cfg(not(feature = "library"))] + #[cfg(target_os = "solana")] pub fn new( program_id: &'a Pubkey, info: &'a AccountInfo<'a>, @@ -145,7 +145,7 @@ impl<'a> State<'a> { Ok(finalized) } - #[cfg(not(feature = "library"))] + #[cfg(target_os = "solana")] fn make_deposit( &self, system_program: &program::System<'a>, @@ -196,7 +196,7 @@ impl<'a> State<'a> { Ok(accounts) } - #[cfg(not(feature = "library"))] + #[cfg(target_os = "solana")] fn write_blocked_accounts( &mut self, program_id: &Pubkey, diff --git a/evm_loader/program/src/types/mod.rs b/evm_loader/program/src/types/mod.rs index 05ffd3d0df..06000d18fb 100644 --- a/evm_loader/program/src/types/mod.rs +++ b/evm_loader/program/src/types/mod.rs @@ -6,6 +6,6 @@ pub use transaction::Transaction; pub use transaction::TransactionPayload; mod address; -#[cfg(feature = "library")] +#[cfg(not(target_os = "solana"))] pub mod hexbytes; mod transaction; diff --git a/evm_loader/program/src/types/transaction.rs b/evm_loader/program/src/types/transaction.rs index 2c3f82172c..b6d1e202f8 100644 --- a/evm_loader/program/src/types/transaction.rs +++ b/evm_loader/program/src/types/transaction.rs @@ -20,7 +20,7 @@ impl rlp::Decodable for StorageKey { } } -#[cfg(feature = "library")] +#[cfg(not(target_os = "solana"))] impl TryFrom for StorageKey { type Error = String;