Skip to content

Commit

Permalink
Release 2.2.0. (#340)
Browse files Browse the repository at this point in the history
* Test asserting we do not change the engine state binary format (#333)
* Introduce data structure for validated NEAR account IDs (#318)
* Fix(eth-connector): Allow 0x prefix on deposit recipient (#337)

Co-authored-by: Evgeny Ukhanov <evgeny@aurora.dev>
Co-authored-by: Joshua J. Bouw <joshua@aurora.dev>
  • Loading branch information
3 people authored Nov 10, 2021
1 parent c4f4edb commit d020887
Show file tree
Hide file tree
Showing 22 changed files with 738 additions and 194 deletions.
9 changes: 8 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.2.0] - 2021-11-09

### Added

- Depositing ETH from Ethereum to Aurora now allows an `0x` prefix on the recipient address by [@joshuajbouw]. ([#337](https://github.com/aurora-is-near/aurora-engine/pull/337))

## [2.1.0] - 2021-11-04

### Fixed
Expand Down Expand Up @@ -139,7 +145,8 @@ struct SubmitResult {

## [1.0.0] - 2021-05-12

[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/2.1.0...master
[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/2.2.0...master
[2.2.0]: https://github.com/aurora-is-near/aurora-engine/compare/2.1.0...2.2.0
[2.1.0]: https://github.com/aurora-is-near/aurora-engine/compare/2.0.2...2.1.0
[2.0.2]: https://github.com/aurora-is-near/aurora-engine/compare/2.0.1...2.0.2
[2.0.1]: https://github.com/aurora-is-near/aurora-engine/compare/2.0.0...2.0.1
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ documentation.

Network | Contract ID | Chain ID | Version
------- | ------------------- | ---------- | ------
Mainnet | [`aurora`][Mainnet] | 1313161554 | 2.1.0
Testnet | [`aurora`][Testnet] | 1313161555 | 2.1.0
Betanet | [`aurora`][Betanet] | 1313161556 | 2.1.0
Local | `aurora.test.near` | 1313161556 | 2.1.0
Mainnet | [`aurora`][Mainnet] | 1313161554 | 2.2.0
Testnet | [`aurora`][Testnet] | 1313161555 | 2.2.0
Betanet | [`aurora`][Betanet] | 1313161556 | 2.2.0
Local | `aurora.test.near` | 1313161556 | 2.2.0

[Mainnet]: https://explorer.near.org/accounts/aurora
[Testnet]: https://explorer.testnet.near.org/accounts/aurora
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
2.2.0
25 changes: 11 additions & 14 deletions engine-precompiles/src/native.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use super::{EvmPrecompileResult, Precompile};
#[cfg(feature = "contract")]
use crate::prelude::{
format, is_valid_account_id,
format,
parameters::{PromiseCreateArgs, WithdrawCallArgs},
sdk,
storage::{bytes_to_key, KeyPrefix},
types::AccountId,
vec, BorshSerialize, Cow, String, ToString, TryInto, Vec, H160, U256,
vec, AccountId, BorshSerialize, Cow, String, ToString, TryFrom, TryInto, Vec, H160, U256,
};

use crate::prelude::Address;
Expand Down Expand Up @@ -193,9 +192,9 @@ impl ExitToNear {

#[cfg(feature = "contract")]
fn get_nep141_from_erc20(erc20_token: &[u8]) -> AccountId {
AccountId::from_utf8(
sdk::read_storage(bytes_to_key(KeyPrefix::Erc20Nep141Map, erc20_token).as_slice())
.expect(ERR_TARGET_TOKEN_NOT_FOUND),
AccountId::try_from(
&sdk::read_storage(bytes_to_key(KeyPrefix::Erc20Nep141Map, erc20_token).as_slice())
.expect(ERR_TARGET_TOKEN_NOT_FOUND)[..],
)
.unwrap()
}
Expand Down Expand Up @@ -253,10 +252,9 @@ impl Precompile for ExitToNear {
// Input slice format:
// recipient_account_id (bytes) - the NEAR recipient account which will receive NEP-141 ETH tokens

if is_valid_account_id(input) {
let dest_account = String::from_utf8(input.to_vec()).unwrap();
if let Ok(dest_account) = AccountId::try_from(input) {
(
String::from_utf8(sdk::current_account_id()).unwrap(),
AccountId::try_from(sdk::current_account_id()).unwrap(),
// There is no way to inject json, given the encoding of both arguments
// as decimal and valid account id respectively.
format!(
Expand All @@ -267,7 +265,7 @@ impl Precompile for ExitToNear {
events::ExitToNear {
sender: context.caller,
erc20_address: events::ETH_ADDRESS,
dest: dest_account,
dest: dest_account.to_string(),
amount: context.apparent_value,
},
)
Expand Down Expand Up @@ -298,8 +296,7 @@ impl Precompile for ExitToNear {
let amount = U256::from_big_endian(&input[..32]);
input = &input[32..];

if is_valid_account_id(input) {
let receiver_account_id: AccountId = String::from_utf8(input.to_vec()).unwrap();
if let Ok(receiver_account_id) = AccountId::try_from(input) {
(
nep141_address,
// There is no way to inject json, given the encoding of both arguments
Expand All @@ -312,7 +309,7 @@ impl Precompile for ExitToNear {
events::ExitToNear {
sender: erc20_address,
erc20_address,
dest: receiver_account_id,
dest: receiver_account_id.to_string(),
amount,
},
)
Expand Down Expand Up @@ -421,7 +418,7 @@ impl Precompile for ExitToEthereum {
.try_into()
.map_err(|_| ExitError::Other(Cow::from("ERR_INVALID_RECIPIENT_ADDRESS")))?;
(
String::from_utf8(sdk::current_account_id()).unwrap(),
AccountId::try_from(sdk::current_account_id()).unwrap(),
// There is no way to inject json, given the encoding of both arguments
// as decimal and hexadecimal respectively.
WithdrawCallArgs {
Expand Down
1 change: 1 addition & 0 deletions engine-precompiles/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub use aurora_engine_sdk as sdk;
pub use aurora_engine_types::account_id::*;
pub use aurora_engine_types::parameters;
pub use aurora_engine_types::storage;
pub use aurora_engine_types::types;
Expand Down
16 changes: 11 additions & 5 deletions engine-tests/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aurora_engine_types::account_id::AccountId;
use borsh::{BorshDeserialize, BorshSerialize};
use near_primitives_core::config::VMConfig;
use near_primitives_core::contract::ContractCode;
Expand All @@ -18,12 +19,12 @@ use crate::prelude::transaction::{
access_list::{self, AccessListEthSignedTransaction, AccessListEthTransaction},
LegacyEthSignedTransaction, LegacyEthTransaction,
};
use crate::prelude::{sdk, AccountId, Address, Wei, U256};
use crate::prelude::{sdk, Address, Wei, U256};
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() -> AccountId {
pub fn origin() -> String {
"aurora".to_string()
}

Expand Down Expand Up @@ -440,8 +441,8 @@ pub(crate) fn deploy_evm() -> AuroraRunner {
let mut runner = AuroraRunner::default();
let args = NewCallArgs {
chain_id: crate::prelude::u256_to_arr(&U256::from(runner.chain_id)),
owner_id: runner.aurora_account_id.clone(),
bridge_prover_id: "bridge_prover.near".to_string(),
owner_id: str_to_account_id(runner.aurora_account_id.as_str()),
bridge_prover_id: str_to_account_id("bridge_prover.near"),
upgrade_delay_blocks: 1,
};

Expand All @@ -451,7 +452,7 @@ pub(crate) fn deploy_evm() -> AuroraRunner {
assert!(maybe_error.is_none());

let args = InitCallArgs {
prover_account: "prover.near".to_string(),
prover_account: str_to_account_id("prover.near"),
eth_custodian_address: "d045f7e19B2488924B97F9c145b5E51D0D895A65".to_string(),
metadata: FungibleTokenMetadata::default(),
};
Expand Down Expand Up @@ -625,6 +626,11 @@ pub(crate) fn as_account_id(account_id: &str) -> near_primitives_core::types::Ac
account_id.parse().unwrap()
}

pub(crate) fn str_to_account_id(account_id: &str) -> AccountId {
use aurora_engine_types::str::FromStr;
AccountId::from_str(account_id).unwrap()
}

pub fn unwrap_success(result: SubmitResult) -> Vec<u8> {
match result.status {
TransactionStatus::Succeed(ret) => ret,
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/contract_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn withdraw() {
let exit_events = parse_exit_events(withdraw_result, &schema);

// One exit event
assert!(exit_events.len() == 1);
assert_eq!(exit_events.len(), 1);

let dest = if is_to_near {
// transferred to "target.aurora" (defined in Tester.sol)
Expand Down
33 changes: 12 additions & 21 deletions engine-tests/src/tests/erc20_connector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::prelude::{AccountId, Address, Balance, RawAddress, TryInto, Wei, U256};
use crate::prelude::{Address, Balance, RawAddress, TryInto, Wei, U256};
use crate::test_utils;
use crate::test_utils::{create_eth_transaction, origin, AuroraRunner};
use aurora_engine::parameters::{FunctionCallArgs, SubmitResult};
Expand Down Expand Up @@ -91,28 +91,19 @@ impl test_utils::AuroraRunner {
CallResult { outcome, error }
}

pub fn evm_call(
&mut self,
contract: RawAddress,
input: Vec<u8>,
origin: AccountId,
) -> CallResult {
pub fn evm_call(&mut self, contract: RawAddress, input: Vec<u8>, origin: String) -> CallResult {
self.make_call(
"call",
origin,
(FunctionCallArgs { contract, input }).try_to_vec().unwrap(),
)
}

pub fn evm_submit(
&mut self,
input: LegacyEthSignedTransaction,
origin: AccountId,
) -> CallResult {
pub fn evm_submit(&mut self, input: LegacyEthSignedTransaction, origin: String) -> CallResult {
self.make_call("submit", origin, rlp::encode(&input).to_vec())
}

pub fn deploy_erc20_token(&mut self, nep141: &AccountId) -> RawAddress {
pub fn deploy_erc20_token(&mut self, nep141: &String) -> RawAddress {
let result = self.make_call("deploy_erc20_token", origin(), nep141.try_to_vec().unwrap());

result.check_ok();
Expand All @@ -134,7 +125,7 @@ impl test_utils::AuroraRunner {
}
}

pub fn balance_of(&mut self, token: RawAddress, target: RawAddress, origin: AccountId) -> U256 {
pub fn balance_of(&mut self, token: RawAddress, target: RawAddress, origin: String) -> U256 {
let input = build_input("balanceOf(address)", &[Token::Address(target.into())]);
let result = self.evm_call(token, input, origin);
result.check_ok();
Expand All @@ -147,7 +138,7 @@ impl test_utils::AuroraRunner {
token: RawAddress,
target: RawAddress,
amount: u64,
origin: AccountId,
origin: String,
) -> CallResult {
let input = build_input(
"mint(address,uint256)",
Expand All @@ -162,7 +153,7 @@ impl test_utils::AuroraRunner {
}

#[allow(dead_code)]
pub fn admin(&mut self, token: RawAddress, origin: AccountId) -> CallResult {
pub fn admin(&mut self, token: RawAddress, origin: String) -> CallResult {
let input = build_input("admin()", &[]);
let result = self.evm_call(token, input, origin);
result.check_ok();
Expand All @@ -175,7 +166,7 @@ impl test_utils::AuroraRunner {
sender: SecretKey,
receiver: RawAddress,
amount: u64,
origin: AccountId,
origin: String,
) -> CallResult {
// transfer(address recipient, uint256 amount)
let input = build_input(
Expand All @@ -195,9 +186,9 @@ impl test_utils::AuroraRunner {

pub fn ft_on_transfer(
&mut self,
nep141: AccountId,
sender_id: AccountId,
relayer_id: AccountId,
nep141: String,
sender_id: String,
relayer_id: String,
amount: Balance,
msg: String,
) -> String {
Expand All @@ -219,7 +210,7 @@ impl test_utils::AuroraRunner {

pub fn register_relayer(
&mut self,
relayer_account_id: AccountId,
relayer_account_id: String,
relayer_address: Address,
) -> CallResult {
self.make_call(
Expand Down
77 changes: 74 additions & 3 deletions engine-tests/src/tests/eth_connector.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::prelude::EthAddress;
use crate::prelude::WithdrawCallArgs;
use crate::prelude::U256;
use crate::test_utils::str_to_account_id;
use aurora_engine::admin_controlled::{PausedMask, ERR_PAUSED};
use aurora_engine::connector::{
ERR_NOT_ENOUGH_BALANCE_FOR_FEE, PAUSE_DEPOSIT, PAUSE_WITHDRAW, UNPAUSE_ALL,
Expand Down Expand Up @@ -68,8 +69,8 @@ fn init_contract(
"new",
&NewCallArgs {
chain_id: [0u8; 32],
owner_id: master_account.account_id.clone().into(),
bridge_prover_id: accounts(0).to_string(),
owner_id: str_to_account_id(master_account.account_id.clone().as_str()),
bridge_prover_id: str_to_account_id(accounts(0).as_str()),
upgrade_delay_blocks: 1,
}
.try_to_vec()
Expand All @@ -83,7 +84,7 @@ fn init_contract(
contract_name.parse().unwrap(),
"new_eth_connector",
&InitCallArgs {
prover_account: PROVER_ACCOUNT.into(),
prover_account: str_to_account_id(PROVER_ACCOUNT.into()),
eth_custodian_address: custodian_address.into(),
metadata: FungibleTokenMetadata::default(),
}
Expand Down Expand Up @@ -589,6 +590,76 @@ fn test_ft_transfer_call_without_message() {
assert_eq!(balance, 0);
}

#[test]
fn test_deposit_with_0x_prefix() {
let (master_account, contract) = init(CUSTODIAN_ADDRESS);

let eth_custodian_address: [u8; 20] = {
let mut buf = [0u8; 20];
let bytes = hex::decode(CUSTODIAN_ADDRESS).unwrap();
buf.copy_from_slice(&bytes);
buf
};
let recipient_address = [10u8; 20];
let deposit_amount = U256::from(17);
let deposit_event = aurora_engine::deposit_event::DepositedEvent {
eth_custodian_address,
sender: [0u8; 20],
// Note the 0x prefix before the deposit address.
recipient: [
CONTRACT_ACC,
":",
"0x",
hex::encode(&recipient_address).as_str(),
]
.concat(),
amount: deposit_amount,
fee: U256::zero(),
};

let event_schema = ethabi::Event {
name: aurora_engine::deposit_event::DEPOSITED_EVENT.into(),
inputs: aurora_engine::deposit_event::DepositedEvent::event_params(),
anonymous: false,
};
let log_entry = aurora_engine::log_entry::LogEntry {
address: eth_custodian_address.into(),
topics: vec![
event_schema.signature(),
// the sender is not important
crate::prelude::H256::zero(),
],
data: ethabi::encode(&[
ethabi::Token::String(deposit_event.recipient),
ethabi::Token::Uint(deposit_event.amount),
ethabi::Token::Uint(deposit_event.fee),
]),
};
let proof = Proof {
log_index: 1,
// Only this field matters for the purpose of this test
log_entry_data: rlp::encode(&log_entry).to_vec(),
receipt_index: 1,
receipt_data: Vec::new(),
header_data: Vec::new(),
proof: Vec::new(),
};

let res = master_account.call(
contract.account_id(),
"deposit",
&proof.try_to_vec().unwrap(),
DEFAULT_GAS,
0,
);
res.assert_success();

let aurora_balance = get_eth_on_near_balance(&master_account, CONTRACT_ACC, CONTRACT_ACC);
assert_eq!(aurora_balance, deposit_amount.low_u128());
let address_balance = get_eth_balance(&master_account, recipient_address, CONTRACT_ACC);
assert_eq!(address_balance, deposit_amount.low_u128());
}

#[test]
fn test_deposit_with_same_proof() {
let (_master_account, contract) = init(CUSTODIAN_ADDRESS);
Expand Down
Loading

0 comments on commit d020887

Please sign in to comment.