Skip to content

Commit 5d21348

Browse files
committed
wip-bump-revm
1 parent a056a8e commit 5d21348

8 files changed

Lines changed: 370 additions & 57 deletions

File tree

Cargo.lock

Lines changed: 318 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime-sdk/modules/evm-new/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ rand_core = { version = "0.6.4", default-features = false }
2727
# Ethereum.
2828
ethabi = { version = "18.0.0", default-features = false, features = ["std"] }
2929
ethereum = "0.15"
30-
revm = { git = "https://github.com/bluealloy/revm", tag = "v56", default-features = false, features = ["std", "serde", "optional_eip3607"] }
30+
revm = { git = "https://github.com/bluealloy/revm", tag = "v66", default-features = false, features = ["std", "serde", "optional_eip3607"] }
3131
fixed-hash = "0.8.0"
3232
primitive-types = { version = "0.12", default-features = false, features = ["rlp", "num-traits"] }
3333
rlp = "0.5.2"

runtime-sdk/modules/evm-new/src/db.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use revm::{
2-
primitives::{Account, AccountInfo, Address, Bytecode, B256, KECCAK_EMPTY, U256},
2+
database::DBErrorMarker,
3+
primitives::{Address, B256, KECCAK_EMPTY, U256},
4+
state::{Account, AccountInfo, Bytecode},
35
Database, DatabaseCommit,
46
};
5-
use std::{collections::HashMap, vec::Vec};
7+
use std::{collections::HashMap, error::Error, fmt, vec::Vec};
68

79
use std::marker::PhantomData;
810

@@ -27,9 +29,27 @@ impl<'ctx, C: Context, Cfg: Config> OasisDB<'ctx, C, Cfg> {
2729
}
2830
}
2931

