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

Add initial EIP-1559 support #244

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions Cargo.lock

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

62 changes: 59 additions & 3 deletions engine-precompiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::modexp::ModExp;
use crate::native::{ExitToEthereum, ExitToNear};
use crate::secp256k1::ECRecover;
use evm::backend::Log;
use evm::executor;
use evm::{Context, ExitError, ExitSucceed};

#[derive(Debug, Default)]
Expand Down Expand Up @@ -96,6 +97,26 @@ type PrecompileFn = fn(&[u8], Option<u64>, &Context, bool) -> EvmPrecompileResul

pub struct Precompiles(pub prelude::BTreeMap<prelude::Address, PrecompileFn>);

impl executor::PrecompileSet for Precompiles {
fn execute(
&self,
address: prelude::Address,
input: &[u8],
gas_limit: Option<u64>,
context: &Context,
is_static: bool,
) -> Option<Result<executor::PrecompileOutput, executor::PrecompileFailure>> {
self.0.get(&address).map(|f| {
f(input, gas_limit, context, is_static)
.map_err(|exit_status| executor::PrecompileFailure::Error { exit_status })
})
}

fn is_precompile(&self, address: prelude::Address) -> bool {
self.0.contains_key(&address)
}
}

impl Precompiles {
#[allow(dead_code)]
pub fn new_homestead() -> Self {
Expand Down Expand Up @@ -187,9 +208,44 @@ impl Precompiles {
Precompiles(map)
}

#[allow(dead_code)]
fn new_berlin() -> Self {
Self::new_istanbul()
pub fn new_berlin() -> Self {
let addresses = prelude::vec![
ECRecover::ADDRESS,
SHA256::ADDRESS,
RIPEMD160::ADDRESS,
Identity::ADDRESS,
ModExp::<Berlin>::ADDRESS,
Bn128Add::<Istanbul>::ADDRESS,
Bn128Mul::<Istanbul>::ADDRESS,
Bn128Pair::<Istanbul>::ADDRESS,
Blake2F::ADDRESS,
ExitToNear::ADDRESS,
ExitToEthereum::ADDRESS,
];
let fun: prelude::Vec<PrecompileFn> = prelude::vec![
ECRecover::run,
SHA256::run,
RIPEMD160::run,
Identity::run,
ModExp::<Berlin>::run,
Bn128Add::<Istanbul>::run,
Bn128Mul::<Istanbul>::run,
Bn128Pair::<Istanbul>::run,
Blake2F::run,
ExitToNear::run,
ExitToEthereum::run,
];
let mut map = prelude::BTreeMap::new();
for (address, fun) in addresses.into_iter().zip(fun) {
map.insert(address, fun);
}

Precompiles(map)
}

pub fn new_london() -> Self {
// no precompile changes in London HF
Self::new_berlin()
}
}

Expand Down
6 changes: 3 additions & 3 deletions engine-tests/src/benches/nft_pagination.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::prelude::types::Wei;
use crate::prelude::{Address, U256};
use crate::test_utils::{self, solidity};
use aurora_engine::transaction::LegacyEthTransaction;
use aurora_engine::transaction::legacy::TransactionLegacy;
use secp256k1::SecretKey;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -130,7 +130,7 @@ impl MarketPlace {
data: String,
price: Wei,
nonce: U256,
) -> LegacyEthTransaction {
) -> TransactionLegacy {
self.0.call_method_with_args(
"minar",
&[
Expand All @@ -147,7 +147,7 @@ impl MarketPlace {
tokens_per_page: usize,
page_index: usize,
nonce: U256,
) -> LegacyEthTransaction {
) -> TransactionLegacy {
self.0.call_method_with_args(
"obtenerPaginav2",
&[
Expand Down
32 changes: 16 additions & 16 deletions engine-tests/src/test_utils/erc20.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::prelude::{transaction::LegacyEthTransaction, Address, U256};
use crate::prelude::{transaction::legacy::TransactionLegacy, Address, U256};
use crate::test_utils::solidity;
use std::path::{Path, PathBuf};
use std::sync::Once;
Expand All @@ -25,7 +25,7 @@ impl ERC20Constructor {
))
}

pub fn deploy(&self, name: &str, symbol: &str, nonce: U256) -> LegacyEthTransaction {
pub fn deploy(&self, name: &str, symbol: &str, nonce: U256) -> TransactionLegacy {
let data = self
.0
.abi
Expand All @@ -39,10 +39,10 @@ impl ERC20Constructor {
],
)
.unwrap();
LegacyEthTransaction {
TransactionLegacy {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
gas_limit: u64::MAX.into(),
to: None,
value: Default::default(),
data,
Expand Down Expand Up @@ -71,7 +71,7 @@ impl ERC20Constructor {
}

impl ERC20 {
pub fn mint(&self, recipient: Address, amount: U256, nonce: U256) -> LegacyEthTransaction {
pub fn mint(&self, recipient: Address, amount: U256, nonce: U256) -> TransactionLegacy {
let data = self
.0
.abi
Expand All @@ -83,17 +83,17 @@ impl ERC20 {
])
.unwrap();

LegacyEthTransaction {
TransactionLegacy {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
gas_limit: u64::MAX.into(),
to: Some(self.0.address),
value: Default::default(),
data,
}
}

pub fn transfer(&self, recipient: Address, amount: U256, nonce: U256) -> LegacyEthTransaction {
pub fn transfer(&self, recipient: Address, amount: U256, nonce: U256) -> TransactionLegacy {
let data = self
.0
.abi
Expand All @@ -104,46 +104,46 @@ impl ERC20 {
ethabi::Token::Uint(amount),
])
.unwrap();
LegacyEthTransaction {
TransactionLegacy {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
gas_limit: u64::MAX.into(),
to: Some(self.0.address),
value: Default::default(),
data,
}
}

pub fn approve(&self, spender: Address, amount: U256, nonce: U256) -> LegacyEthTransaction {
pub fn approve(&self, spender: Address, amount: U256, nonce: U256) -> TransactionLegacy {
let data = self
.0
.abi
.function("approve")
.unwrap()
.encode_input(&[ethabi::Token::Address(spender), ethabi::Token::Uint(amount)])
.unwrap();
LegacyEthTransaction {
TransactionLegacy {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
gas_limit: u64::MAX.into(),
to: Some(self.0.address),
value: Default::default(),
data,
}
}

pub fn balance_of(&self, address: Address, nonce: U256) -> LegacyEthTransaction {
pub fn balance_of(&self, address: Address, nonce: U256) -> TransactionLegacy {
let data = self
.0
.abi
.function("balanceOf")
.unwrap()
.encode_input(&[ethabi::Token::Address(address)])
.unwrap();
LegacyEthTransaction {
TransactionLegacy {
nonce,
gas_price: Default::default(),
gas: u64::MAX.into(),
gas_limit: u64::MAX.into(),
to: Some(self.0.address),
value: Default::default(),
data,
Expand Down
12 changes: 6 additions & 6 deletions engine-tests/src/test_utils/exit_precompile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::{
parameters::SubmitResult, transaction::LegacyEthTransaction, Address, Wei, U256,
parameters::SubmitResult, transaction::legacy::TransactionLegacy, Address, Wei, U256,
};
use crate::test_utils::{self, solidity, AuroraRunner, Signer};

Expand All @@ -17,7 +17,7 @@ impl TesterConstructor {
))
}

pub fn deploy(&self, nonce: u64, token: Address) -> LegacyEthTransaction {
pub fn deploy(&self, nonce: u64, token: Address) -> TransactionLegacy {
let data = self
.0
.abi
Expand All @@ -26,10 +26,10 @@ impl TesterConstructor {
.encode_input(self.0.code.clone(), &[ethabi::Token::Address(token)])
.unwrap();

LegacyEthTransaction {
TransactionLegacy {
nonce: nonce.into(),
gas_price: Default::default(),
gas: U256::from(DEPLOY_CONTRACT_GAS),
gas_limit: U256::from(DEPLOY_CONTRACT_GAS),
to: None,
value: Default::default(),
data,
Expand Down Expand Up @@ -70,10 +70,10 @@ impl Tester {
.encode_input(params)
.unwrap();

let tx = LegacyEthTransaction {
let tx = TransactionLegacy {
nonce: signer.use_nonce().into(),
gas_price: Default::default(),
gas: U256::from(DEPLOY_CONTRACT_GAS),
gas_limit: U256::from(DEPLOY_CONTRACT_GAS),
to: Some(self.contract.address),
value,
data,
Expand Down
Loading