Skip to content

Commit

Permalink
Merge branch 'develop' into feat/erc20-gas-token
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss authored Feb 6, 2023
2 parents 43b5019 + 5675e75 commit 3753523
Show file tree
Hide file tree
Showing 29 changed files with 515 additions and 489 deletions.
591 changes: 322 additions & 269 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ wget https://github.com/aurora-is-near/aurora-engine/releases/download/latest/ma
### Installing the Aurora CLI tool

```sh
npm install -g aurora-is-near/aurora-cli
npm install -g @auroraisnear/cli
```

### Deploying the EVM with the CLI
Expand Down
1 change: 0 additions & 1 deletion engine-precompiles/src/modexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ fn saturating_round(x: U256) -> u64 {
fn parse_lengths(input: &[u8]) -> (u64, u64, u64) {
let parse = |start: usize| -> u64 {
// I don't understand why I need a closure here, but doesn't compile without one
#[allow(clippy::redundant_closure)]
saturating_round(parse_bytes(input, start, 32, |x| U256::from(x)))
};
let base_len = parse(0);
Expand Down
10 changes: 6 additions & 4 deletions engine-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ autobenches = false

[dependencies]
aurora-engine-types = { path = "../engine-types", default-features = false }
borsh = { version = "0.9.3", default-features = false }
sha3 = { version = "0.10.2", default-features = false }
sha2 = { version = "0.10.2", default-features = false }

base64 = { version = "0.21", default-features = false, features = [ "alloc" ] }
borsh = { version = "0.9", default-features = false }
sha2 = { version = "0.10", default-features = false }
sha3 = { version = "0.10", default-features = false }

[features]
std = ["aurora-engine-types/std", "borsh/std", "sha3/std", "sha2/std"]
std = ["aurora-engine-types/std", "borsh/std", "sha3/std", "sha2/std", "base64/std" ]
contract = []
log = []
all-promise-actions = []
Expand Down
13 changes: 13 additions & 0 deletions engine-sdk/src/base64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use aurora_engine_types::{String, Vec};
pub use base64::DecodeError;
use base64::Engine;

/// Encode arbitrary octets as base64 using the standard `base64::Engine`.
pub fn encode<T: AsRef<[u8]>>(input: T) -> String {
base64::engine::general_purpose::STANDARD.encode(input)
}

/// Decode from string reference as octets using the standard `base64::Engine`.
pub fn decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, DecodeError> {
base64::engine::general_purpose::STANDARD.decode(input)
}
2 changes: 1 addition & 1 deletion engine-sdk/src/caching.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use aurora_engine_types::BTreeMap;

/// A naive cache storing all key-value pairs it learns about..
/// A naive cache storing all key-value pairs it learns about.
#[derive(Default)]
pub struct FullCache<K, V> {
inner: BTreeMap<K, V>,
Expand Down
2 changes: 1 addition & 1 deletion engine-sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc_error_handler))]

#[cfg(feature = "contract")]
use crate::prelude::{Address, Vec, U256};
use crate::prelude::{H256, STORAGE_PRICE_PER_BYTE};
pub use types::keccak;