32+
#[derive(Debug)]
33+
pub struct DBError(pub String);
34+
35+
impl DBErrorMarker for DBError {}
36+
impl Error for DBError {}
37+
38+
impl fmt::Display for DBError {
39+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40+
write!(f, "{}", self.0)
41+
}
42+
}
43+
44+
impl From<String> for DBError {
45+
fn from(s: String) -> Self {
46+
Self(s)
47+
}
48+
}
49+
3050
// Implement read-only parts of the database.
3151
impl<'ctx, C: Context, Cfg: Config> Database for OasisDB<'ctx, C, Cfg> {
32-
type Error = String;
52+
type Error = DBError;
3353

3454
/// Get basic account information.
3555
fn basic(&mut self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
@@ -79,7 +99,7 @@ impl<'ctx, C: Context, Cfg: Config> Database for OasisDB<'ctx, C, Cfg> {
7999
/// Get account code by its hash (unimplemented).
80100
fn code_by_hash(&mut self, _code_hash: B256) -> Result<Bytecode, Self::Error> {
81101
println!("###### code_by_hash called ######");
82-
Err("getting code by hash is not supported".to_string())
102+
Err("getting code by hash is not supported".to_string().into())
83103
}
84104

85105
/// Get storage value of address at index.

runtime-sdk/modules/evm-new/src/lib.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ mod signed_call;
1010
pub mod state;
1111
pub mod types;
1212

13-
use std::sync::Arc;
14-
1513
use base64::prelude::*;
1614
use revm::{
15+
context::TxEnv,
16+
context_interface::result::{ExecutionResult, Output},
1717
precompile::PrecompileWithAddress,
18-
primitives::{Bytes, ExecutionResult, Output, SpecId, TxEnv, TxKind},
19-
Evm,
18+
primitives::{hardfork::SpecId, Bytes, TxKind},
19+
Context as EvmContext, ExecuteCommitEvm, ExecuteEvm, MainBuilder, MainContext,
2020
};
2121

2222
use oasis_runtime_sdk::{
@@ -394,46 +394,43 @@ impl<Cfg: Config> Module<Cfg> {
394394

395395
// Prepare the environment.
396396
let db = db::OasisDB::<'_, C, Cfg>::new(ctx);
397-
let mut evm = Evm::builder()
397+
let mut evm = EvmContext::mainnet()
398398
.with_db(db)
399-
.with_spec_id(SpecId::SHANGHAI)
400-
.modify_cfg_env(|cfg| {
399+
.modify_cfg_chained(|cfg| {
400+
cfg.spec = SpecId::SHANGHAI;
401401
cfg.disable_eip3607 = true;
402402
})
403-
.append_handler_register(|handler| {
403+
// TODO: Port precompiles to the new API.
404+
/*.append_handler_register(|handler| {
404405
// Load standard precompiles.
405406
//
406407
// For Shanghai spec these include the following: ecrecover,
407408
// sha256, ripemd160, identity, bn128::{add,mul,pair}, blake2,
408409
// modexp.
409410
let precompiles = handler.pre_execution.load_precompiles();
410-
411411
handler.pre_execution.load_precompiles = Arc::new(move || {
412412
// Start with standard precompiles.
413413
let mut precompiles = precompiles.clone();
414-
415414
// Extend with Oasis-specific precompiles.
416415
precompiles.extend(precompile::new());
417-
418416
// Extend with module-specific precompiles (if any).
419417
if let Some(additional_precompiles) = Cfg::additional_precompiles() {
420418
precompiles.extend(additional_precompiles);
421419
}
422-
423420
precompiles
424421
});
425-
})
426-
.modify_tx_env(f)
427-
.build();
422+
})*/
423+
.modify_tx_chained(f)
424+
.build_mainnet();
428425

429426
// Run the transaction.
430427
let tx_result = if estimate_gas {
431-
match evm.transact() {
428+
match evm.transact(evm.tx.clone()) {
432429
Ok(result) => result.result,
433430
Err(err) => return Err(crate::Error::ExecutionFailed(format!("{:?}", err))),
434431
}
435432
} else {
436-
match evm.transact_commit() {
433+
match evm.transact_commit(evm.tx.clone()) {
437434
Ok(result) => result,
438435
Err(err) => return Err(crate::Error::ExecutionFailed(format!("{:?}", err))),
439436
}
@@ -523,7 +520,7 @@ impl<Cfg: Config> Module<Cfg> {
523520
.unwrap(); // XXX: err checking
524521

525522
tx.caller = caller.0.into();
526-
tx.transact_to = TxKind::Create;
523+
tx.kind = TxKind::Create;
527524
tx.value = revm::primitives::U256::from_be_bytes(value.into());
528525
tx.data = init_code.into();
529526
})
@@ -544,7 +541,7 @@ impl<Cfg: Config> Module<Cfg> {
544541
.unwrap(); // XXX: err checking
545542

546543
tx.caller = caller.0.into();
547-
tx.transact_to = TxKind::Call(address.0.into());
544+
tx.kind = TxKind::Call(address.0.into());
548545
tx.value = revm::primitives::U256::from_be_bytes(value.into());
549546
tx.data = data.into();
550547
})

runtime-sdk/modules/evm-new/src/precompile/confidential.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Implements the confidential precompiles.
2-
use std::{collections::HashMap, convert::TryInto};
2+
/*use std::{collections::HashMap, convert::TryInto};
33
44
use ethabi::{ParamType, Token};
55
use hmac::{Hmac, Mac};
@@ -320,3 +320,4 @@ pub(super) fn call_verify(input: &Bytes, gas_limit: u64) -> PrecompileResult {
320320
let output = ethabi::encode(&[Token::Bool(result.is_ok())]);
321321
Ok(PrecompileOutput::new(cost, output.into()))
322322
}
323+
*/

runtime-sdk/modules/evm-new/src/precompile/gas.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ethabi::{ParamType, Token};
1+
/*use ethabi::{ParamType, Token};
22
use revm::{
33
precompile::{PrecompileError, PrecompileOutput, PrecompileResult},
44
primitives::{Bytes, Env},
@@ -49,3 +49,4 @@ pub(super) fn call_pad_gas(input: &Bytes, gas_limit: u64, _env: &Env) -> Precomp
4949
5050
Ok(PrecompileOutput::new(cost, Bytes::new()))
5151
}
52+
*/

runtime-sdk/modules/evm-new/src/precompile/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use revm::precompile::{Address, Precompile, PrecompileWithAddress};
1+
use revm::{precompile::PrecompileWithAddress, primitives::Address};
22

33
mod confidential;
44
mod gas;
@@ -13,7 +13,9 @@ pub const fn oasis_addr(a18: u8, a19: u8) -> Address {
1313
}
1414

1515
pub fn new() -> Vec<PrecompileWithAddress> {
16-
vec![
16+
// TODO: Port precompiles to the new revm API.
17+
vec![]
18+
/*vec![
1719
// Oasis-specific, confidential.
1820
// TODO: random_bytes
1921
/*PrecompileWithAddress(
@@ -62,5 +64,5 @@ pub fn new() -> Vec<PrecompileWithAddress> {
6264
Precompile::Env(subcall::call_subcall),
6365
),*/
6466
PrecompileWithAddress(oasis_addr(1, 4), Precompile::Standard(sha2::call_sha384)),
65-
]
67+
]*/
6668
}

runtime-sdk/modules/evm-new/src/precompile/sha2.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Implements SHA2 precompiles.
2-
use revm::{
2+
/*use revm::{
33
precompile::{calc_linear_cost_u32, PrecompileError, PrecompileOutput, PrecompileResult},
44
primitives::Bytes,
55
};
@@ -24,3 +24,4 @@ macro_rules! make_hasher {
2424
make_hasher!(call_sha512_256, Sha512_256);
2525
make_hasher!(call_sha384, Sha384);
2626
make_hasher!(call_sha512, Sha512);
27+
*/

0 commit comments

Comments
 (0)