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

Update neonevm #906

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a82443c
Ndev 1981 neon api tests (#156)
kristinaNikolaevaa Aug 8, 2023
13a4e79
NDEV-1925: Remove environmental crate (#149)
andreisilviudragnea Aug 9, 2023
cd01c21
Fix neon evm CI (#161)
kristinaNikolaevaa Aug 14, 2023
163f6de
Simplified `TracerType` (removed unnecessary `Option`) (#164)
dk-neon Aug 16, 2023
98b7a5b
NDEV-1881: Use non blocking writer for logs (#165)
Deniskore Aug 16, 2023
9864c35
Fix performance with precompile contract (#172)
anton-lisanin Aug 24, 2023
ce1e732
Added own operator for each thread in tests (#171)
kristinaNikolaevaa Aug 25, 2023
bfa302d
Added support for different tracer types (#168)
dk-neon Aug 25, 2023
1f6e5da
NDEV-2117 Check holder address (#176)
s-medvedev Aug 30, 2023
98f9f18
Set version to v1.3.0-dev (#178)
afalaleev Aug 30, 2023
b14d1cc
EIP2930: Tx envelop and AccessList tx support (#140)
raventid Sep 1, 2023
8c20d64
NDEV-2059: Improve performance of get_account_rooted_slot, get_branch…
Deniskore Sep 4, 2023
e2b78b2
NDEV-2115: Replace default_features with default-features (#174)
andreisilviudragnea Sep 5, 2023
85312da
NDEV-2160: Improve account data printing (#183)
Deniskore Sep 5, 2023
690fd47
NDEV-2155: Use neon-evm-1 runners (#182)
andreisilviudragnea Sep 6, 2023
12bbb9b
NDEV-2133: Implement a mechanism to obtain NEON_REVISION (#184)
Deniskore Sep 6, 2023
2716ff0
Changing file permissions (#185)
kristinaNikolaevaa Sep 6, 2023
b5663a3
Update the 'ethnum' crate version and remove serialization workaround…
stanislav-tkach Sep 8, 2023
3f334b2
Set version v1.5.0-dev (#190)
afalaleev Sep 10, 2023
aa95aba
NDEV-2176: Change the ordering in neon_revision SQL (#189)
Deniskore Sep 11, 2023
b761291
NDEV-2175: Use tracing::instrument and request id on neon-api endpoin…
andreisilviudragnea Sep 11, 2023
dc02672
NDEV-2081: More useful CI logs (#191)
andreisilviudragnea Sep 12, 2023
3800125
Update neonevm from base develop (#192)
gigimon Sep 12, 2023
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
Prev Previous commit
Next Next commit
EIP2930: Tx envelop and AccessList tx support (#140)
 EIP2930: Tx envelop and AccessList transaction support
- Uses individual structs for Transactions
- Adds tests for different structure of access list
- Changes Transaction core type and it's usage everywhere
  • Loading branch information
raventid authored Sep 1, 2023
commit b14d1ccaf3fd1f6dfe3b9b4c2f0cca913e73e85f
20 changes: 19 additions & 1 deletion evm_loader/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use neon_lib::{
get_ether_account_data, get_neon_elf, get_neon_elf::CachedElfParams, get_storage_at,
init_environment, trace,
},
errors, rpc, types,
errors, rpc,
types::{self, AccessListItem},
};

use clap::ArgMatches;
Expand Down Expand Up @@ -319,16 +320,21 @@ fn parse_tx(params: &ArgMatches) -> (TxParams, TraceCallConfig) {
)
})
.unwrap_or_default();

let value = u256_of(params, "value");

let gas_limit = u256_of(params, "gas_limit");

let access_list = access_list_of(params, "access_list");

let tx_params = TxParams {
nonce: None,
from,
to,
data,
value,
gas_limit,
access_list,
};

(tx_params, trace_config)
Expand Down Expand Up @@ -403,6 +409,18 @@ fn address_of(matches: &ArgMatches<'_>, name: &str) -> Option<Address> {
.map(|value| Address::from_hex(value).unwrap())
}

fn access_list_of(matches: &ArgMatches<'_>, name: &str) -> Option<Vec<AccessListItem>> {
matches.value_of(name).map(|value| {
let address = Address::from_hex(value).unwrap();
let keys = vec![];
let item = AccessListItem {
address,
storage_keys: keys,
};
vec![item]
})
}

fn u256_of(matches: &ArgMatches<'_>, name: &str) -> Option<U256> {
matches.value_of(name).map(|value| {
if value.is_empty() {
Expand Down
8 changes: 8 additions & 0 deletions evm_loader/cli/src/program_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ fn trx_params<'a, 'b>(cmd: &'static str, desc: &'static str) -> App<'a, 'b> {
.validator(is_valid_u256)
.help("Gas limit"),
)
.arg(
Arg::with_name("access_list")
.long("access-list")
.takes_value(true)
.required(false)
.multiple(true)
.value_name("ADDRESS [STORAGE_KEYS ...]"),
)
.arg(
Arg::with_name("cached_accounts")
.value_name("CACHED_ACCOUNTS")
Expand Down
70 changes: 58 additions & 12 deletions evm_loader/lib/src/commands/emulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,65 @@ pub(crate) async fn emulate_trx<'a>(
) -> Result<evm_loader::evm::tracing::EmulationResult, NeonError> {
let (exit_status, actions, steps_executed) = {
let mut backend = ExecutorState::new(storage);
let trx = Transaction {
nonce: tx_params
.nonce
.unwrap_or_else(|| storage.nonce(&tx_params.from)),
gas_price: U256::ZERO,
gas_limit: tx_params.gas_limit.unwrap_or(U256::MAX),
target: tx_params.to,
value: tx_params.value.unwrap_or_default(),
call_data: evm_loader::evm::Buffer::from_slice(&tx_params.data.unwrap_or_default()),
chain_id: Some(chain_id.into()),
..Transaction::default()
let trx_payload = if tx_params.access_list.is_some() {
let access_list = tx_params
.access_list
.expect("access_list is present")
.into_iter()
.map(|item| {
(
item.address,
item.storage_keys
.into_iter()
.map(|k| {
evm_loader::types::StorageKey::try_from(k)
.expect("key to be correct")
})
.collect(),
)
})
.collect();
evm_loader::types::TransactionPayload::AccessList(evm_loader::types::AccessListTx {
nonce: tx_params
.nonce
.unwrap_or_else(|| storage.nonce(&tx_params.from)),
gas_price: U256::ZERO,
gas_limit: tx_params.gas_limit.unwrap_or(U256::MAX),
target: tx_params.to,
value: tx_params.value.unwrap_or_default(),
call_data: evm_loader::evm::Buffer::from_slice(&tx_params.data.unwrap_or_default()),
r: U256::default(),
s: U256::default(),
chain_id: chain_id.into(),
recovery_id: u8::default(),
access_list,
})
} else {
evm_loader::types::TransactionPayload::Legacy(evm_loader::types::LegacyTx {
nonce: tx_params
.nonce
.unwrap_or_else(|| storage.nonce(&tx_params.from)),
gas_price: U256::ZERO,
gas_limit: tx_params.gas_limit.unwrap_or(U256::MAX),
target: tx_params.to,
value: tx_params.value.unwrap_or_default(),
call_data: evm_loader::evm::Buffer::from_slice(&tx_params.data.unwrap_or_default()),
v: U256::default(),
r: U256::default(),
s: U256::default(),
chain_id: Some(chain_id.into()),
recovery_id: u8::default(),
})
};
let mut evm = Machine::new(trx, tx_params.from, &mut backend, tracer)?;

let mut trx = Transaction {
transaction: trx_payload,
byte_len: usize::default(),
hash: <[u8; 32]>::default(),
signed_hash: <[u8; 32]>::default(),
};

let mut evm = Machine::new(&mut trx, tx_params.from, &mut backend, tracer)?;

let (result, steps_executed) = evm.execute(step_limit, &mut backend)?;
if result == ExitStatus::StepLimit {
Expand Down
1 change: 1 addition & 0 deletions evm_loader/lib/src/types/indexer_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ impl IndexerDb {
data: Some(data),
value: Some(value),
gas_limit: Some(gas_limit),
access_list: None,
})
}
}
7 changes: 7 additions & 0 deletions evm_loader/lib/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ pub struct ChDbConfig {
pub indexer_password: String,
}

#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct AccessListItem {
pub address: Address,
pub storage_keys: Vec<HexBytes>,
}

#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct TxParams {
pub nonce: Option<u64>,
Expand All @@ -41,6 +47,7 @@ pub struct TxParams {
pub data: Option<Vec<u8>>,
pub value: Option<U256>,
pub gas_limit: Option<U256>,
pub access_list: Option<Vec<AccessListItem>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
4 changes: 4 additions & 0 deletions evm_loader/lib/src/types/request_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use evm_loader::types::Address;
use serde::{Deserialize, Serialize};
use solana_sdk::pubkey::Pubkey;

use super::AccessListItem;

#[derive(Deserialize, Serialize, Debug, Default)]
pub struct GetEtherRequest {
pub ether: Address,
Expand All @@ -25,6 +27,7 @@ pub struct TxParamsRequestModel {
pub data: Option<Vec<u8>>,
pub value: Option<U256>,
pub gas_limit: Option<U256>,
pub access_list: Option<Vec<AccessListItem>>,
}

impl From<TxParamsRequestModel> for TxParams {
Expand All @@ -36,6 +39,7 @@ impl From<TxParamsRequestModel> for TxParams {
data: model.data,
value: model.value,
gas_limit: model.gas_limit,
access_list: model.access_list,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions evm_loader/program/src/account/holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ impl<'a> Holder<'a> {
}

pub fn validate_transaction(&self, trx: &Transaction) -> Result<()> {
if self.transaction_hash != trx.hash {
return Err(Error::HolderInvalidHash(self.transaction_hash, trx.hash));
if self.transaction_hash != trx.hash() {
return Err(Error::HolderInvalidHash(self.transaction_hash, trx.hash()));
}

Ok(())
Expand Down
46 changes: 23 additions & 23 deletions evm_loader/program/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<B: Database> Machine<B> {
}

pub fn new(
trx: Transaction,
trx: &mut Transaction,
origin: Address,
backend: &mut B,
#[cfg(feature = "tracing")] tracer: TracerTypeOpt,
Expand All @@ -203,29 +203,29 @@ impl<B: Database> Machine<B> {
return Err(Error::NonceOverflow(origin));
}

if origin_nonce != trx.nonce {
if origin_nonce != trx.nonce() {
return Err(Error::InvalidTransactionNonce(
origin,
origin_nonce,
trx.nonce,
trx.nonce(),
));
}

if let Some(chain_id) = trx.chain_id {
if let Some(chain_id) = trx.chain_id() {
if backend.chain_id() != chain_id {
return Err(Error::InvalidChainId(chain_id));
}
}

if backend.balance(&origin)? < trx.value {
return Err(Error::InsufficientBalance(origin, trx.value));
if backend.balance(&origin)? < trx.value() {
return Err(Error::InsufficientBalance(origin, trx.value()));
}

if backend.code_size(&origin)? != 0 {
return Err(Error::SenderHasDeployedCode(origin));
}

if trx.target.is_some() {
if trx.target().is_some() {
Self::new_call(
trx,
origin,
Expand All @@ -245,20 +245,20 @@ impl<B: Database> Machine<B> {
}

fn new_call(
trx: Transaction,
trx: &mut Transaction,
origin: Address,
backend: &mut B,
#[cfg(feature = "tracing")] tracer: TracerTypeOpt,
) -> Result<Self> {
assert!(trx.target.is_some());
assert!(trx.target().is_some());

let target = trx.target.unwrap();
let target = trx.target().unwrap();
sol_log_data(&[b"ENTER", b"CALL", target.as_bytes()]);

backend.increment_nonce(origin)?;
backend.snapshot();

backend.transfer(origin, target, trx.value)?;
backend.transfer(origin, target, trx.value())?;

let execution_code = backend.code(&target)?;

Expand All @@ -267,13 +267,13 @@ impl<B: Database> Machine<B> {
context: Context {
caller: origin,
contract: target,
value: trx.value,
value: trx.value(),
code_address: Some(target),
},
gas_price: trx.gas_price,
gas_limit: trx.gas_limit,
gas_price: trx.gas_price(),
gas_limit: trx.gas_limit(),
execution_code,
call_data: trx.call_data,
call_data: trx.extract_call_data(),
return_data: Buffer::empty(),
return_range: 0..0,
stack: Stack::new(
Expand All @@ -295,14 +295,14 @@ impl<B: Database> Machine<B> {
}

fn new_create(
trx: Transaction,
trx: &mut Transaction,
origin: Address,
backend: &mut B,
#[cfg(feature = "tracing")] tracer: TracerTypeOpt,
) -> Result<Self> {
assert!(trx.target.is_none());
assert!(trx.target().is_none());

let target = Address::from_create(&origin, trx.nonce);
let target = Address::from_create(&origin, trx.nonce());
sol_log_data(&[b"ENTER", b"CREATE", target.as_bytes()]);

if (backend.nonce(&target)? != 0) || (backend.code_size(&target)? != 0) {
Expand All @@ -313,18 +313,18 @@ impl<B: Database> Machine<B> {
backend.snapshot();

backend.increment_nonce(target)?;
backend.transfer(origin, target, trx.value)?;
backend.transfer(origin, target, trx.value())?;

Ok(Self {
origin,
context: Context {
caller: origin,
contract: target,
value: trx.value,
value: trx.value(),
code_address: None,
},
gas_price: trx.gas_price,
gas_limit: trx.gas_limit,
gas_price: trx.gas_price(),
gas_limit: trx.gas_limit(),
return_data: Buffer::empty(),
return_range: 0..0,
stack: Stack::new(
Expand All @@ -338,7 +338,7 @@ impl<B: Database> Machine<B> {
pc: 0_usize,
is_static: false,
reason: Reason::Create,
execution_code: trx.call_data,
execution_code: trx.extract_call_data(),
call_data: Buffer::empty(),
parent: None,
phantom: PhantomData,
Expand Down
2 changes: 1 addition & 1 deletion evm_loader/program/src/gasometer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Gasometer {
}

pub fn record_write_to_holder(&mut self, trx: &Transaction) {
let size: u64 = trx.rlp_len.try_into().expect("usize is 8 bytes");
let size: u64 = trx.rlp_len().try_into().expect("usize is 8 bytes");
let cost: u64 = ((size + (HOLDER_MSG_SIZE - 1)) / HOLDER_MSG_SIZE)
.saturating_mul(WRITE_TO_HOLDER_TRX_COST);

Expand Down
10 changes: 5 additions & 5 deletions evm_loader/program/src/instruction/transaction_execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub fn validate(
trx: &Transaction,
_caller_address: &Address,
) -> Result<()> {
if trx.chain_id != Some(CHAIN_ID.into()) {
return Err(Error::InvalidChainId(trx.chain_id.unwrap_or(U256::ZERO)));
if trx.chain_id() != Some(CHAIN_ID.into()) {
return Err(Error::InvalidChainId(trx.chain_id().unwrap_or(U256::ZERO)));
}

account_storage.check_for_blocked_accounts()?;
Expand All @@ -39,7 +39,7 @@ pub fn execute<'a>(
accounts: Accounts<'a>,
account_storage: &mut ProgramAccountStorage<'a>,
mut gasometer: Gasometer,
trx: Transaction,
trx: &mut Transaction,
caller_address: Address,
) -> Result<()> {
accounts.system_program.transfer(
Expand All @@ -48,8 +48,8 @@ pub fn execute<'a>(
crate::config::PAYMENT_TO_TREASURE,
)?;

let gas_limit = trx.gas_limit;
let gas_price = trx.gas_price;
let gas_limit = trx.gas_limit();
let gas_price = trx.gas_price();

let (exit_reason, apply_state) = {
let mut backend = ExecutorState::new(account_storage);
Expand Down
Loading