pub mod base64;
pub mod caching;
pub mod env;
pub mod error;
Expand Down
4 changes: 2 additions & 2 deletions engine-sdk/src/near_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Runtime {
const GAS_FOR_STATE_MIGRATION: NearGas = NearGas::new(100_000_000_000_000);

/// Deploy code from given key in place of the current contract.
/// Not implemented in terms of higher level traits (eg IO) for efficiency reasons.
/// Not implemented in terms of higher level traits (e.g. IO) for efficiency reasons.
pub fn self_deploy(code_key: &[u8]) {
unsafe {
// Load current account id into register 0.
Expand Down Expand Up @@ -107,7 +107,7 @@ impl StorageIntermediate for RegisterIndex {
unsafe {
let result = exports::register_len(self.0);
// By convention, an unused register will return a length of U64::MAX
// (see https://nomicon.io/RuntimeSpec/Components/BindingsSpec/RegistersAPI.html).
// (see https://nomicon.io/RuntimeSpec/Components/BindingsSpec/RegistersAPI).
if result < u64::MAX {
result as usize
} else {
Expand Down
3 changes: 1 addition & 2 deletions engine-standalone-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ aurora-engine-types = { path = "../engine-types", default-features = false, feat
aurora-engine-sdk = { path = "../engine-sdk", default-features = false, features = ["std"] }
aurora-engine-transactions = { path = "../engine-transactions", default-features = false, features = ["std"] }
aurora-engine-precompiles = { path = "../engine-precompiles", default-features = false, features = ["std"] }
borsh = { version = "0.9.3" }
borsh = "0.9"
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.37.4-aurora", default-features = false }
hex = "0.4.3"
rocksdb = { version = "0.19.0", default-features = false }
postgres = "0.19.2"
serde = "1.0.130"
serde_json = "1.0.72"
base64 = "0.13.0"

[features]
default = ["snappy", "lz4", "zstd", "zlib"]
Expand Down
12 changes: 7 additions & 5 deletions engine-standalone-storage/src/json_snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub fn initialize_engine_state(

let mut batch = rocksdb::WriteBatch::default();
for entry in snapshot.result.values {
let key = base64::decode(entry.key)?;
let value = base64::decode(entry.value)?;
let key = aurora_engine_sdk::base64::decode(entry.key)?;
let value = aurora_engine_sdk::base64::decode(entry.value)?;
let storage_key = crate::construct_engine_key(&key, block_height, transaction_position);
let storage_value = crate::diff::DiffValue::Modified(value);
batch.put(storage_key, storage_value.try_to_bytes()?);
Expand All @@ -26,15 +26,17 @@ pub fn initialize_engine_state(
}

pub mod error {
use aurora_engine_sdk::base64::DecodeError;

#[derive(Debug)]
pub enum Error {
Base64(base64::DecodeError),
Base64(DecodeError),
Rocksdb(rocksdb::Error),
Borsh(std::io::Error),
}

impl From<base64::DecodeError> for Error {
fn from(e: base64::DecodeError) -> Self {
impl From<DecodeError> for Error {
fn from(e: DecodeError) -> Self {
Self::Base64(e)
}
}
Expand Down
6 changes: 3 additions & 3 deletions engine-standalone-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ impl Storage {

let value = if iter.valid() {
let bytes = iter.value().unwrap();
diff::DiffValue::try_from_bytes(bytes).unwrap_or_else(|e| {
DiffValue::try_from_bytes(bytes).unwrap_or_else(|e| {
panic!(
"Could not deserialize key={} value={} error={:?}",
base64::encode(&db_key),
base64::encode(bytes),
aurora_engine_sdk::base64::encode(&db_key),
aurora_engine_sdk::base64::encode(bytes),
e,
)
})
Expand Down
3 changes: 1 addition & 2 deletions engine-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.37.4-
evm-runtime = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.37.4-aurora", default-features = false, features = ["std", "tracing"] }
evm-gasometer = { git = "https://github.com/aurora-is-near/sputnikvm.git", tag = "v0.37.4-aurora", default-features = false, features = ["std", "tracing"] }
rlp = { version = "0.5.0", default-features = false }
base64 = "0.13.0"
bstr = "1.0.1"
byte-slice-cast = { version = "1.0", default-features = false }
ethabi = "18.0"
Expand All @@ -47,7 +46,7 @@ near-primitives = { git = "https://github.com/birchmd/nearcore.git", rev = "6033
libsecp256k1 = { version = "0.7.0", default-features = false }
rand = "0.8.5"
criterion = "0.4.0"
git2 = "0.15"
git2 = "0.16"
tempfile = "3.2.0"
walrus = "0.19"

Expand Down
20 changes: 8 additions & 12 deletions engine-tests/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ use crate::test_utils::solidity::{ContractConstructor, DeployedContract};

// TODO(Copied from #84): Make sure that there is only one Signer after both PR are merged.

pub fn origin() -> String {
"aurora".to_string()
}

pub(crate) const ORIGIN: &str = "aurora";
pub(crate) const SUBMIT: &str = "submit";
pub(crate) const CALL: &str = "call";
pub(crate) const DEPLOY_ERC20: &str = "deploy_erc20_token";
Expand Down Expand Up @@ -248,8 +245,8 @@ impl AuroraRunner {
) {
let trie = &mut self.ext.underlying.fake_trie;
for entry in snapshot.result.values {
let key = base64::decode(entry.key).unwrap();
let value = base64::decode(entry.value).unwrap();
let key = aurora_engine_sdk::base64::decode(entry.key).unwrap();
let value = aurora_engine_sdk::base64::decode(entry.value).unwrap();
trie.insert(key, value);
}
}
Expand Down Expand Up @@ -539,7 +536,6 @@ impl AuroraRunner {

impl Default for AuroraRunner {
fn default() -> Self {
let aurora_account_id = "aurora".to_string();
let evm_wasm_bytes = if cfg!(feature = "mainnet-test") {
std::fs::read("../bin/aurora-mainnet-test.wasm").unwrap()
} else if cfg!(feature = "testnet-test") {
Expand All @@ -554,16 +550,16 @@ impl Default for AuroraRunner {
let wasm_config = runtime_config.wasm_config.clone();

Self {
aurora_account_id: aurora_account_id.clone(),
aurora_account_id: ORIGIN.to_string(),
chain_id: 1313161556, // NEAR localnet,
code: ContractCode::new(evm_wasm_bytes, None),
cache: Default::default(),
ext: mocked_external::MockedExternalWithTrie::new(Default::default()),
context: VMContext {
current_account_id: as_account_id(&aurora_account_id),
signer_account_id: as_account_id(&aurora_account_id),
current_account_id: as_account_id(ORIGIN),
signer_account_id: as_account_id(ORIGIN),
signer_account_pk: vec![],
predecessor_account_id: as_account_id(&aurora_account_id),
predecessor_account_id: as_account_id(ORIGIN),
input: vec![],
block_index: 0,
block_timestamp: 0,
Expand Down Expand Up @@ -803,7 +799,7 @@ pub(crate) fn parse_eth_gas(output: &VMOutcome) -> u64 {
pub(crate) fn validate_address_balance_and_nonce(
runner: &AuroraRunner,
address: Address,
expected_balance: crate::prelude::Wei,
expected_balance: Wei,
expected_nonce: U256,
) {
assert_eq!(runner.get_balance(address), expected_balance, "balance");
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/contract_call.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::{parameters::SubmitResult, vec, Address, Wei, H256, U256};
use crate::test_utils::{origin, AuroraRunner, Signer};
use crate::test_utils::{AuroraRunner, Signer, ORIGIN};

use crate::test_utils;
use crate::test_utils::exit_precompile::{Tester, TesterConstructor, DEST_ACCOUNT, DEST_ADDRESS};
Expand All @@ -25,7 +25,7 @@ fn setup_test() -> (AuroraRunner, Signer, Address, Tester) {
)
.into();

runner.mint(token, tester.contract.address, 1_000_000_000, origin());
runner.mint(token, tester.contract.address, 1_000_000_000, ORIGIN);

(runner, signer, token, tester)
}
Expand Down
6 changes: 3 additions & 3 deletions engine-tests/src/tests/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const EXAMPLE_TX_HEX: &str = "02f8c101010a8207d0833d090094cccccccccccccccccccccc
// TODO(#170): generally support Ethereum tests
#[test]
fn test_eip_1559_tx_encoding_decoding() {
let secret_key = exmaple_signer().secret_key;
let secret_key = example_signer().secret_key;
let transaction = example_transaction();

let signed_tx = test_utils::sign_eip_1559_transaction(transaction, &secret_key);
Expand Down Expand Up @@ -52,7 +52,7 @@ fn test_eip_1559_tx_encoding_decoding() {
#[test]
fn test_eip_1559_example() {
let mut runner = test_utils::deploy_evm();
let mut signer = exmaple_signer();
let mut signer = example_signer();
let signer_address = test_utils::address_from_secret_key(&signer.secret_key);
let contract_address = test_utils::address_from_hex(CONTRACT_ADDRESS);
let contract_code = hex::decode(CONTRACT_CODE).unwrap();
Expand Down Expand Up @@ -112,7 +112,7 @@ fn encode_tx(signed_tx: &SignedTransaction1559) -> Vec<u8> {
.collect()
}

fn exmaple_signer() -> test_utils::Signer {
fn example_signer() -> test_utils::Signer {
let secret_key =
libsecp256k1::SecretKey::parse_slice(&hex::decode(SECRET_KEY).unwrap()).unwrap();

Expand Down
Loading

0 comments on commit 3753523

Please sign in to comment.