Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NDEV-2252: Clean up tracer implementation #208

Merged
merged 5 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions evm_loader/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion evm_loader/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ evm-loader = { path = "../program", default-features = false, features = ["log"]
solana-sdk = "=1.16.15"
solana-client = "=1.16.15"
serde = "1.0.186"
serde_json = "1.0.85"
serde_json = { version = "1.0.107", features = ["preserve_order"] }
ethnum = { version = "1.4", default-features = false, features = ["serde"] }
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion evm_loader/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ solana-clap-utils = "=1.16.15"
solana-cli-config = "=1.16.15"
hex = "0.4.2"
serde = "1.0.186"
serde_json = "1.0.85"
serde_json = { version = "1.0.107", features = ["preserve_order"] }
log = "0.4.17"
fern = "0.6"
ethnum = { version = "1.4", default-features = false, features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion evm_loader/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spl-associated-token-account = { version = "~1.1", default-features = false, fea
bs58 = "0.4.0"
hex = "0.4.2"
serde = "1.0.186"
serde_json = "1.0.105"
serde_json = { version = "1.0.107", features = ["preserve_order"] }
log = "0.4.17"
rand = "0.8"
ethnum = { version = "1.4", default-features = false, features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion evm_loader/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ borsh = "0.9"
bincode = "1"
serde_bytes = "0.11.12"
serde = { version = "1.0.186", default-features = false, features = ["derive", "rc"] }
serde_json = { version = "1.0.105", optional = true }
serde_json = { version = "1.0.107", features = ["preserve_order"], optional = true }
ethnum = { version = "1.4", default-features = false, features = ["serde"] }
const_format = { version = "0.2.21" }
cfg-if = { version = "1.0" }
Expand Down
68 changes: 4 additions & 64 deletions evm_loader/program/src/evm/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use std::ops::Range;
use solana_program::program_memory::{sol_memcpy, sol_memset};

use crate::error::Error;
#[cfg(not(target_os = "solana"))]
use crate::evm::tracing::TracerTypeOpt;

use super::utils::checked_next_multiple_of_32;
use super::{tracing_event, Buffer};
use super::Buffer;

const MAX_MEMORY_SIZE: usize = 64 * 1024;
const MEMORY_CAPACITY: usize = 1024;
Expand All @@ -20,23 +18,14 @@ pub struct Memory {
data: *mut u8,
capacity: usize,
size: usize,
#[cfg(not(target_os = "solana"))]
tracer: TracerTypeOpt,
}

impl Memory {
pub fn new(#[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt) -> Self {
Self::with_capacity(
MEMORY_CAPACITY,
#[cfg(not(target_os = "solana"))]
tracer,
)
pub fn new() -> Self {
Self::with_capacity(MEMORY_CAPACITY)
}

pub fn with_capacity(
capacity: usize,
#[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt,
) -> Self {
pub fn with_capacity(capacity: usize) -> Self {
unsafe {
let layout = Layout::from_size_align_unchecked(capacity, MEMORY_ALIGN);
let data = crate::allocator::EVM.alloc_zeroed(layout);
Expand All @@ -48,8 +37,6 @@ impl Memory {
data,
capacity,
size: 0,
#[cfg(not(target_os = "solana"))]
tracer,
}
}
}
Expand All @@ -70,8 +57,6 @@ impl Memory {
data,
capacity,
size: v.len(),
#[cfg(not(target_os = "solana"))]
tracer: None,
}
}
}
Expand Down Expand Up @@ -157,14 +142,6 @@ impl Memory {
}

pub fn write_32(&mut self, offset: usize, value: &[u8; 32]) -> Result<(), Error> {
tracing_event!(
self,
super::tracing::Event::MemorySet {
offset,
data: value.to_vec()
}
);

self.realloc(offset, 32)?;

unsafe {
Expand All @@ -176,14 +153,6 @@ impl Memory {
}

pub fn write_byte(&mut self, offset: usize, value: u8) -> Result<(), Error> {
tracing_event!(
self,
super::tracing::Event::MemorySet {
offset,
data: vec![value]
}
);

self.realloc(offset, 1)?;

unsafe {
Expand Down Expand Up @@ -214,45 +183,16 @@ impl Memory {

match source_offset {
source_offset if source_offset >= source.len() => {
tracing_event!(
self,
super::tracing::Event::MemorySet {
offset,
data: vec![0; length]
}
);

sol_memset(data, 0, length);
}
source_offset if (source_offset + length) > source.len() => {
let source = &source[source_offset..];

tracing_event!(
self,
super::tracing::Event::MemorySet {
offset,
data: {
let mut buffer = vec![0_u8; length];
buffer[..source.len()].copy_from_slice(source);
buffer
}
}
);

data[..source.len()].copy_from_slice(source);
data[source.len()..].fill(0_u8);
}
source_offset => {
let source = &source[source_offset..source_offset + length];

tracing_event!(
self,
super::tracing::Event::MemorySet {
offset,
data: source.to_vec()
}
);

sol_memcpy(data, source, length);
}
}
Expand Down
30 changes: 6 additions & 24 deletions evm_loader/program/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,8 @@ impl<B: Database> Machine<B> {
call_data: trx.extract_call_data(),
return_data: Buffer::empty(),
return_range: 0..0,
stack: Stack::new(
#[cfg(not(target_os = "solana"))]
tracer.clone(),
),
memory: Memory::new(
#[cfg(not(target_os = "solana"))]
tracer.clone(),
),
stack: Stack::new(),
memory: Memory::new(),
pc: 0_usize,
is_static: false,
reason: Reason::Call,
Expand Down Expand Up @@ -336,14 +330,8 @@ impl<B: Database> Machine<B> {
gas_limit: trx.gas_limit(),
return_data: Buffer::empty(),
return_range: 0..0,
stack: Stack::new(
#[cfg(not(target_os = "solana"))]
tracer.clone(),
),
memory: Memory::new(
#[cfg(not(target_os = "solana"))]
tracer.clone(),
),
stack: Stack::new(),
memory: Memory::new(),
pc: 0_usize,
is_static: false,
reason: Reason::Create,
Expand Down Expand Up @@ -449,14 +437,8 @@ impl<B: Database> Machine<B> {
call_data,
return_data: Buffer::empty(),
return_range: 0..0,
stack: Stack::new(
#[cfg(not(target_os = "solana"))]
self.tracer.clone(),
),
memory: Memory::new(
#[cfg(not(target_os = "solana"))]
self.tracer.clone(),
),
stack: Stack::new(),
memory: Memory::new(),
pc: 0_usize,
is_static: self.is_static,
reason,
Expand Down
1 change: 0 additions & 1 deletion evm_loader/program/src/evm/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ impl<B: Database> Machine<B> {
let index = self.stack.pop_u256()?;
let value = *self.stack.pop_array()?;

tracing_event!(self, super::tracing::Event::StorageSet { index, value });
tracing_event!(self, super::tracing::Event::StorageAccess { index, value });

backend.set_storage(self.context.contract, index, value)?;
Expand Down
22 changes: 2 additions & 20 deletions evm_loader/program/src/evm/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@ use std::{

use ethnum::{I256, U256};

#[cfg(not(target_os = "solana"))]
use crate::evm::TracerTypeOpt;
use crate::{error::Error, types::Address};

use super::tracing_event;

const ELEMENT_SIZE: usize = 32;
const STACK_SIZE: usize = ELEMENT_SIZE * 128;

pub struct Stack {
begin: *mut u8,
end: *mut u8,
top: *mut u8,
#[cfg(not(target_os = "solana"))]
tracer: TracerTypeOpt,
}

impl Stack {
pub fn new(#[cfg(not(target_os = "solana"))] tracer: TracerTypeOpt) -> Self {
pub fn new() -> Self {
let (begin, end) = unsafe {
let layout = Layout::from_size_align_unchecked(STACK_SIZE, ELEMENT_SIZE);
let begin = crate::allocator::EVM.alloc(layout);
Expand All @@ -42,8 +36,6 @@ impl Stack {
begin,
end,
top: begin,
#[cfg(not(target_os = "solana"))]
tracer,
}
}

Expand All @@ -70,13 +62,6 @@ impl Stack {
return Err(Error::StackOverflow);
}

tracing_event!(
self,
super::tracing::Event::StackPush {
value: unsafe { *self.read() }
}
);

unsafe {
self.top = self.top.add(32);
}
Expand Down Expand Up @@ -315,10 +300,7 @@ impl<'de> serde::Deserialize<'de> for Stack {
return Err(E::invalid_length(v.len(), &self));
}

let mut stack = Stack::new(
#[cfg(not(target_os = "solana"))]
None,
);
let mut stack = Stack::new();
unsafe {
stack.top = stack.begin.add(v.len());

Expand Down
13 changes: 1 addition & 12 deletions evm_loader/program/src/evm/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ pub enum Event {
gas_used: u64,
return_data: Option<Vec<u8>>,
},
StackPush {
value: [u8; 32],
},
MemorySet {
offset: usize,
data: Vec<u8>,
},
StorageSet {
index: U256,
value: [u8; 32],
},
StorageAccess {
index: U256,
value: [u8; 32],
Expand Down Expand Up @@ -124,7 +113,7 @@ pub struct TraceConfig {
pub enable_return_data: bool,
pub tracer: Option<String>,
pub timeout: Option<String>,
pub tracer_config: Value,
pub tracer_config: Option<Value>,
}

#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
Expand Down
Loading