From 29c88633ffe117ae976e667dded3af75f2186496 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 8 Sep 2020 18:10:37 -0700 Subject: [PATCH 01/61] initial gas used in evm interpreter --- runtime/near-evm-runner/src/interpreter.rs | 46 ++++++++++++++++------ 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index 7f2a45040eb..e0d9ea4e1fb 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -11,6 +11,8 @@ use crate::near_ext::NearExt; use crate::types::Result; use crate::utils; +const PREPAID_GAS: u128 = 1_000_000_000_000; + pub fn deploy_code( state: &mut T, origin: &Address, @@ -39,12 +41,20 @@ pub fn deploy_code( // Apply known gas amount changes (all reverts are NeedsReturn) // Apply NeedsReturn changes if apply_state // Return the result unmodified + let gas_used: U256; let (return_data, apply) = match result { - Some(GasLeft::Known(_)) => (ReturnData::empty(), true), - Some(GasLeft::NeedsReturn { gas_left: _, data, apply_state }) => (data, apply_state), + Some(GasLeft::Known(gas_left)) => { + gas_used = U256::from(PREPAID_GAS) - gas_left; + (ReturnData::empty(), true) + }, + Some(GasLeft::NeedsReturn { gas_left, data, apply_state }) => { + gas_used = U256::from(PREPAID_GAS) - gas_left; + (data, apply_state) + }, _ => return Err(VMLogicError::EvmError(EvmError::UnknownError)), }; + println!("Gas used in deploy_code: {}", gas_used); if apply { state.commit_changes(&state_updates.unwrap())?; state.set_code(&address, &return_data.to_vec())?; @@ -74,7 +84,7 @@ pub fn _create( sender: *sender, origin: *origin, // TODO: gas usage. - gas: 1_000_000_000.into(), + gas: PREPAID_GAS.into(), gas_price: 1.into(), value: ActionValue::Transfer(value), code: Some(Arc::new(code.to_vec())), @@ -88,7 +98,7 @@ pub fn _create( let mut ext = NearExt::new(*address, *origin, &mut sub_state, call_stack_depth + 1, false); // TODO: gas usage. - ext.info.gas_limit = U256::from(1_000_000_000); + ext.info.gas_limit = U256::from(PREPAID_GAS); ext.schedule = Schedule::new_constantinople(); let instance = Factory::default().create(params, ext.schedule(), ext.depth()); @@ -203,14 +213,28 @@ fn run_and_commit_if_success( // Apply known gas amount changes (all reverts are NeedsReturn) // Apply NeedsReturn changes if apply_state // Return the result unmodified + let gas_used: U256; let return_data = match result { - Some(GasLeft::Known(_)) => Ok(ReturnData::empty()), - Some(GasLeft::NeedsReturn { gas_left: _, data, apply_state: true }) => Ok(data), - Some(GasLeft::NeedsReturn { gas_left: _, data, apply_state: false }) => { + Some(GasLeft::Known(gas_left)) => { + println!("-=-=-= {} {}", PREPAID_GAS, gas_left); + gas_used = U256::from(PREPAID_GAS) - gas_left; + Ok(ReturnData::empty()) + }, + Some(GasLeft::NeedsReturn { gas_left, data, apply_state: true }) => { + println!("-=-=-= {} {}", PREPAID_GAS, gas_left); + + gas_used = U256::from(PREPAID_GAS) - gas_left; + Ok(data) + }, + Some(GasLeft::NeedsReturn { gas_left, data, apply_state: false }) => { + println!("-=-=-= {} {}", PREPAID_GAS, gas_left); + + gas_used = U256::from(PREPAID_GAS) - gas_left; Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) - } - _ => Err(VMLogicError::EvmError(EvmError::UnknownError)), + }, + _ => return Err(VMLogicError::EvmError(EvmError::UnknownError)), }; + println!("Gas used in run_and_commit_if_success: {}", gas_used); // Don't apply changes from a static context (these _should_ error in the ext) if !is_static && return_data.is_ok() && should_commit { @@ -246,7 +270,7 @@ fn run_against_state( sender: *sender, origin: *origin, // TODO: gas usage. - gas: 1_000_000_000.into(), + gas: PREPAID_GAS.into(), gas_price: 1.into(), value: ActionValue::Apparent(0.into()), code: Some(Arc::new(code)), @@ -264,7 +288,7 @@ fn run_against_state( let mut ext = NearExt::new(*state_address, *origin, &mut sub_state, call_stack_depth + 1, is_static); // TODO: gas usage. - ext.info.gas_limit = U256::from(1_000_000_000); + ext.info.gas_limit = U256::from(PREPAID_GAS); ext.schedule = Schedule::new_constantinople(); let instance = Factory::default().create(params, ext.schedule(), ext.depth()); From 6b02f23e510a6197ad293387c661908541f978e3 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 8 Sep 2020 18:15:11 -0700 Subject: [PATCH 02/61] see what case in result --- runtime/near-evm-runner/src/interpreter.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index e0d9ea4e1fb..c648598a154 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -216,19 +216,17 @@ fn run_and_commit_if_success( let gas_used: U256; let return_data = match result { Some(GasLeft::Known(gas_left)) => { - println!("-=-=-= {} {}", PREPAID_GAS, gas_left); + println!("Known {} {}", PREPAID_GAS, gas_left); gas_used = U256::from(PREPAID_GAS) - gas_left; Ok(ReturnData::empty()) }, Some(GasLeft::NeedsReturn { gas_left, data, apply_state: true }) => { - println!("-=-=-= {} {}", PREPAID_GAS, gas_left); - + println!("NeedsReturn, apply_state: true {} {}", PREPAID_GAS, gas_left); gas_used = U256::from(PREPAID_GAS) - gas_left; Ok(data) }, Some(GasLeft::NeedsReturn { gas_left, data, apply_state: false }) => { - println!("-=-=-= {} {}", PREPAID_GAS, gas_left); - + println!("NeedsReturn, apply_state: false {} {}", PREPAID_GAS, gas_left); gas_used = U256::from(PREPAID_GAS) - gas_left; Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) }, From 7917573223b7dbe0edaa4e3c322fbf3d65ddead7 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Thu, 10 Sep 2020 18:41:44 -0700 Subject: [PATCH 03/61] atempt of return different gas left --- runtime/near-evm-runner/src/interpreter.rs | 90 ++++++++++++------- runtime/near-evm-runner/src/lib.rs | 15 ++-- runtime/near-evm-runner/src/near_ext.rs | 24 +++-- runtime/near-evm-runner/tests/standard_ops.rs | 1 + rust-toolchain | 2 +- 5 files changed, 85 insertions(+), 47 deletions(-) diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index c648598a154..a27e5736764 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use ethereum_types::{Address, U256}; -use evm::{CreateContractAddress, Factory}; +use evm::{CreateContractAddress, Factory, Finalize}; use vm::{ActionParams, ActionValue, CallType, Ext, GasLeft, ParamsType, ReturnData, Schedule}; use near_vm_errors::{EvmError, VMLogicError}; @@ -11,7 +11,7 @@ use crate::near_ext::NearExt; use crate::types::Result; use crate::utils; -const PREPAID_GAS: u128 = 1_000_000_000_000; +pub const PREPAID_EVM_GAS: u128 = 1_000_000_000; pub fn deploy_code( state: &mut T, @@ -22,7 +22,7 @@ pub fn deploy_code( address_type: CreateContractAddress, recreate: bool, code: &[u8], -) -> Result
{ +) -> Result<(Address, U256)> { let mut nonce = U256::default(); if address_type == CreateContractAddress::FromSenderAndNonce { nonce = state.next_nonce(&sender)?; @@ -42,15 +42,20 @@ pub fn deploy_code( // Apply NeedsReturn changes if apply_state // Return the result unmodified let gas_used: U256; + let left: U256; let (return_data, apply) = match result { Some(GasLeft::Known(gas_left)) => { - gas_used = U256::from(PREPAID_GAS) - gas_left; + left = gas_left; + gas_used = U256::from(PREPAID_EVM_GAS) - gas_left; + println!("Known {} {}", PREPAID_EVM_GAS, gas_left); (ReturnData::empty(), true) - }, + } Some(GasLeft::NeedsReturn { gas_left, data, apply_state }) => { - gas_used = U256::from(PREPAID_GAS) - gas_left; + gas_used = U256::from(PREPAID_EVM_GAS) - gas_left; + left = gas_left; + println!("NeedsReturn, apply_state: {} {} {}", apply_state, PREPAID_EVM_GAS, gas_left); (data, apply_state) - }, + } _ => return Err(VMLogicError::EvmError(EvmError::UnknownError)), }; @@ -63,7 +68,7 @@ pub fn deploy_code( return_data.to_vec(), )))); } - Ok(address) + Ok((address, left)) } pub fn _create( @@ -75,6 +80,7 @@ pub fn _create( address: &Address, code: &[u8], ) -> Result<(Option, Option)> { + println!("enter _create"); let mut store = StateStore::default(); let mut sub_state = SubState::new(sender, &mut store, state); @@ -84,7 +90,7 @@ pub fn _create( sender: *sender, origin: *origin, // TODO: gas usage. - gas: PREPAID_GAS.into(), + gas: PREPAID_EVM_GAS.into(), gas_price: 1.into(), value: ActionValue::Transfer(value), code: Some(Arc::new(code.to_vec())), @@ -98,14 +104,14 @@ pub fn _create( let mut ext = NearExt::new(*address, *origin, &mut sub_state, call_stack_depth + 1, false); // TODO: gas usage. - ext.info.gas_limit = U256::from(PREPAID_GAS); + ext.info.gas_limit = U256::from(PREPAID_EVM_GAS); ext.schedule = Schedule::new_constantinople(); let instance = Factory::default().create(params, ext.schedule(), ext.depth()); // Run the code let result = instance.exec(&mut ext); - + println!("leave _create"); Ok((result.ok().unwrap().ok(), Some(store))) } @@ -119,8 +125,12 @@ pub fn call( contract_address: &Address, input: &[u8], should_commit: bool, -) -> Result { - run_and_commit_if_success( +) -> Result<(ReturnData, U256)> { + println!( + "enter interpreter::call {:?} {:?} {:?} {:?} {:?} {:?} {:?}", + origin, sender, value, call_stack_depth, contract_address, input, should_commit + ); + let r = run_and_commit_if_success( state, origin, sender, @@ -132,7 +142,9 @@ pub fn call( input, false, should_commit, - ) + ); + println!("leave interpreter::call {:?}", r); + r } pub fn delegate_call( @@ -143,7 +155,7 @@ pub fn delegate_call( context: &Address, delegee: &Address, input: &[u8], -) -> Result { +) -> Result<(ReturnData, U256)> { run_and_commit_if_success( state, origin, @@ -166,7 +178,7 @@ pub fn static_call( call_stack_depth: usize, contract_address: &Address, input: &[u8], -) -> Result { +) -> Result<(ReturnData, U256)> { run_and_commit_if_success( state, origin, @@ -195,8 +207,9 @@ fn run_and_commit_if_success( input: &[u8], is_static: bool, should_commit: bool, -) -> Result { +) -> Result<(ReturnData, U256)> { // run the interpreter and + println!("enter run_and_commit_if_success"); let (result, state_updates) = run_against_state( state, origin, @@ -214,31 +227,34 @@ fn run_and_commit_if_success( // Apply NeedsReturn changes if apply_state // Return the result unmodified let gas_used: U256; + let left: U256; let return_data = match result { Some(GasLeft::Known(gas_left)) => { - println!("Known {} {}", PREPAID_GAS, gas_left); - gas_used = U256::from(PREPAID_GAS) - gas_left; - Ok(ReturnData::empty()) - }, + println!("Known {} {}", PREPAID_EVM_GAS, gas_left); + left = gas_left; + gas_used = U256::from(PREPAID_EVM_GAS) - gas_left; + Ok((ReturnData::empty(), left)) + } Some(GasLeft::NeedsReturn { gas_left, data, apply_state: true }) => { - println!("NeedsReturn, apply_state: true {} {}", PREPAID_GAS, gas_left); - gas_used = U256::from(PREPAID_GAS) - gas_left; - Ok(data) - }, + println!("NeedsReturn, apply_state: true {} {}", PREPAID_EVM_GAS, gas_left); + gas_used = U256::from(PREPAID_EVM_GAS) - gas_left; + left = gas_left; + Ok((data, left)) + } Some(GasLeft::NeedsReturn { gas_left, data, apply_state: false }) => { - println!("NeedsReturn, apply_state: false {} {}", PREPAID_GAS, gas_left); - gas_used = U256::from(PREPAID_GAS) - gas_left; + println!("NeedsReturn, apply_state: false {} {}", PREPAID_EVM_GAS, gas_left); + gas_used = U256::from(PREPAID_EVM_GAS) - gas_left; + left = gas_left; Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) - }, - _ => return Err(VMLogicError::EvmError(EvmError::UnknownError)), + } + x => return Err(VMLogicError::EvmError(EvmError::UnknownError)), }; println!("Gas used in run_and_commit_if_success: {}", gas_used); - // Don't apply changes from a static context (these _should_ error in the ext) if !is_static && return_data.is_ok() && should_commit { state.commit_changes(&state_updates.unwrap())?; } - + println!("leave run_and_commit_if_success {:?}", return_data); return_data } @@ -256,6 +272,7 @@ fn run_against_state( input: &[u8], is_static: bool, ) -> Result<(Option, Option)> { + println!("enter run_against_state"); let code = state.code_at(code_address)?.unwrap_or_else(Vec::new); let mut store = StateStore::default(); @@ -268,7 +285,7 @@ fn run_against_state( sender: *sender, origin: *origin, // TODO: gas usage. - gas: PREPAID_GAS.into(), + gas: PREPAID_EVM_GAS.into(), gas_price: 1.into(), value: ActionValue::Apparent(0.into()), code: Some(Arc::new(code)), @@ -286,12 +303,17 @@ fn run_against_state( let mut ext = NearExt::new(*state_address, *origin, &mut sub_state, call_stack_depth + 1, is_static); // TODO: gas usage. - ext.info.gas_limit = U256::from(PREPAID_GAS); + // Gas limit is evm block gas limit, should at least prepaid gas. + ext.info.gas_limit = U256::from(PREPAID_EVM_GAS); ext.schedule = Schedule::new_constantinople(); let instance = Factory::default().create(params, ext.schedule(), ext.depth()); // Run the code + println!("before instance.exec"); let result = instance.exec(&mut ext); - Ok((result.ok().unwrap().ok(), Some(store))) + println!("after instance.exec"); + let r = result.ok(); + println!("leave run_against_state {:?}", &r); + Ok((r.unwrap().ok(), Some(store))) } diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 61b5d458426..5a7b41ff46e 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -144,7 +144,7 @@ impl<'a> EvmContext<'a> { pub fn deploy_code(&mut self, bytecode: Vec) -> Result
{ let sender = utils::near_account_id_to_evm_address(&self.predecessor_id); self.add_balance(&sender, U256::from(self.attached_deposit))?; - interpreter::deploy_code( + let r = interpreter::deploy_code( self, &sender, &sender, @@ -153,10 +153,12 @@ impl<'a> EvmContext<'a> { CreateContractAddress::FromSenderAndNonce, false, &bytecode, - ) + )?; + Ok(r.0) } pub fn call_function(&mut self, args: Vec) -> Result> { + println!("enter call_function"); if args.len() <= 20 { return Err(VMLogicError::EvmError(EvmError::ArgumentParseError)); } @@ -166,8 +168,11 @@ impl<'a> EvmContext<'a> { self.add_balance(&sender, U256::from(self.attached_deposit))?; let value = if self.attached_deposit == 0 { None } else { Some(U256::from(self.attached_deposit)) }; - interpreter::call(self, &sender, &sender, value, 0, &contract_address, &input, true) - .map(|rd| rd.to_vec()) + let r = + interpreter::call(self, &sender, &sender, value, 0, &contract_address, &input, true) + .map(|rd| rd.0.to_vec()); + println!("leave call_function"); + r } /// Make an EVM transaction. Calls `contract_address` with `encoded_input`. Execution @@ -189,7 +194,7 @@ impl<'a> EvmContext<'a> { &args.args, false, ) - .map(|rd| rd.to_vec()) + .map(|rd| rd.0.to_vec()) } pub fn get_code(&self, args: Vec) -> Result> { diff --git a/runtime/near-evm-runner/src/near_ext.rs b/runtime/near-evm-runner/src/near_ext.rs index ef9a849e112..b45946bed4a 100644 --- a/runtime/near-evm-runner/src/near_ext.rs +++ b/runtime/near-evm-runner/src/near_ext.rs @@ -13,6 +13,9 @@ use near_vm_errors::{EvmError, VMLogicError}; use crate::evm_state::{EvmState, SubState}; use crate::interpreter; +// use crate::interpreter::PREPAID_EVM_GAS; +pub const PREPAID_EVM_GAS: u128 = 0; + use crate::utils::format_log; // https://github.com/paritytech/parity-ethereum/blob/77643c13e80ca09d9a6b10631034f5a1568ba6d3/ethcore/machine/src/externalities.rs @@ -123,19 +126,21 @@ impl<'a> vm::Ext for NearExt<'a> { fn create( &mut self, - _gas: &U256, + gas: &U256, value: &U256, code: &[u8], address_type: CreateContractAddress, _trap: bool, ) -> Result { + println!("enter NearExt.create {:?}", gas); if self.is_static() { + println!("leave NearExt.create {:?}", gas); return Err(TrapKind::Call(ActionParams::default())); } // TODO: better error propagation. // TODO: gas metering. - interpreter::deploy_code( + let r = interpreter::deploy_code( self.sub_state, &self.origin, &self.context_addr, @@ -146,8 +151,10 @@ impl<'a> vm::Ext for NearExt<'a> { &code.to_vec(), ) // TODO: gas usage. - .map(|result| ContractCreateResult::Created(result, 1_000_000_000.into())) - .map_err(|_| TrapKind::Call(ActionParams::default())) + .map(|(result, gas_left)| ContractCreateResult::Created(result, PREPAID_EVM_GAS.into())) + .map_err(|_| TrapKind::Call(ActionParams::default())); + println!("leave NearExt.create {:?}", gas); + r } /// Message call. @@ -157,7 +164,7 @@ impl<'a> vm::Ext for NearExt<'a> { /// and true if subcall was successful. fn call( &mut self, - _gas: &U256, + gas: &U256, sender_address: &Address, receive_address: &Address, value: Option, @@ -166,12 +173,14 @@ impl<'a> vm::Ext for NearExt<'a> { call_type: CallType, _trap: bool, ) -> Result { + println!("enter NearExt.call {:?}", gas); if self.is_static() && call_type != CallType::StaticCall { panic!("MutableCallInStaticContext") } // hijack builtins if crate::builtins::is_precompile(receive_address) { + println!("leave NearExt.call {:?} precompile", gas); return Ok(crate::builtins::process_precompile(receive_address, data)); } @@ -215,7 +224,7 @@ impl<'a> vm::Ext for NearExt<'a> { let msg_call_result = match result { // TODO: gas usage. - Ok(data) => MessageCallResult::Success(1_000_000_000.into(), data), + Ok((data, gas_left)) => MessageCallResult::Success(PREPAID_EVM_GAS.into(), data), Err(err) => { let message = match err { VMLogicError::EvmError(EvmError::Revert(encoded_message)) => { @@ -226,11 +235,12 @@ impl<'a> vm::Ext for NearExt<'a> { let message_len = message.len(); // TODO: gas usage. MessageCallResult::Reverted( - 1_000_000_000.into(), + PREPAID_EVM_GAS.into(), ReturnData::new(message, 0, message_len), ) } }; + println!("leave NearExt.call {:?}", gas); Ok(msg_call_result) } diff --git a/runtime/near-evm-runner/tests/standard_ops.rs b/runtime/near-evm-runner/tests/standard_ops.rs index de2e86a981a..ac5252e8ed2 100644 --- a/runtime/near-evm-runner/tests/standard_ops.rs +++ b/runtime/near-evm-runner/tests/standard_ops.rs @@ -109,6 +109,7 @@ fn test_internal_create() { let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); assert_eq!(context.get_nonce(test_addr.0.to_vec()).unwrap(), U256::from(1)); + println!("=========="); let sub_addr = address_from_arr(&raw[12..32]); let (new_input, _) = subcontract::functions::a_number::call(); let new_raw = context.call_function(encode_call_function_args(sub_addr, new_input)).unwrap(); diff --git a/rust-toolchain b/rust-toolchain index 8737a7eb567..a36829b681f 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2020-05-15 +nightly-2020-08-26 From 981e7c16bc01c60f9935487d1fd42491dde077cd Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Thu, 10 Sep 2020 19:07:53 -0700 Subject: [PATCH 04/61] gas_left --- runtime/near-evm-runner/src/near_ext.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/near-evm-runner/src/near_ext.rs b/runtime/near-evm-runner/src/near_ext.rs index b45946bed4a..eff4f76ff91 100644 --- a/runtime/near-evm-runner/src/near_ext.rs +++ b/runtime/near-evm-runner/src/near_ext.rs @@ -151,7 +151,7 @@ impl<'a> vm::Ext for NearExt<'a> { &code.to_vec(), ) // TODO: gas usage. - .map(|(result, gas_left)| ContractCreateResult::Created(result, PREPAID_EVM_GAS.into())) + .map(|(result, gas_left)| ContractCreateResult::Created(result, gas_left)) .map_err(|_| TrapKind::Call(ActionParams::default())); println!("leave NearExt.create {:?}", gas); r @@ -224,7 +224,7 @@ impl<'a> vm::Ext for NearExt<'a> { let msg_call_result = match result { // TODO: gas usage. - Ok((data, gas_left)) => MessageCallResult::Success(PREPAID_EVM_GAS.into(), data), + Ok((data, gas_left)) => MessageCallResult::Success(gas_left, data), Err(err) => { let message = match err { VMLogicError::EvmError(EvmError::Revert(encoded_message)) => { From c90e816430d19c5a724208d9fc35ab8e334efc4d Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 11 Sep 2020 12:12:20 -0700 Subject: [PATCH 05/61] all gas metering works --- runtime/near-evm-runner/src/builtins.rs | 4 +- runtime/near-evm-runner/src/interpreter.rs | 49 +++++++++++++--------- runtime/near-evm-runner/src/lib.rs | 19 +++++++-- runtime/near-evm-runner/src/near_ext.rs | 8 +++- 4 files changed, 53 insertions(+), 27 deletions(-) diff --git a/runtime/near-evm-runner/src/builtins.rs b/runtime/near-evm-runner/src/builtins.rs index 8e1c86314dc..6c9ff279e37 100644 --- a/runtime/near-evm-runner/src/builtins.rs +++ b/runtime/near-evm-runner/src/builtins.rs @@ -45,7 +45,7 @@ pub fn precompile(id: u64) -> Result, String> { }) } -pub fn process_precompile(addr: &Address, input: &[u8]) -> MessageCallResult { +pub fn process_precompile(addr: &Address, input: &[u8], gas: &U256) -> MessageCallResult { let f = match precompile(addr.to_low_u64_be()) { Ok(f) => f, Err(_) => return MessageCallResult::Failed, @@ -61,7 +61,7 @@ pub fn process_precompile(addr: &Address, input: &[u8]) -> MessageCallResult { let size = bytes.len(); // TODO: add gas usage here. - MessageCallResult::Success(1_000_000_000.into(), ReturnData::new(bytes, 0, size)) + MessageCallResult::Success(*gas, ReturnData::new(bytes, 0, size)) } /** the following is copied from ethcore/src/builtin.rs **/ diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index a27e5736764..9c5d51ba402 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use ethereum_types::{Address, U256}; -use evm::{CreateContractAddress, Factory, Finalize}; +use evm::{CreateContractAddress, Factory}; use vm::{ActionParams, ActionValue, CallType, Ext, GasLeft, ParamsType, ReturnData, Schedule}; use near_vm_errors::{EvmError, VMLogicError}; @@ -11,8 +11,6 @@ use crate::near_ext::NearExt; use crate::types::Result; use crate::utils; -pub const PREPAID_EVM_GAS: u128 = 1_000_000_000; - pub fn deploy_code( state: &mut T, origin: &Address, @@ -22,6 +20,7 @@ pub fn deploy_code( address_type: CreateContractAddress, recreate: bool, code: &[u8], + gas: &U256, ) -> Result<(Address, U256)> { let mut nonce = U256::default(); if address_type == CreateContractAddress::FromSenderAndNonce { @@ -36,7 +35,7 @@ pub fn deploy_code( } let (result, state_updates) = - _create(state, origin, sender, value, call_stack_depth, &address, code)?; + _create(state, origin, sender, value, call_stack_depth, &address, code, gas)?; // Apply known gas amount changes (all reverts are NeedsReturn) // Apply NeedsReturn changes if apply_state @@ -46,14 +45,14 @@ pub fn deploy_code( let (return_data, apply) = match result { Some(GasLeft::Known(gas_left)) => { left = gas_left; - gas_used = U256::from(PREPAID_EVM_GAS) - gas_left; - println!("Known {} {}", PREPAID_EVM_GAS, gas_left); + gas_used = gas - gas_left; + println!("Known {} {}", gas, gas_left); (ReturnData::empty(), true) } Some(GasLeft::NeedsReturn { gas_left, data, apply_state }) => { - gas_used = U256::from(PREPAID_EVM_GAS) - gas_left; + gas_used = gas - gas_left; left = gas_left; - println!("NeedsReturn, apply_state: {} {} {}", apply_state, PREPAID_EVM_GAS, gas_left); + println!("NeedsReturn, apply_state: {} {} {}", apply_state, gas, gas_left); (data, apply_state) } _ => return Err(VMLogicError::EvmError(EvmError::UnknownError)), @@ -79,6 +78,7 @@ pub fn _create( call_stack_depth: usize, address: &Address, code: &[u8], + gas: &U256, ) -> Result<(Option, Option)> { println!("enter _create"); let mut store = StateStore::default(); @@ -90,7 +90,7 @@ pub fn _create( sender: *sender, origin: *origin, // TODO: gas usage. - gas: PREPAID_EVM_GAS.into(), + gas: *gas, gas_price: 1.into(), value: ActionValue::Transfer(value), code: Some(Arc::new(code.to_vec())), @@ -104,7 +104,7 @@ pub fn _create( let mut ext = NearExt::new(*address, *origin, &mut sub_state, call_stack_depth + 1, false); // TODO: gas usage. - ext.info.gas_limit = U256::from(PREPAID_EVM_GAS); + ext.info.gas_limit = U256::from(gas); ext.schedule = Schedule::new_constantinople(); let instance = Factory::default().create(params, ext.schedule(), ext.depth()); @@ -125,6 +125,7 @@ pub fn call( contract_address: &Address, input: &[u8], should_commit: bool, + gas: &U256, ) -> Result<(ReturnData, U256)> { println!( "enter interpreter::call {:?} {:?} {:?} {:?} {:?} {:?} {:?}", @@ -142,6 +143,7 @@ pub fn call( input, false, should_commit, + gas, ); println!("leave interpreter::call {:?}", r); r @@ -155,6 +157,7 @@ pub fn delegate_call( context: &Address, delegee: &Address, input: &[u8], + gas: &U256, ) -> Result<(ReturnData, U256)> { run_and_commit_if_success( state, @@ -168,6 +171,7 @@ pub fn delegate_call( input, false, true, + gas, ) } @@ -178,6 +182,7 @@ pub fn static_call( call_stack_depth: usize, contract_address: &Address, input: &[u8], + gas: &U256, ) -> Result<(ReturnData, U256)> { run_and_commit_if_success( state, @@ -191,6 +196,7 @@ pub fn static_call( input, true, false, + gas, ) } @@ -207,6 +213,7 @@ fn run_and_commit_if_success( input: &[u8], is_static: bool, should_commit: bool, + gas: &U256, ) -> Result<(ReturnData, U256)> { // run the interpreter and println!("enter run_and_commit_if_success"); @@ -221,6 +228,7 @@ fn run_and_commit_if_success( code_address, input, is_static, + gas, )?; // Apply known gas amount changes (all reverts are NeedsReturn) @@ -230,24 +238,24 @@ fn run_and_commit_if_success( let left: U256; let return_data = match result { Some(GasLeft::Known(gas_left)) => { - println!("Known {} {}", PREPAID_EVM_GAS, gas_left); + println!("Known {} {}", gas, gas_left); left = gas_left; - gas_used = U256::from(PREPAID_EVM_GAS) - gas_left; + gas_used = gas - gas_left; Ok((ReturnData::empty(), left)) } Some(GasLeft::NeedsReturn { gas_left, data, apply_state: true }) => { - println!("NeedsReturn, apply_state: true {} {}", PREPAID_EVM_GAS, gas_left); - gas_used = U256::from(PREPAID_EVM_GAS) - gas_left; + println!("NeedsReturn, apply_state: true {} {}", gas, gas_left); + gas_used = gas - gas_left; left = gas_left; Ok((data, left)) } Some(GasLeft::NeedsReturn { gas_left, data, apply_state: false }) => { - println!("NeedsReturn, apply_state: false {} {}", PREPAID_EVM_GAS, gas_left); - gas_used = U256::from(PREPAID_EVM_GAS) - gas_left; + println!("NeedsReturn, apply_state: false {} {}", gas, gas_left); + gas_used = gas - gas_left; left = gas_left; Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) } - x => return Err(VMLogicError::EvmError(EvmError::UnknownError)), + _ => return Err(VMLogicError::EvmError(EvmError::UnknownError)), }; println!("Gas used in run_and_commit_if_success: {}", gas_used); // Don't apply changes from a static context (these _should_ error in the ext) @@ -271,8 +279,9 @@ fn run_against_state( code_address: &Address, input: &[u8], is_static: bool, + gas: &U256, ) -> Result<(Option, Option)> { - println!("enter run_against_state"); + println!("enter run_against_state {:?}", gas); let code = state.code_at(code_address)?.unwrap_or_else(Vec::new); let mut store = StateStore::default(); @@ -285,7 +294,7 @@ fn run_against_state( sender: *sender, origin: *origin, // TODO: gas usage. - gas: PREPAID_EVM_GAS.into(), + gas: *gas, gas_price: 1.into(), value: ActionValue::Apparent(0.into()), code: Some(Arc::new(code)), @@ -304,7 +313,7 @@ fn run_against_state( NearExt::new(*state_address, *origin, &mut sub_state, call_stack_depth + 1, is_static); // TODO: gas usage. // Gas limit is evm block gas limit, should at least prepaid gas. - ext.info.gas_limit = U256::from(PREPAID_EVM_GAS); + ext.info.gas_limit = *gas; ext.schedule = Schedule::new_constantinople(); let instance = Factory::default().create(params, ext.schedule(), ext.depth()); diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 5a7b41ff46e..0e316a25b04 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -39,6 +39,8 @@ enum KeyPrefix { Contract = 1, } +pub const PREPAID_EVM_GAS: u128 = 1_000_000_000; + fn address_to_key(prefix: KeyPrefix, address: &H160) -> Vec { let mut result = Vec::with_capacity(21); result.push(prefix as u8); @@ -153,6 +155,7 @@ impl<'a> EvmContext<'a> { CreateContractAddress::FromSenderAndNonce, false, &bytecode, + &PREPAID_EVM_GAS.into(), )?; Ok(r.0) } @@ -168,9 +171,18 @@ impl<'a> EvmContext<'a> { self.add_balance(&sender, U256::from(self.attached_deposit))?; let value = if self.attached_deposit == 0 { None } else { Some(U256::from(self.attached_deposit)) }; - let r = - interpreter::call(self, &sender, &sender, value, 0, &contract_address, &input, true) - .map(|rd| rd.0.to_vec()); + let r = interpreter::call( + self, + &sender, + &sender, + value, + 0, + &contract_address, + &input, + true, + &PREPAID_EVM_GAS.into(), + ) + .map(|rd| rd.0.to_vec()); println!("leave call_function"); r } @@ -193,6 +205,7 @@ impl<'a> EvmContext<'a> { &Address::from(&args.address), &args.args, false, + &PREPAID_EVM_GAS.into(), ) .map(|rd| rd.0.to_vec()) } diff --git a/runtime/near-evm-runner/src/near_ext.rs b/runtime/near-evm-runner/src/near_ext.rs index eff4f76ff91..692da041836 100644 --- a/runtime/near-evm-runner/src/near_ext.rs +++ b/runtime/near-evm-runner/src/near_ext.rs @@ -13,7 +13,7 @@ use near_vm_errors::{EvmError, VMLogicError}; use crate::evm_state::{EvmState, SubState}; use crate::interpreter; -// use crate::interpreter::PREPAID_EVM_GAS; + pub const PREPAID_EVM_GAS: u128 = 0; use crate::utils::format_log; @@ -149,6 +149,7 @@ impl<'a> vm::Ext for NearExt<'a> { address_type, true, &code.to_vec(), + gas, ) // TODO: gas usage. .map(|(result, gas_left)| ContractCreateResult::Created(result, gas_left)) @@ -181,7 +182,7 @@ impl<'a> vm::Ext for NearExt<'a> { // hijack builtins if crate::builtins::is_precompile(receive_address) { println!("leave NearExt.call {:?} precompile", gas); - return Ok(crate::builtins::process_precompile(receive_address, data)); + return Ok(crate::builtins::process_precompile(receive_address, data, gas)); } let result = match call_type { @@ -198,6 +199,7 @@ impl<'a> vm::Ext for NearExt<'a> { receive_address, &data.to_vec(), true, // should_commit + gas, ), CallType::StaticCall => interpreter::static_call( self.sub_state, @@ -206,6 +208,7 @@ impl<'a> vm::Ext for NearExt<'a> { self.depth, receive_address, &data.to_vec(), + gas, ), CallType::CallCode => { // Call another contract using storage of the current contract. No longer used. @@ -219,6 +222,7 @@ impl<'a> vm::Ext for NearExt<'a> { receive_address, code_address, &data.to_vec(), + gas, ), }; From 31fc610d80d3a85e8199bbb610db710312adda20 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 11 Sep 2020 15:27:17 -0700 Subject: [PATCH 06/61] undo all debug prints --- runtime/near-evm-runner/src/builtins.rs | 4 +- runtime/near-evm-runner/src/interpreter.rs | 63 +++---------------- runtime/near-evm-runner/src/lib.rs | 7 +-- runtime/near-evm-runner/src/near_ext.rs | 14 +---- runtime/near-evm-runner/tests/standard_ops.rs | 1 - 5 files changed, 16 insertions(+), 73 deletions(-) diff --git a/runtime/near-evm-runner/src/builtins.rs b/runtime/near-evm-runner/src/builtins.rs index 6c9ff279e37..48a8ac72b32 100644 --- a/runtime/near-evm-runner/src/builtins.rs +++ b/runtime/near-evm-runner/src/builtins.rs @@ -60,7 +60,6 @@ pub fn process_precompile(addr: &Address, input: &[u8], gas: &U256) -> MessageCa }; let size = bytes.len(); - // TODO: add gas usage here. MessageCallResult::Success(*gas, ReturnData::new(bytes, 0, size)) } @@ -128,6 +127,9 @@ pub struct Blake2FImpl; pub trait Impl: Send + Sync { /// execute this built-in on the given input, writing to the given output. fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), Error>; + fn gas(&self, _input: &[u8]) -> U256 { + 0.into() + } } impl Impl for Identity { diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index 9c5d51ba402..7c2c1b95206 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -40,25 +40,14 @@ pub fn deploy_code( // Apply known gas amount changes (all reverts are NeedsReturn) // Apply NeedsReturn changes if apply_state // Return the result unmodified - let gas_used: U256; - let left: U256; - let (return_data, apply) = match result { - Some(GasLeft::Known(gas_left)) => { - left = gas_left; - gas_used = gas - gas_left; - println!("Known {} {}", gas, gas_left); - (ReturnData::empty(), true) - } - Some(GasLeft::NeedsReturn { gas_left, data, apply_state }) => { - gas_used = gas - gas_left; - left = gas_left; - println!("NeedsReturn, apply_state: {} {} {}", apply_state, gas, gas_left); - (data, apply_state) + let (return_data, apply, gas_left) = match result { + Some(GasLeft::Known(left)) => (ReturnData::empty(), true, left), + Some(GasLeft::NeedsReturn { gas_left: left, data, apply_state }) => { + (data, apply_state, left) } _ => return Err(VMLogicError::EvmError(EvmError::UnknownError)), }; - println!("Gas used in deploy_code: {}", gas_used); if apply { state.commit_changes(&state_updates.unwrap())?; state.set_code(&address, &return_data.to_vec())?; @@ -67,7 +56,7 @@ pub fn deploy_code( return_data.to_vec(), )))); } - Ok((address, left)) + Ok((address, gas_left)) } pub fn _create( @@ -80,7 +69,6 @@ pub fn _create( code: &[u8], gas: &U256, ) -> Result<(Option, Option)> { - println!("enter _create"); let mut store = StateStore::default(); let mut sub_state = SubState::new(sender, &mut store, state); @@ -89,7 +77,6 @@ pub fn _create( address: *address, sender: *sender, origin: *origin, - // TODO: gas usage. gas: *gas, gas_price: 1.into(), value: ActionValue::Transfer(value), @@ -103,7 +90,6 @@ pub fn _create( sub_state.transfer_balance(sender, address, value)?; let mut ext = NearExt::new(*address, *origin, &mut sub_state, call_stack_depth + 1, false); - // TODO: gas usage. ext.info.gas_limit = U256::from(gas); ext.schedule = Schedule::new_constantinople(); @@ -111,7 +97,6 @@ pub fn _create( // Run the code let result = instance.exec(&mut ext); - println!("leave _create"); Ok((result.ok().unwrap().ok(), Some(store))) } @@ -127,11 +112,7 @@ pub fn call( should_commit: bool, gas: &U256, ) -> Result<(ReturnData, U256)> { - println!( - "enter interpreter::call {:?} {:?} {:?} {:?} {:?} {:?} {:?}", - origin, sender, value, call_stack_depth, contract_address, input, should_commit - ); - let r = run_and_commit_if_success( + run_and_commit_if_success( state, origin, sender, @@ -144,9 +125,7 @@ pub fn call( false, should_commit, gas, - ); - println!("leave interpreter::call {:?}", r); - r + ) } pub fn delegate_call( @@ -216,7 +195,6 @@ fn run_and_commit_if_success( gas: &U256, ) -> Result<(ReturnData, U256)> { // run the interpreter and - println!("enter run_and_commit_if_success"); let (result, state_updates) = run_against_state( state, origin, @@ -234,35 +212,18 @@ fn run_and_commit_if_success( // Apply known gas amount changes (all reverts are NeedsReturn) // Apply NeedsReturn changes if apply_state // Return the result unmodified - let gas_used: U256; - let left: U256; let return_data = match result { - Some(GasLeft::Known(gas_left)) => { - println!("Known {} {}", gas, gas_left); - left = gas_left; - gas_used = gas - gas_left; - Ok((ReturnData::empty(), left)) - } - Some(GasLeft::NeedsReturn { gas_left, data, apply_state: true }) => { - println!("NeedsReturn, apply_state: true {} {}", gas, gas_left); - gas_used = gas - gas_left; - left = gas_left; - Ok((data, left)) - } + Some(GasLeft::Known(gas_left)) => Ok((ReturnData::empty(), gas_left)), + Some(GasLeft::NeedsReturn { gas_left, data, apply_state: true }) => Ok((data, gas_left)), Some(GasLeft::NeedsReturn { gas_left, data, apply_state: false }) => { - println!("NeedsReturn, apply_state: false {} {}", gas, gas_left); - gas_used = gas - gas_left; - left = gas_left; Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) } _ => return Err(VMLogicError::EvmError(EvmError::UnknownError)), }; - println!("Gas used in run_and_commit_if_success: {}", gas_used); // Don't apply changes from a static context (these _should_ error in the ext) if !is_static && return_data.is_ok() && should_commit { state.commit_changes(&state_updates.unwrap())?; } - println!("leave run_and_commit_if_success {:?}", return_data); return_data } @@ -281,7 +242,6 @@ fn run_against_state( is_static: bool, gas: &U256, ) -> Result<(Option, Option)> { - println!("enter run_against_state {:?}", gas); let code = state.code_at(code_address)?.unwrap_or_else(Vec::new); let mut store = StateStore::default(); @@ -293,7 +253,6 @@ fn run_against_state( address: *state_address, sender: *sender, origin: *origin, - // TODO: gas usage. gas: *gas, gas_price: 1.into(), value: ActionValue::Apparent(0.into()), @@ -311,7 +270,6 @@ fn run_against_state( let mut ext = NearExt::new(*state_address, *origin, &mut sub_state, call_stack_depth + 1, is_static); - // TODO: gas usage. // Gas limit is evm block gas limit, should at least prepaid gas. ext.info.gas_limit = *gas; ext.schedule = Schedule::new_constantinople(); @@ -319,10 +277,7 @@ fn run_against_state( let instance = Factory::default().create(params, ext.schedule(), ext.depth()); // Run the code - println!("before instance.exec"); let result = instance.exec(&mut ext); - println!("after instance.exec"); let r = result.ok(); - println!("leave run_against_state {:?}", &r); Ok((r.unwrap().ok(), Some(store))) } diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 0e316a25b04..f65911bd8ec 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -161,7 +161,6 @@ impl<'a> EvmContext<'a> { } pub fn call_function(&mut self, args: Vec) -> Result> { - println!("enter call_function"); if args.len() <= 20 { return Err(VMLogicError::EvmError(EvmError::ArgumentParseError)); } @@ -171,7 +170,7 @@ impl<'a> EvmContext<'a> { self.add_balance(&sender, U256::from(self.attached_deposit))?; let value = if self.attached_deposit == 0 { None } else { Some(U256::from(self.attached_deposit)) }; - let r = interpreter::call( + interpreter::call( self, &sender, &sender, @@ -182,9 +181,7 @@ impl<'a> EvmContext<'a> { true, &PREPAID_EVM_GAS.into(), ) - .map(|rd| rd.0.to_vec()); - println!("leave call_function"); - r + .map(|rd| rd.0.to_vec()) } /// Make an EVM transaction. Calls `contract_address` with `encoded_input`. Execution diff --git a/runtime/near-evm-runner/src/near_ext.rs b/runtime/near-evm-runner/src/near_ext.rs index 692da041836..1edbe13f729 100644 --- a/runtime/near-evm-runner/src/near_ext.rs +++ b/runtime/near-evm-runner/src/near_ext.rs @@ -132,15 +132,12 @@ impl<'a> vm::Ext for NearExt<'a> { address_type: CreateContractAddress, _trap: bool, ) -> Result { - println!("enter NearExt.create {:?}", gas); if self.is_static() { - println!("leave NearExt.create {:?}", gas); return Err(TrapKind::Call(ActionParams::default())); } // TODO: better error propagation. - // TODO: gas metering. - let r = interpreter::deploy_code( + interpreter::deploy_code( self.sub_state, &self.origin, &self.context_addr, @@ -151,11 +148,8 @@ impl<'a> vm::Ext for NearExt<'a> { &code.to_vec(), gas, ) - // TODO: gas usage. .map(|(result, gas_left)| ContractCreateResult::Created(result, gas_left)) - .map_err(|_| TrapKind::Call(ActionParams::default())); - println!("leave NearExt.create {:?}", gas); - r + .map_err(|_| TrapKind::Call(ActionParams::default())) } /// Message call. @@ -174,14 +168,12 @@ impl<'a> vm::Ext for NearExt<'a> { call_type: CallType, _trap: bool, ) -> Result { - println!("enter NearExt.call {:?}", gas); if self.is_static() && call_type != CallType::StaticCall { panic!("MutableCallInStaticContext") } // hijack builtins if crate::builtins::is_precompile(receive_address) { - println!("leave NearExt.call {:?} precompile", gas); return Ok(crate::builtins::process_precompile(receive_address, data, gas)); } @@ -227,7 +219,6 @@ impl<'a> vm::Ext for NearExt<'a> { }; let msg_call_result = match result { - // TODO: gas usage. Ok((data, gas_left)) => MessageCallResult::Success(gas_left, data), Err(err) => { let message = match err { @@ -244,7 +235,6 @@ impl<'a> vm::Ext for NearExt<'a> { ) } }; - println!("leave NearExt.call {:?}", gas); Ok(msg_call_result) } diff --git a/runtime/near-evm-runner/tests/standard_ops.rs b/runtime/near-evm-runner/tests/standard_ops.rs index ac5252e8ed2..de2e86a981a 100644 --- a/runtime/near-evm-runner/tests/standard_ops.rs +++ b/runtime/near-evm-runner/tests/standard_ops.rs @@ -109,7 +109,6 @@ fn test_internal_create() { let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); assert_eq!(context.get_nonce(test_addr.0.to_vec()).unwrap(), U256::from(1)); - println!("=========="); let sub_addr = address_from_arr(&raw[12..32]); let (new_input, _) = subcontract::functions::a_number::call(); let new_raw = context.call_function(encode_call_function_args(sub_addr, new_input)).unwrap(); From f5a70026376ba0885a8916c786c177c2e8bc1106 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 11 Sep 2020 16:48:21 -0700 Subject: [PATCH 07/61] revert is not considered as error until top level to calc revert gas left --- Cargo.lock | 1 + runtime/near-evm-runner/src/interpreter.rs | 13 +++++++------ runtime/near-evm-runner/src/lib.rs | 9 ++++++++- runtime/near-evm-runner/src/near_ext.rs | 1 - runtime/near-vm-errors/Cargo.toml | 2 ++ runtime/near-vm-errors/src/lib.rs | 1 + 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f5a351c03f9..8d8a8d335e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3164,6 +3164,7 @@ name = "near-vm-errors" version = "2.2.0" dependencies = [ "borsh", + "ethereum-types", "near-rpc-error-macro", "serde", ] diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index 7c2c1b95206..987e86dadd8 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -2,7 +2,10 @@ use std::sync::Arc; use ethereum_types::{Address, U256}; use evm::{CreateContractAddress, Factory}; -use vm::{ActionParams, ActionValue, CallType, Ext, GasLeft, ParamsType, ReturnData, Schedule}; +use vm::{ + ActionParams, ActionValue, CallType, ContractCreateResult, Ext, GasLeft, ParamsType, + ReturnData, Schedule, +}; use near_vm_errors::{EvmError, VMLogicError}; @@ -21,7 +24,7 @@ pub fn deploy_code( recreate: bool, code: &[u8], gas: &U256, -) -> Result<(Address, U256)> { +) -> Result { let mut nonce = U256::default(); if address_type == CreateContractAddress::FromSenderAndNonce { nonce = state.next_nonce(&sender)?; @@ -51,12 +54,10 @@ pub fn deploy_code( if apply { state.commit_changes(&state_updates.unwrap())?; state.set_code(&address, &return_data.to_vec())?; + Ok(ContractCreateResult::Created(address, gas_left)) } else { - return Err(VMLogicError::EvmError(EvmError::DeployFail(hex::encode( - return_data.to_vec(), - )))); + Ok(ContractCreateResult::Reverted(gas_left, return_data)) } - Ok((address, gas_left)) } pub fn _create( diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index f65911bd8ec..b1211bddd30 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -4,6 +4,7 @@ extern crate enum_primitive_derive; use borsh::{BorshDeserialize, BorshSerialize}; use ethereum_types::{Address, H160, U256}; use evm::CreateContractAddress; +use vm::ContractCreateResult; use near_runtime_fees::RuntimeFeesConfig; use near_vm_errors::{EvmError, FunctionCallError, VMError}; @@ -157,7 +158,13 @@ impl<'a> EvmContext<'a> { &bytecode, &PREPAID_EVM_GAS.into(), )?; - Ok(r.0) + match r { + ContractCreateResult::Created(address, gas_left) => Ok(address), + ContractCreateResult::Reverted(gas_left, return_data) => { + Err(VMLogicError::EvmError(EvmError::DeployFail(hex::encode(return_data.to_vec())))) + } + _ => unreachable!(), + } } pub fn call_function(&mut self, args: Vec) -> Result> { diff --git a/runtime/near-evm-runner/src/near_ext.rs b/runtime/near-evm-runner/src/near_ext.rs index 1edbe13f729..7e65f187764 100644 --- a/runtime/near-evm-runner/src/near_ext.rs +++ b/runtime/near-evm-runner/src/near_ext.rs @@ -148,7 +148,6 @@ impl<'a> vm::Ext for NearExt<'a> { &code.to_vec(), gas, ) - .map(|(result, gas_left)| ContractCreateResult::Created(result, gas_left)) .map_err(|_| TrapKind::Call(ActionParams::default())) } diff --git a/runtime/near-vm-errors/Cargo.toml b/runtime/near-vm-errors/Cargo.toml index 2373b78b2d0..ed1cd95bd80 100644 --- a/runtime/near-vm-errors/Cargo.toml +++ b/runtime/near-vm-errors/Cargo.toml @@ -19,5 +19,7 @@ borsh = "0.7.1" near-rpc-error-macro = { path = "../../tools/rpctypegen/macro", version = "0.1.0" } +ethereum-types = "0.6.0" + [features] dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"] diff --git a/runtime/near-vm-errors/src/lib.rs b/runtime/near-vm-errors/src/lib.rs index 4def95f3cff..cd96cdd3fb2 100644 --- a/runtime/near-vm-errors/src/lib.rs +++ b/runtime/near-vm-errors/src/lib.rs @@ -5,6 +5,7 @@ use serde::export::fmt::Error; use serde::export::Formatter; use serde::{Deserialize, Serialize}; +use ethereum_types::U256; use near_rpc_error_macro::RpcError; #[derive(Debug, Clone, PartialEq, Eq, BorshDeserialize, BorshSerialize, Deserialize, Serialize)] From ecc207d03c43cdacb95e4db3d130f50591c69f78 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 11 Sep 2020 17:23:20 -0700 Subject: [PATCH 08/61] resolve all gas from revert --- runtime/near-evm-runner/src/interpreter.rs | 26 +++++++++++++--------- runtime/near-evm-runner/src/lib.rs | 26 ++++++++++++++++------ runtime/near-evm-runner/src/near_ext.rs | 20 +---------------- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index 987e86dadd8..615244444ac 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -3,8 +3,8 @@ use std::sync::Arc; use ethereum_types::{Address, U256}; use evm::{CreateContractAddress, Factory}; use vm::{ - ActionParams, ActionValue, CallType, ContractCreateResult, Ext, GasLeft, ParamsType, - ReturnData, Schedule, + ActionParams, ActionValue, CallType, ContractCreateResult, Ext, GasLeft, MessageCallResult, + ParamsType, ReturnData, Schedule, }; use near_vm_errors::{EvmError, VMLogicError}; @@ -112,7 +112,7 @@ pub fn call( input: &[u8], should_commit: bool, gas: &U256, -) -> Result<(ReturnData, U256)> { +) -> Result { run_and_commit_if_success( state, origin, @@ -138,7 +138,7 @@ pub fn delegate_call( delegee: &Address, input: &[u8], gas: &U256, -) -> Result<(ReturnData, U256)> { +) -> Result { run_and_commit_if_success( state, origin, @@ -163,7 +163,7 @@ pub fn static_call( contract_address: &Address, input: &[u8], gas: &U256, -) -> Result<(ReturnData, U256)> { +) -> Result { run_and_commit_if_success( state, origin, @@ -194,7 +194,7 @@ fn run_and_commit_if_success( is_static: bool, should_commit: bool, gas: &U256, -) -> Result<(ReturnData, U256)> { +) -> Result { // run the interpreter and let (result, state_updates) = run_against_state( state, @@ -213,16 +213,22 @@ fn run_and_commit_if_success( // Apply known gas amount changes (all reverts are NeedsReturn) // Apply NeedsReturn changes if apply_state // Return the result unmodified + let mut should_apply_state = true; let return_data = match result { - Some(GasLeft::Known(gas_left)) => Ok((ReturnData::empty(), gas_left)), - Some(GasLeft::NeedsReturn { gas_left, data, apply_state: true }) => Ok((data, gas_left)), + Some(GasLeft::Known(gas_left)) => { + Ok(MessageCallResult::Success(gas_left, ReturnData::empty())) + } + Some(GasLeft::NeedsReturn { gas_left, data, apply_state: true }) => { + Ok(MessageCallResult::Success(gas_left, data)) + } Some(GasLeft::NeedsReturn { gas_left, data, apply_state: false }) => { - Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) + should_apply_state = false; + Ok(MessageCallResult::Reverted(gas_left, data)) } _ => return Err(VMLogicError::EvmError(EvmError::UnknownError)), }; // Don't apply changes from a static context (these _should_ error in the ext) - if !is_static && return_data.is_ok() && should_commit { + if !is_static && return_data.is_ok() && should_apply_state && should_commit { state.commit_changes(&state_updates.unwrap())?; } return_data diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index b1211bddd30..657d450390f 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -4,7 +4,7 @@ extern crate enum_primitive_derive; use borsh::{BorshDeserialize, BorshSerialize}; use ethereum_types::{Address, H160, U256}; use evm::CreateContractAddress; -use vm::ContractCreateResult; +use vm::{ContractCreateResult, MessageCallResult}; use near_runtime_fees::RuntimeFeesConfig; use near_vm_errors::{EvmError, FunctionCallError, VMError}; @@ -177,7 +177,7 @@ impl<'a> EvmContext<'a> { self.add_balance(&sender, U256::from(self.attached_deposit))?; let value = if self.attached_deposit == 0 { None } else { Some(U256::from(self.attached_deposit)) }; - interpreter::call( + let rd = interpreter::call( self, &sender, &sender, @@ -187,8 +187,14 @@ impl<'a> EvmContext<'a> { &input, true, &PREPAID_EVM_GAS.into(), - ) - .map(|rd| rd.0.to_vec()) + )?; + match rd { + MessageCallResult::Success(gas_left, data) => Ok(data.to_vec()), + MessageCallResult::Reverted(gas_left, data) => { + Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) + } + _ => unreachable!(), + } } /// Make an EVM transaction. Calls `contract_address` with `encoded_input`. Execution @@ -200,7 +206,7 @@ impl<'a> EvmContext<'a> { let args = ViewCallArgs::try_from_slice(&args) .map_err(|_| VMLogicError::EvmError(EvmError::ArgumentParseError))?; let sender = Address::from(&args.sender); - interpreter::call( + let rd = interpreter::call( self, &sender, &sender, @@ -210,8 +216,14 @@ impl<'a> EvmContext<'a> { &args.args, false, &PREPAID_EVM_GAS.into(), - ) - .map(|rd| rd.0.to_vec()) + )?; + match rd { + MessageCallResult::Success(gas_left, data) => Ok(data.to_vec()), + MessageCallResult::Reverted(gas_left, data) => { + Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) + } + _ => unreachable!(), + } } pub fn get_code(&self, args: Vec) -> Result> { diff --git a/runtime/near-evm-runner/src/near_ext.rs b/runtime/near-evm-runner/src/near_ext.rs index 7e65f187764..f417fb8f83d 100644 --- a/runtime/near-evm-runner/src/near_ext.rs +++ b/runtime/near-evm-runner/src/near_ext.rs @@ -216,25 +216,7 @@ impl<'a> vm::Ext for NearExt<'a> { gas, ), }; - - let msg_call_result = match result { - Ok((data, gas_left)) => MessageCallResult::Success(gas_left, data), - Err(err) => { - let message = match err { - VMLogicError::EvmError(EvmError::Revert(encoded_message)) => { - hex::decode(encoded_message).unwrap_or(vec![]) - } - _ => format!("{:?}", err).as_bytes().to_vec(), - }; - let message_len = message.len(); - // TODO: gas usage. - MessageCallResult::Reverted( - PREPAID_EVM_GAS.into(), - ReturnData::new(message, 0, message_len), - ) - } - }; - Ok(msg_call_result) + result.map_err(|_| TrapKind::Call(ActionParams::default())) } /// Returns code at given address From f00a8aebdc239c0cce1063e7a65d99219b4b6ca9 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 11 Sep 2020 17:30:53 -0700 Subject: [PATCH 09/61] cost hook for precompile functions --- runtime/near-evm-runner/src/builtins.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/near-evm-runner/src/builtins.rs b/runtime/near-evm-runner/src/builtins.rs index 48a8ac72b32..73ee6345b1a 100644 --- a/runtime/near-evm-runner/src/builtins.rs +++ b/runtime/near-evm-runner/src/builtins.rs @@ -52,6 +52,11 @@ pub fn process_precompile(addr: &Address, input: &[u8], gas: &U256) -> MessageCa }; let mut bytes = vec![]; let mut output = parity_bytes::BytesRef::Flexible(&mut bytes); + let cost = f.gas(input); + + if cost > *gas { + return MessageCallResult::Failed; + } // mutates bytes match f.execute(input, &mut output) { @@ -60,7 +65,7 @@ pub fn process_precompile(addr: &Address, input: &[u8], gas: &U256) -> MessageCa }; let size = bytes.len(); - MessageCallResult::Success(*gas, ReturnData::new(bytes, 0, size)) + MessageCallResult::Success(*gas - cost, ReturnData::new(bytes, 0, size)) } /** the following is copied from ethcore/src/builtin.rs **/ From 8508167f64b9cee5d3b5baccd11c162e933d70d2 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 11 Sep 2020 17:55:53 -0700 Subject: [PATCH 10/61] basic evm gas counter --- runtime/near-evm-runner/src/evm_state.rs | 24 ++++++++++++++++++++ runtime/near-evm-runner/src/lib.rs | 28 ++++++++++++++++++------ runtime/near-evm-runner/src/near_ext.rs | 4 ---- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/runtime/near-evm-runner/src/evm_state.rs b/runtime/near-evm-runner/src/evm_state.rs index b167bd4f190..df3f31cb56c 100644 --- a/runtime/near-evm-runner/src/evm_state.rs +++ b/runtime/near-evm-runner/src/evm_state.rs @@ -310,6 +310,30 @@ impl EvmState for SubState<'_> { } } +pub struct EvmGasCounter { + used_gas: U256, + max_gas: U256, +} + +impl EvmGasCounter { + pub fn new(used_gas: U256, max_gas: U256) -> EvmGasCounter { + Self { used_gas, max_gas } + } + + pub fn pay_gas(&mut self, amount: U256) { + // TODO: return error if gas not sufficient + self.used_gas += amount; + } + + pub fn set_gas_left(&mut self, left: U256) { + self.used_gas = self.max_gas - left; + } + + pub fn gas_left(&self) -> U256 { + self.max_gas - self.used_gas + } +} + #[cfg(test)] mod test { use super::*; diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 657d450390f..00015e58d90 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -12,7 +12,7 @@ use near_vm_logic::gas_counter::GasCounter; use near_vm_logic::types::{AccountId, Balance, Gas, ReturnData, StorageUsage}; use near_vm_logic::{ActionCosts, External, VMConfig, VMLogicError, VMOutcome}; -use crate::evm_state::{EvmAccount, EvmState, StateStore}; +use crate::evm_state::{EvmAccount, EvmGasCounter, EvmState, StateStore}; use crate::types::{ AddressArg, GetStorageAtArgs, Result, TransferArgs, ViewCallArgs, WithdrawArgs, }; @@ -32,6 +32,7 @@ pub struct EvmContext<'a> { storage_usage: StorageUsage, pub logs: Vec, gas_counter: GasCounter, + evm_gas_counter: EvmGasCounter, fees_config: &'a RuntimeFeesConfig, } @@ -140,6 +141,7 @@ impl<'a> EvmContext<'a> { is_view, None, ), + evm_gas_counter: EvmGasCounter::new(0.into(), PREPAID_EVM_GAS.into()), fees_config, } } @@ -156,11 +158,15 @@ impl<'a> EvmContext<'a> { CreateContractAddress::FromSenderAndNonce, false, &bytecode, - &PREPAID_EVM_GAS.into(), + &self.evm_gas_counter.gas_left(), )?; match r { - ContractCreateResult::Created(address, gas_left) => Ok(address), + ContractCreateResult::Created(address, gas_left) => { + self.evm_gas_counter.set_gas_left(gas_left); + Ok(address) + } ContractCreateResult::Reverted(gas_left, return_data) => { + self.evm_gas_counter.set_gas_left(gas_left); Err(VMLogicError::EvmError(EvmError::DeployFail(hex::encode(return_data.to_vec())))) } _ => unreachable!(), @@ -186,11 +192,15 @@ impl<'a> EvmContext<'a> { &contract_address, &input, true, - &PREPAID_EVM_GAS.into(), + &self.evm_gas_counter.gas_left(), )?; match rd { - MessageCallResult::Success(gas_left, data) => Ok(data.to_vec()), + MessageCallResult::Success(gas_left, data) => { + self.evm_gas_counter.set_gas_left(gas_left); + Ok(data.to_vec()) + } MessageCallResult::Reverted(gas_left, data) => { + self.evm_gas_counter.set_gas_left(gas_left); Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) } _ => unreachable!(), @@ -215,11 +225,15 @@ impl<'a> EvmContext<'a> { &Address::from(&args.address), &args.args, false, - &PREPAID_EVM_GAS.into(), + &self.evm_gas_counter.gas_left(), )?; match rd { - MessageCallResult::Success(gas_left, data) => Ok(data.to_vec()), + MessageCallResult::Success(gas_left, data) => { + self.evm_gas_counter.set_gas_left(gas_left); + Ok(data.to_vec()) + } MessageCallResult::Reverted(gas_left, data) => { + self.evm_gas_counter.set_gas_left(gas_left); Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) } _ => unreachable!(), diff --git a/runtime/near-evm-runner/src/near_ext.rs b/runtime/near-evm-runner/src/near_ext.rs index f417fb8f83d..2e54b14b774 100644 --- a/runtime/near-evm-runner/src/near_ext.rs +++ b/runtime/near-evm-runner/src/near_ext.rs @@ -9,13 +9,9 @@ use vm::{ MessageCallResult, Result as EvmResult, ReturnData, Schedule, TrapKind, }; -use near_vm_errors::{EvmError, VMLogicError}; - use crate::evm_state::{EvmState, SubState}; use crate::interpreter; -pub const PREPAID_EVM_GAS: u128 = 0; - use crate::utils::format_log; // https://github.com/paritytech/parity-ethereum/blob/77643c13e80ca09d9a6b10631034f5a1568ba6d3/ethcore/machine/src/externalities.rs From b9adf54134fcfa5f2659dad6f808d537c5693991 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 11 Sep 2020 18:08:50 -0700 Subject: [PATCH 11/61] got evm gas used in all tests --- runtime/near-evm-runner/src/evm_state.rs | 4 ++-- runtime/near-evm-runner/src/lib.rs | 2 +- runtime/near-evm-runner/tests/standard_ops.rs | 17 ++++++++++++++++- runtime/near-evm-runner/tests/utils.rs | 4 ++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/runtime/near-evm-runner/src/evm_state.rs b/runtime/near-evm-runner/src/evm_state.rs index df3f31cb56c..27c01a281ba 100644 --- a/runtime/near-evm-runner/src/evm_state.rs +++ b/runtime/near-evm-runner/src/evm_state.rs @@ -311,8 +311,8 @@ impl EvmState for SubState<'_> { } pub struct EvmGasCounter { - used_gas: U256, - max_gas: U256, + pub used_gas: U256, + pub max_gas: U256, } impl EvmGasCounter { diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 00015e58d90..fcd55bda533 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -32,7 +32,7 @@ pub struct EvmContext<'a> { storage_usage: StorageUsage, pub logs: Vec, gas_counter: GasCounter, - evm_gas_counter: EvmGasCounter, + pub evm_gas_counter: EvmGasCounter, fees_config: &'a RuntimeFeesConfig, } diff --git a/runtime/near-evm-runner/tests/standard_ops.rs b/runtime/near-evm-runner/tests/standard_ops.rs index de2e86a981a..2d81381e81f 100644 --- a/runtime/near-evm-runner/tests/standard_ops.rs +++ b/runtime/near-evm-runner/tests/standard_ops.rs @@ -15,7 +15,7 @@ use near_vm_errors::{EvmError, VMLogicError}; use near_vm_logic::mocks::mock_external::MockedExternal; use near_vm_logic::VMConfig; -use crate::utils::{accounts, create_context, setup}; +use crate::utils::{accounts, create_context, setup, show_evm_gas_used}; mod utils; @@ -79,8 +79,10 @@ fn test_deploy_with_nonce() { let address = near_account_id_to_evm_address(&accounts(1)); assert_eq!(context.get_nonce(address.0.to_vec()).unwrap(), U256::from(0)); let address1 = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); + show_evm_gas_used(&context); assert_eq!(context.get_nonce(address.0.to_vec()).unwrap(), U256::from(1)); let address2 = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); + show_evm_gas_used(&context); assert_eq!(context.get_nonce(address.0.to_vec()).unwrap(), U256::from(2)); assert_ne!(address1, address2); } @@ -92,6 +94,7 @@ fn test_failed_deploy_returns_error() { if let Err(VMLogicError::EvmError(EvmError::DeployFail(_))) = context.deploy_code(hex::decode(&CONSTRUCTOR_TEST).unwrap()) { + show_evm_gas_used(&context); } else { panic!("Should fail"); } @@ -102,16 +105,19 @@ fn test_internal_create() { let (mut fake_external, vm_config, fees_config) = setup(); let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 0); let test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); + show_evm_gas_used(&context); assert_eq!(context.get_nonce(test_addr.0.to_vec()).unwrap(), U256::from(0)); // This should increment the nonce of the deploying contract let (input, _) = soltest::functions::deploy_new_guy::call(8); let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); + show_evm_gas_used(&context); assert_eq!(context.get_nonce(test_addr.0.to_vec()).unwrap(), U256::from(1)); let sub_addr = address_from_arr(&raw[12..32]); let (new_input, _) = subcontract::functions::a_number::call(); let new_raw = context.call_function(encode_call_function_args(sub_addr, new_input)).unwrap(); + show_evm_gas_used(&context); let output = subcontract::functions::a_number::decode_output(&new_raw).unwrap(); assert_eq!(output, U256::from(8)); } @@ -122,10 +128,12 @@ fn test_precompiles() { let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 100); let test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); + show_evm_gas_used(&context); let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 0); let (input, _) = soltest::functions::precompile_test::call(); let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); + show_evm_gas_used(&context); assert_eq!(raw.len(), 0); } @@ -134,6 +142,7 @@ fn setup_and_deploy_test() -> (MockedExternal, Address, VMConfig, RuntimeFeesCon let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 100); let test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); + show_evm_gas_used(&context); assert_eq!(context.get_balance(test_addr.0.to_vec()).unwrap(), U256::from(100)); (fake_external, test_addr, vm_config, fees_config) } @@ -148,6 +157,7 @@ fn test_deploy_and_transfer() { let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 100); let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); + show_evm_gas_used(&context); assert!(context.logs.len() > 0); // The sub_addr should have been transferred 100 yoctoN. @@ -166,6 +176,7 @@ fn test_deploy_with_value() { let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 100); let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); + show_evm_gas_used(&context); // The sub_addr should have been transferred 100 tokens. let sub_addr = raw[12..32].to_vec(); @@ -181,6 +192,7 @@ fn test_contract_to_eoa_transfer() { let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 100); let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); + show_evm_gas_used(&context); let sender_addr = raw[12..32].to_vec(); assert_eq!(context.get_balance(test_addr.0.to_vec()).unwrap(), U256::from(150)); @@ -212,6 +224,7 @@ fn test_view_call() { input, )) .unwrap(); + show_evm_gas_used(&context); assert_eq!(context.get_nonce(test_addr.0.to_vec()).unwrap(), U256::from(0)); let sub_addr = raw[12..32].to_vec(); @@ -231,11 +244,13 @@ fn test_solidity_accurate_storage_on_selfdestruct() { // Deploy CREATE2 Factory let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 0); let factory_addr = context.deploy_code(hex::decode(&FACTORY_TEST).unwrap()).unwrap(); + show_evm_gas_used(&context); // Deploy + SelfDestruct in one transaction let salt = H256([0u8; 32]); let destruct_code = hex::decode(&DESTRUCT_TEST).unwrap(); let input = create2factory::functions::test_double_deploy::call(salt, destruct_code.clone()).0; let raw = context.call_function(encode_call_function_args(factory_addr, input)).unwrap(); + show_evm_gas_used(&context); assert!(create2factory::functions::test_double_deploy::decode_output(&raw).unwrap()); } diff --git a/runtime/near-evm-runner/tests/utils.rs b/runtime/near-evm-runner/tests/utils.rs index c937363c949..c8ddcc5d19d 100644 --- a/runtime/near-evm-runner/tests/utils.rs +++ b/runtime/near-evm-runner/tests/utils.rs @@ -34,3 +34,7 @@ pub fn create_context<'a>( false, ) } + +pub fn show_evm_gas_used(context: &EvmContext) { + println!("Accumulated EVM gas used: {}", &context.evm_gas_counter.used_gas); +} From bb50e66e441301b65ed96c4e5c37a7a2128fb7f4 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 14 Sep 2020 17:03:31 -0700 Subject: [PATCH 12/61] count deploy evm code cost --- Cargo.lock | 3 +- runtime/near-evm-runner/Cargo.toml | 2 +- runtime/near-evm-runner/src/lib.rs | 18 ++-- runtime/near-vm-runner/Cargo.toml | 1 + runtime/runtime-params-estimator/src/cases.rs | 7 +- runtime/runtime-params-estimator/src/main.rs | 2 + .../src/vm_estimator.rs | 87 ++++++++++++++++++- runtime/runtime/src/actions.rs | 5 +- rust-toolchain | 2 +- 9 files changed, 114 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d8a8d335e8..5fc5e89d738 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2853,7 +2853,7 @@ dependencies = [ [[package]] name = "near-evm-runner" -version = "0.1.0" +version = "2.2.0" dependencies = [ "bn", "borsh", @@ -3193,6 +3193,7 @@ dependencies = [ "assert_matches", "bencher", "cached", + "near-evm-runner", "near-runtime-fees", "near-vm-errors", "near-vm-logic", diff --git a/runtime/near-evm-runner/Cargo.toml b/runtime/near-evm-runner/Cargo.toml index 3e85496668d..5b30782067e 100644 --- a/runtime/near-evm-runner/Cargo.toml +++ b/runtime/near-evm-runner/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "near-evm-runner" -version = "0.1.0" +version = "2.2.0" authors = ["Near Inc "] edition = "2018" license = "Apache-2.0" diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index fcd55bda533..8f3d0b7f1d4 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -361,7 +361,7 @@ pub fn run_evm( args: Vec, prepaid_gas: Gas, is_view: bool, -) -> (Option, Option) { +) -> (Option, Option, U256) { let mut context = EvmContext::new( ext, config, @@ -402,12 +402,18 @@ pub fn run_evm( used_gas: context.gas_counter.used_gas(), logs: context.logs, }; - (Some(outcome), None) + (Some(outcome), None, context.evm_gas_counter.used_gas) } - Err(VMLogicError::EvmError(err)) => { - (None, Some(VMError::FunctionCallError(FunctionCallError::EvmError(err)))) - } - Err(_) => (None, Some(VMError::FunctionCallError(FunctionCallError::WasmUnknownError))), + Err(VMLogicError::EvmError(err)) => ( + None, + Some(VMError::FunctionCallError(FunctionCallError::EvmError(err))), + context.evm_gas_counter.used_gas, + ), + Err(_) => ( + None, + Some(VMError::FunctionCallError(FunctionCallError::WasmUnknownError)), + context.evm_gas_counter.used_gas, + ), } } diff --git a/runtime/near-vm-runner/Cargo.toml b/runtime/near-vm-runner/Cargo.toml index fe54ea0bf1c..768697b6274 100644 --- a/runtime/near-vm-runner/Cargo.toml +++ b/runtime/near-vm-runner/Cargo.toml @@ -23,6 +23,7 @@ anyhow = { version = "1.0.19", optional = true } near-runtime-fees = { path="../near-runtime-fees", version = "2.2.0" } near-vm-logic = { path="../near-vm-logic", version = "2.2.0", default-features = false, features = []} near-vm-errors = { path = "../near-vm-errors", version = "2.2.0" } +near-evm-runner = { path = "../near-evm-runner", version = "2.2.0"} [dev-dependencies] assert_matches = "1.3" diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index 44eaf7078ae..ac63f775e1a 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -145,7 +145,7 @@ pub enum Metric { cpu_ram_soak_test, } -pub fn run(mut config: Config, only_compile: bool) -> RuntimeConfig { +pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeConfig { let mut m = Measurements::new(config.metric); if only_compile { let (contract_compile_cost, contract_compile_base_cost) = @@ -157,6 +157,11 @@ pub fn run(mut config: Config, only_compile: bool) -> RuntimeConfig { ratio_to_gas(config.metric, contract_compile_base_cost) ); process::exit(0); + } else if only_evm { + let (evm_cost, evm_base_cost) = cost_of_evm(config.metric, config.vm_kind); + let contract_byte_cost = ratio_to_gas(config.metric, evm_cost); + println!("{}, {}", contract_byte_cost, ratio_to_gas(config.metric, evm_base_cost)); + process::exit(0); } config.block_sizes = vec![100]; // Measure the speed of processing empty receipts. diff --git a/runtime/runtime-params-estimator/src/main.rs b/runtime/runtime-params-estimator/src/main.rs index 4ff7df436d2..0d5d3aa60e6 100644 --- a/runtime/runtime-params-estimator/src/main.rs +++ b/runtime/runtime-params-estimator/src/main.rs @@ -71,6 +71,7 @@ fn main() { .long("transaction") .help("Disables transaction measurements"), ) + .arg(Arg::with_name("evm-only").long("evm-only").help("only test evm related cost")) .get_matches(); let state_dump_path = matches.value_of("home").unwrap().to_string(); @@ -102,6 +103,7 @@ fn main() { disable_measure_transaction, }, matches.is_present("compile-only"), + matches.is_present("evm-only"), ); println!("Generated RuntimeConfig:"); diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 67e7a104ecd..4193bdc5211 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -2,6 +2,7 @@ use crate::testbed_runners::end_count; use crate::testbed_runners::start_count; use crate::testbed_runners::GasMetric; use glob::glob; +use near_evm_runner::run_evm; use near_primitives::version::PROTOCOL_VERSION; use near_runtime_fees::RuntimeFeesConfig; use near_vm_logic::mocks::mock_external::MockedExternal; @@ -131,13 +132,97 @@ fn load_and_compile(path: &PathBuf, gas_metric: GasMetric, vm_kind: VMKind) -> O } } +struct EvmCost { + evm_gas: u64, + cost: Ratio, +} + +fn deploy_evm_contract(code: &[u8], gas_metric: &GasMetric) -> Option { + let mut fake_external = MockedExternal::new(); + let config = VMConfig::default(); + let fees = RuntimeFeesConfig::default(); + + let start = start_count(gas_metric); + let evm_gas; + for i in 0..NUM_ITERATIONS { + let (_, _, gas_used) = run_evm( + fake_external, + config, + fees, + "alice".to_string(), + 1000.into(), + 0.into(), + 0.into(), + "deploy_code", + code, + 1_000_000_000.into(), + false, + ); + // All iterations use same amount of (evm) gas, it's safe to use any of them as gas_used. + // But we loop because we want avg of number of (near) gas_metric + evm_gas = gas_used; + } + let end = end_count(gas_metric, &start); + Some((evm_gas as u64, Ratio::new(end, NUM_ITERATIONS))) +} + +fn load_and_deploy_evm_contract(path: &PathBuf, gas_metric: GasMetric) -> Option { + match fs::read(path) { + Ok(mut code) => deploy_evm_contract(&code, gas_metric), + _ => None, + } +} + #[cfg(feature = "lightbeam")] const USING_LIGHTBEAM: bool = true; #[cfg(not(feature = "lightbeam"))] const USING_LIGHTBEAM: bool = false; +/// Cost of all evm related +pub fn cost_of_evm(gas_metric: GasMetric, vm_kind: VMKind) -> (Ratio, Ratio) { + let globbed_files = glob("./**/*.bin").expect("Failed to read glob pattern for bin files"); + let paths = globbed_files + .filter_map(|x| match x { + Ok(p) => Some(p), + _ => None, + }) + .collect::>(); + let ratio = Ratio::new(0 as u64, 1); + let base = Ratio::new(u64::MAX, 1); + + let measurements = paths + .iter() + .filter(|path| fs::metadata(path).is_ok()) + .map(|path| { + if verbose { + print!("Testing {}: ", path.display()); + }; + // Evm counted gas already count on size of the contract, therefore we look for cost = m*evm_gas + b. + if let Some((evm_gas, cost)) = load_and_deploy_evm_contract(path, gas_metric) { + if verbose { + println!("({}, {})", evm_gas, cost); + }; + Some(EvmCost { evm_gas, cost }) + } else { + if verbose { + println!("FAILED") + }; + None + } + }) + .filter(|x| x.is_some()) + .map(|x| x.unwrap()) + .collect::>(); + let b = measurements.iter().fold(base, |base, (_, cost)| base.min(*cost)); + let m = measurements.iter().fold(ratio, |r, (evm_gas, cost)| r.max((*cost - b) / evm_gas)); + if verbose { + println!("raw data: ({},{})", m, b); + } + (m, b) +} + /// Cost of the compile contract with vm_kind -pub fn cost_to_compile( +pub fn cost_of_compile( gas_metric: GasMetric, vm_kind: VMKind, verbose: bool, diff --git a/runtime/runtime/src/actions.rs b/runtime/runtime/src/actions.rs index 0047d4ca527..d727caecb53 100644 --- a/runtime/runtime/src/actions.rs +++ b/runtime/runtime/src/actions.rs @@ -51,7 +51,7 @@ pub(crate) fn execute_function_call( is_view: bool, ) -> (Option, Option) { if account.code_hash == *EVM_CODE_HASH { - near_evm_runner::run_evm( + let (outcome, error, _) = near_evm_runner::run_evm( runtime_ext, &config.wasm_config, &config.transaction_costs, @@ -63,7 +63,8 @@ pub(crate) fn execute_function_call( function_call.args.clone(), function_call.gas, is_view, - ) + ); + (outcome, error) } else { let code = match runtime_ext.get_code(account.code_hash) { Ok(Some(code)) => code, diff --git a/rust-toolchain b/rust-toolchain index a36829b681f..8737a7eb567 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2020-08-26 +nightly-2020-05-15 From ca0b69efd798f77197dd4a25ac0485fd5a183ebb Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 14 Sep 2020 18:47:53 -0700 Subject: [PATCH 13/61] compiles --- Cargo.lock | 1 + runtime/runtime-params-estimator/Cargo.toml | 1 + runtime/runtime-params-estimator/src/cases.rs | 4 +- .../src/vm_estimator.rs | 47 ++++++++++--------- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5fc5e89d738..ac0d8549738 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4391,6 +4391,7 @@ dependencies = [ "gnuplot", "indicatif 0.15.0", "near-crypto", + "near-evm-runner", "near-primitives", "near-runtime-fees", "near-store", diff --git a/runtime/runtime-params-estimator/Cargo.toml b/runtime/runtime-params-estimator/Cargo.toml index 14390eaec28..dab48a7b3e7 100644 --- a/runtime/runtime-params-estimator/Cargo.toml +++ b/runtime/runtime-params-estimator/Cargo.toml @@ -28,6 +28,7 @@ neard = { path = "../../neard" } rocksdb = { git = "https://github.com/nearprotocol/rust-rocksdb", branch="disable-thread" } glob = "0.3.0" walrus = "0.18.0" +near-evm-runner = { path = "../../runtime/near-evm-runner" } [features] default = [] diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index ac63f775e1a..a539deb59b3 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -20,7 +20,7 @@ use crate::stats::Measurements; use crate::testbed::RuntimeTestbed; use crate::testbed_runners::GasMetric; use crate::testbed_runners::{get_account_id, measure_actions, measure_transactions, Config}; -use crate::vm_estimator::{cost_per_op, cost_to_compile}; +use crate::vm_estimator::{cost_of_evm, cost_per_op, cost_to_compile}; use near_runtime_fees::{ AccessKeyCreationConfig, ActionCreationConfig, DataReceiptCreationConfig, Fee, RuntimeFeesConfig, @@ -158,7 +158,7 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon ); process::exit(0); } else if only_evm { - let (evm_cost, evm_base_cost) = cost_of_evm(config.metric, config.vm_kind); + let (evm_cost, evm_base_cost) = cost_of_evm(config.metric, true); let contract_byte_cost = ratio_to_gas(config.metric, evm_cost); println!("{}, {}", contract_byte_cost, ratio_to_gas(config.metric, evm_base_cost)); process::exit(0); diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 4193bdc5211..75d47b29883 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -137,38 +137,38 @@ struct EvmCost { cost: Ratio, } -fn deploy_evm_contract(code: &[u8], gas_metric: &GasMetric) -> Option { +fn deploy_evm_contract(code: &[u8], gas_metric: GasMetric) -> Option { let mut fake_external = MockedExternal::new(); let config = VMConfig::default(); let fees = RuntimeFeesConfig::default(); let start = start_count(gas_metric); - let evm_gas; - for i in 0..NUM_ITERATIONS { + let mut evm_gas = 0; + for _ in 0..NUM_ITERATIONS { let (_, _, gas_used) = run_evm( - fake_external, - config, - fees, - "alice".to_string(), - 1000.into(), - 0.into(), - 0.into(), - "deploy_code", - code, - 1_000_000_000.into(), + &mut fake_external, + &config, + &fees, + &"alice".to_string(), + 1000u128, + 0u128, + 0u64, + "deploy_code".to_string(), + code.into(), + 1_000_000_000u64, false, ); // All iterations use same amount of (evm) gas, it's safe to use any of them as gas_used. // But we loop because we want avg of number of (near) gas_metric - evm_gas = gas_used; + evm_gas = gas_used.as_u64(); } let end = end_count(gas_metric, &start); - Some((evm_gas as u64, Ratio::new(end, NUM_ITERATIONS))) + Some(EvmCost { evm_gas, cost: Ratio::new(end, NUM_ITERATIONS) }) } fn load_and_deploy_evm_contract(path: &PathBuf, gas_metric: GasMetric) -> Option { match fs::read(path) { - Ok(mut code) => deploy_evm_contract(&code, gas_metric), + Ok(code) => deploy_evm_contract(&code, gas_metric), _ => None, } } @@ -179,7 +179,7 @@ const USING_LIGHTBEAM: bool = true; const USING_LIGHTBEAM: bool = false; /// Cost of all evm related -pub fn cost_of_evm(gas_metric: GasMetric, vm_kind: VMKind) -> (Ratio, Ratio) { +pub fn cost_of_evm(gas_metric: GasMetric, verbose: bool) -> (Ratio, Ratio) { let globbed_files = glob("./**/*.bin").expect("Failed to read glob pattern for bin files"); let paths = globbed_files .filter_map(|x| match x { @@ -198,7 +198,8 @@ pub fn cost_of_evm(gas_metric: GasMetric, vm_kind: VMKind) -> (Ratio, Ratio print!("Testing {}: ", path.display()); }; // Evm counted gas already count on size of the contract, therefore we look for cost = m*evm_gas + b. - if let Some((evm_gas, cost)) = load_and_deploy_evm_contract(path, gas_metric) { + if let Some(EvmCost { evm_gas, cost }) = load_and_deploy_evm_contract(path, gas_metric) + { if verbose { println!("({}, {})", evm_gas, cost); }; @@ -212,9 +213,11 @@ pub fn cost_of_evm(gas_metric: GasMetric, vm_kind: VMKind) -> (Ratio, Ratio }) .filter(|x| x.is_some()) .map(|x| x.unwrap()) - .collect::>(); - let b = measurements.iter().fold(base, |base, (_, cost)| base.min(*cost)); - let m = measurements.iter().fold(ratio, |r, (evm_gas, cost)| r.max((*cost - b) / evm_gas)); + .collect::>(); + let b = measurements.iter().fold(base, |_b, EvmCost { evm_gas: _, cost }| base.min(*cost)); + let m = measurements + .iter() + .fold(ratio, |r, EvmCost { evm_gas, cost }| r.max((*cost - b) / evm_gas)); if verbose { println!("raw data: ({},{})", m, b); } @@ -222,7 +225,7 @@ pub fn cost_of_evm(gas_metric: GasMetric, vm_kind: VMKind) -> (Ratio, Ratio } /// Cost of the compile contract with vm_kind -pub fn cost_of_compile( +pub fn cost_to_compile( gas_metric: GasMetric, vm_kind: VMKind, verbose: bool, From 740d012ef26d3831b839aeabcd7248a7db51201e Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 14 Sep 2020 20:13:56 -0700 Subject: [PATCH 14/61] wip measure functions --- .../src/vm_estimator.rs | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 75d47b29883..223a3c8e25b 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -2,6 +2,7 @@ use crate::testbed_runners::end_count; use crate::testbed_runners::start_count; use crate::testbed_runners::GasMetric; use glob::glob; +use near_evm::builtins::Precompile; use near_evm_runner::run_evm; use near_primitives::version::PROTOCOL_VERSION; use near_runtime_fees::RuntimeFeesConfig; @@ -132,9 +133,9 @@ fn load_and_compile(path: &PathBuf, gas_metric: GasMetric, vm_kind: VMKind) -> O } } -struct EvmCost { - evm_gas: u64, - cost: Ratio, +pub struct EvmCost { + pub evm_gas: u64, + pub cost: Ratio, } fn deploy_evm_contract(code: &[u8], gas_metric: GasMetric) -> Option { @@ -178,8 +179,22 @@ const USING_LIGHTBEAM: bool = true; #[cfg(not(feature = "lightbeam"))] const USING_LIGHTBEAM: bool = false; -/// Cost of all evm related -pub fn cost_of_evm(gas_metric: GasMetric, verbose: bool) -> (Ratio, Ratio) { +pub struct EvmCostConfig { + pub deploy_cost: EvmCost, + pub run_cost: EvmCost, + pub ecRecoverCost: EvmCost, + pub sha256Cost: EvmCost, + pub ripemd160Cost: EvmCost, + pub identityCost: EvmCost, + pub modexpImplCost: EvmCost, + pub bn128AddImplCost: EvmCost, + pub bn128MulImplCost: EvmCost, + pub bn128PairingImplCost: EvmCost, + pub blake2FImplCost: EvmCost, + pub lastPrecompileCost: EvmCost, +} + +pub fn measure_evm_deploy(gas_metric: GasMetric, verbose: bool) -> (Ratio, Ratio) { let globbed_files = glob("./**/*.bin").expect("Failed to read glob pattern for bin files"); let paths = globbed_files .filter_map(|x| match x { @@ -224,6 +239,21 @@ pub fn cost_of_evm(gas_metric: GasMetric, verbose: bool) -> (Ratio, Ratio (Ratio, Ratio) { + let ratio = Ratio::new(0 as u64, 1); + let base = Ratio::new(u64::MAX, 1); + //TODO + (ratio, base) +} + +/// Cost of all evm related +pub fn cost_of_evm(gas_metric: GasMetric, verbose: bool) -> EvmCostConfig { + let mut evm_cost_config: EvmCostConfig; + evm_cost_config.deploy_cost = measure_deploy(gas_metric, verbose); + + evm_cost_config +} + /// Cost of the compile contract with vm_kind pub fn cost_to_compile( gas_metric: GasMetric, From c1f62106d6193f04491af3af3f71ccca8ce148aa Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 15 Sep 2020 14:56:46 -0700 Subject: [PATCH 15/61] fix deploy cost --- Cargo.lock | 1 + runtime/runtime-params-estimator/Cargo.toml | 1 + runtime/runtime-params-estimator/src/cases.rs | 9 ++-- .../src/vm_estimator.rs | 43 +++++++++---------- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ac0d8549738..58bbda15839 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4389,6 +4389,7 @@ dependencies = [ "csv", "glob 0.3.0", "gnuplot", + "hex", "indicatif 0.15.0", "near-crypto", "near-evm-runner", diff --git a/runtime/runtime-params-estimator/Cargo.toml b/runtime/runtime-params-estimator/Cargo.toml index dab48a7b3e7..0e3ab000927 100644 --- a/runtime/runtime-params-estimator/Cargo.toml +++ b/runtime/runtime-params-estimator/Cargo.toml @@ -29,6 +29,7 @@ rocksdb = { git = "https://github.com/nearprotocol/rust-rocksdb", branch="disabl glob = "0.3.0" walrus = "0.18.0" near-evm-runner = { path = "../../runtime/near-evm-runner" } +hex = "0.4" [features] default = [] diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index a539deb59b3..7330cefa1b1 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -158,9 +158,12 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon ); process::exit(0); } else if only_evm { - let (evm_cost, evm_base_cost) = cost_of_evm(config.metric, true); - let contract_byte_cost = ratio_to_gas(config.metric, evm_cost); - println!("{}, {}", contract_byte_cost, ratio_to_gas(config.metric, evm_base_cost)); + let cost = cost_of_evm(config.metric, true); + println!( + "EVM base deploy cost: {}, deploy cost per EVM gas: {}", + ratio_to_gas(config.metric, cost.deploy_cost.0), + ratio_to_gas(config.metric, cost.deploy_cost.1) + ); process::exit(0); } config.block_sizes = vec![100]; diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 223a3c8e25b..a9504f2c634 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -2,7 +2,6 @@ use crate::testbed_runners::end_count; use crate::testbed_runners::start_count; use crate::testbed_runners::GasMetric; use glob::glob; -use near_evm::builtins::Precompile; use near_evm_runner::run_evm; use near_primitives::version::PROTOCOL_VERSION; use near_runtime_fees::RuntimeFeesConfig; @@ -155,7 +154,7 @@ fn deploy_evm_contract(code: &[u8], gas_metric: GasMetric) -> Option { 0u128, 0u64, "deploy_code".to_string(), - code.into(), + hex::decode(&code).unwrap(), 1_000_000_000u64, false, ); @@ -179,22 +178,24 @@ const USING_LIGHTBEAM: bool = true; #[cfg(not(feature = "lightbeam"))] const USING_LIGHTBEAM: bool = false; -pub struct EvmCostConfig { - pub deploy_cost: EvmCost, - pub run_cost: EvmCost, - pub ecRecoverCost: EvmCost, - pub sha256Cost: EvmCost, - pub ripemd160Cost: EvmCost, - pub identityCost: EvmCost, - pub modexpImplCost: EvmCost, - pub bn128AddImplCost: EvmCost, - pub bn128MulImplCost: EvmCost, - pub bn128PairingImplCost: EvmCost, - pub blake2FImplCost: EvmCost, - pub lastPrecompileCost: EvmCost, +type Coef = (Ratio, Ratio); + +pub struct EvmCostCoef { + pub deploy_cost: Coef, + // pub run_cost: Coef, + // pub ecRecoverCost: Coef, + // pub sha256Cost: Coef, + // pub ripemd160Cost: Coef, + // pub identityCost: Coef, + // pub modexpImplCost: Coef, + // pub bn128AddImplCost: Coef, + // pub bn128MulImplCost: Coef, + // pub bn128PairingImplCost: Coef, + // pub blake2FImplCost: Coef, + // pub lastPrecompileCost: Coef, } -pub fn measure_evm_deploy(gas_metric: GasMetric, verbose: bool) -> (Ratio, Ratio) { +pub fn measure_evm_deploy(gas_metric: GasMetric, verbose: bool) -> Coef { let globbed_files = glob("./**/*.bin").expect("Failed to read glob pattern for bin files"); let paths = globbed_files .filter_map(|x| match x { @@ -229,7 +230,7 @@ pub fn measure_evm_deploy(gas_metric: GasMetric, verbose: bool) -> (Ratio, .filter(|x| x.is_some()) .map(|x| x.unwrap()) .collect::>(); - let b = measurements.iter().fold(base, |_b, EvmCost { evm_gas: _, cost }| base.min(*cost)); + let b = measurements.iter().fold(base, |b, EvmCost { evm_gas: _, cost }| b.min(*cost)); let m = measurements .iter() .fold(ratio, |r, EvmCost { evm_gas, cost }| r.max((*cost - b) / evm_gas)); @@ -239,7 +240,7 @@ pub fn measure_evm_deploy(gas_metric: GasMetric, verbose: bool) -> (Ratio, (m, b) } -pub fn measure_evm_run(gas_metric: GasMetric, verbose: bool) -> (Ratio, Ratio) { +pub fn measure_evm_run(gas_metric: GasMetric, verbose: bool) -> Coef { let ratio = Ratio::new(0 as u64, 1); let base = Ratio::new(u64::MAX, 1); //TODO @@ -247,10 +248,8 @@ pub fn measure_evm_run(gas_metric: GasMetric, verbose: bool) -> (Ratio, Rat } /// Cost of all evm related -pub fn cost_of_evm(gas_metric: GasMetric, verbose: bool) -> EvmCostConfig { - let mut evm_cost_config: EvmCostConfig; - evm_cost_config.deploy_cost = measure_deploy(gas_metric, verbose); - +pub fn cost_of_evm(gas_metric: GasMetric, verbose: bool) -> EvmCostCoef { + let evm_cost_config = EvmCostCoef { deploy_cost: measure_evm_deploy(gas_metric, verbose) }; evm_cost_config } From 299ae1283b5f4b8042cf25521181e28695fd3842 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 15 Sep 2020 18:02:02 -0700 Subject: [PATCH 16/61] measure funcall cost, start adding contract function to know precompile function cost --- Cargo.lock | 4 + runtime/near-evm-runner/tests/build.sh | 1 + .../tests/contracts/SolTests.sol | 54 +++++++ runtime/runtime-params-estimator/Cargo.toml | 4 + runtime/runtime-params-estimator/src/cases.rs | 5 + .../src/vm_estimator.rs | 142 +++++++++++++++--- 6 files changed, 192 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58bbda15839..3970c493440 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4387,10 +4387,14 @@ dependencies = [ "borsh", "clap 2.33.0", "csv", + "ethabi", + "ethabi-contract", + "ethabi-derive", "glob 0.3.0", "gnuplot", "hex", "indicatif 0.15.0", + "lazy-static-include", "near-crypto", "near-evm-runner", "near-primitives", diff --git a/runtime/near-evm-runner/tests/build.sh b/runtime/near-evm-runner/tests/build.sh index 391db5242a6..f6245fa2712 100755 --- a/runtime/near-evm-runner/tests/build.sh +++ b/runtime/near-evm-runner/tests/build.sh @@ -6,6 +6,7 @@ contracts=( "Create2Factory" "SelfDestruct" "ConstructorRevert" + "PrecompiledFunction" ) truffle compile || exit 1 diff --git a/runtime/near-evm-runner/tests/contracts/SolTests.sol b/runtime/near-evm-runner/tests/contracts/SolTests.sol index 0e6973c4e46..480306e769d 100644 --- a/runtime/near-evm-runner/tests/contracts/SolTests.sol +++ b/runtime/near-evm-runner/tests/contracts/SolTests.sol @@ -78,3 +78,57 @@ contract SubContract is ExposesBalance { function () external payable {} } + +contract PrecompiledFunction { + constructor() public payable {} + + function noop() public pure { + + } + + function testSha256() public pure returns bytes32 { + return sha256(""); + } + + function testEcrecover() public pure returns address { + return ecrecover( + hex"1111111111111111111111111111111111111111111111111111111111111111", + 27, + hex"b9f0bb08640d3c1c00761cdd0121209268f6fd3816bc98b9e6f3cc77bf82b698", // r + hex"12ac7a61788a0fdc0e19180f14c945a8e1088a27d92a74dce81c0981fb644744" // s + ); + } + + function testRipemd160() public pure returns bytes20 { + return ripemd160(""); + } + + // TODO: identity function, etc. doesn't exist in solidity need to be tested with evm assembly. + + function modexp(uint base, uint e, uint m) public view returns (uint o) { + assembly { + // define pointer + let p := mload(0x40) + // store data assembly-favouring ways + mstore(p, 0x20) // Length of Base + mstore(add(p, 0x20), 0x20) // Length of Exponent + mstore(add(p, 0x40), 0x20) // Length of Modulus + mstore(add(p, 0x60), base) // Base + mstore(add(p, 0x80), e) // Exponent + mstore(add(p, 0xa0), m) // Modulus + if iszero(staticcall(sub(gas, 2000), 0x05, p, 0xc0, p, 0x20)) { + revert(0, 0) + } + // data + o := mload(p) + } + } + + function testModExp() public pure returns uint { + return expmod(12345, 173, 101); + } + + function testBn128Add() public pure returns uint { + + } +} \ No newline at end of file diff --git a/runtime/runtime-params-estimator/Cargo.toml b/runtime/runtime-params-estimator/Cargo.toml index 0e3ab000927..744a80b3f21 100644 --- a/runtime/runtime-params-estimator/Cargo.toml +++ b/runtime/runtime-params-estimator/Cargo.toml @@ -30,6 +30,10 @@ glob = "0.3.0" walrus = "0.18.0" near-evm-runner = { path = "../../runtime/near-evm-runner" } hex = "0.4" +ethabi = "8.0.0" +ethabi-contract = "8.0.0" +ethabi-derive = "8.0.0" +lazy-static-include = "2.2.2" [features] default = [] diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index 7330cefa1b1..9578a1ddffd 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -164,6 +164,11 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon ratio_to_gas(config.metric, cost.deploy_cost.0), ratio_to_gas(config.metric, cost.deploy_cost.1) ); + println!( + "EVM function call cost: {}, function cost cost per EVM gas: {}", + ratio_to_gas(config.metric, cost.funcall_cost.0), + ratio_to_gas(config.metric, cost.funcall_cost.1) + ); process::exit(0); } config.block_sizes = vec![100]; diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index a9504f2c634..a9cf733fc10 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -1,8 +1,11 @@ use crate::testbed_runners::end_count; use crate::testbed_runners::start_count; use crate::testbed_runners::GasMetric; +use ethabi_contract::use_contract; use glob::glob; -use near_evm_runner::run_evm; +use lazy_static_include::lazy_static_include_str; +use near_evm_runner::utils::encode_call_function_args; +use near_evm_runner::{run_evm, EvmContext}; use near_primitives::version::PROTOCOL_VERSION; use near_runtime_fees::RuntimeFeesConfig; use near_vm_logic::mocks::mock_external::MockedExternal; @@ -182,7 +185,7 @@ type Coef = (Ratio, Ratio); pub struct EvmCostCoef { pub deploy_cost: Coef, - // pub run_cost: Coef, + pub funcall_cost: Coef, // pub ecRecoverCost: Coef, // pub sha256Cost: Coef, // pub ripemd160Cost: Coef, @@ -203,8 +206,6 @@ pub fn measure_evm_deploy(gas_metric: GasMetric, verbose: bool) -> Coef { _ => None, }) .collect::>(); - let ratio = Ratio::new(0 as u64, 1); - let base = Ratio::new(u64::MAX, 1); let measurements = paths .iter() @@ -230,26 +231,118 @@ pub fn measure_evm_deploy(gas_metric: GasMetric, verbose: bool) -> Coef { .filter(|x| x.is_some()) .map(|x| x.unwrap()) .collect::>(); - let b = measurements.iter().fold(base, |b, EvmCost { evm_gas: _, cost }| b.min(*cost)); - let m = measurements - .iter() - .fold(ratio, |r, EvmCost { evm_gas, cost }| r.max((*cost - b) / evm_gas)); - if verbose { - println!("raw data: ({},{})", m, b); - } - (m, b) + measurements_to_coef(measurements, true) } -pub fn measure_evm_run(gas_metric: GasMetric, verbose: bool) -> Coef { - let ratio = Ratio::new(0 as u64, 1); - let base = Ratio::new(u64::MAX, 1); - //TODO - (ratio, base) +use_contract!(soltest, "../near-evm-runner/tests/build/SolTests.abi"); +use_contract!(subcontract, "../near-evm-runner/tests/build/SubContract.abi"); +use_contract!(create2factory, "../near-evm-runner/tests/build/Create2Factory.abi"); +use_contract!(selfdestruct, "../near-evm-runner/tests/build/SelfDestruct.abi"); + +lazy_static_include_str!(TEST, "../near-evm-runner/tests/build/SolTests.bin"); +lazy_static_include_str!(SUBCONTRACT_TEST, "../near-evm-runner/tests/build/SubContract.bin"); +lazy_static_include_str!(FACTORY_TEST, "../near-evm-runner/tests/build/Create2Factory.bin"); +lazy_static_include_str!(DESTRUCT_TEST, "../near-evm-runner/tests/build/SelfDestruct.bin"); +lazy_static_include_str!(CONSTRUCTOR_TEST, "../near-evm-runner/tests/build/ConstructorRevert.bin"); + +pub fn create_evm_context<'a>( + external: &'a mut MockedExternal, + vm_config: &'a VMConfig, + fees_config: &'a RuntimeFeesConfig, + account_id: String, + attached_deposit: u128, +) -> EvmContext<'a> { + EvmContext::new( + external, + vm_config, + fees_config, + 1000, + account_id.to_string(), + attached_deposit, + 0, + 10u64.pow(14), + false, + ) +} + +pub fn measure_evm_funcall(gas_metric: GasMetric, verbose: bool) -> Coef { + let mut fake_external = MockedExternal::new(); + let config = VMConfig::default(); + let fees = RuntimeFeesConfig::default(); + + let mut context = + create_evm_context(&mut fake_external, &config, &fees, "alice".to_string(), 100); + let sol_test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); + // TODO: this deploy always fail with empty string error message + // let factory_test_addr = context.deploy_code(hex::decode(&FACTORY_TEST).unwrap()).unwrap(); + // let destruct_test_addr = context.deploy_code(hex::decode(&DESTRUCT_TEST).unwrap()).unwrap(); + // let constructor_test_addr = + // context.deploy_code(hex::decode(&CONSTRUCTOR_TEST).unwrap()).unwrap(); + let subcontract_test_addr = + context.deploy_code(hex::decode(&SUBCONTRACT_TEST).unwrap()).unwrap(); + + let measurements = vec![ + measure_evm_function( + gas_metric, + verbose, + &mut context, + encode_call_function_args(sol_test_addr, soltest::functions::deploy_new_guy::call(8).0), + ), + measure_evm_function( + gas_metric, + verbose, + &mut context, + encode_call_function_args( + subcontract_test_addr, + subcontract::functions::a_number::call().0, + ), + ), + measure_evm_function( + gas_metric, + verbose, + &mut context, + encode_call_function_args(sol_test_addr, soltest::functions::pay_new_guy::call(8).0), + ), + measure_evm_function( + gas_metric, + verbose, + &mut context, + encode_call_function_args( + sol_test_addr, + soltest::functions::return_some_funds::call().0, + ), + ), + ]; + + measurements_to_coef(measurements, true) +} + +pub fn measure_evm_function( + gas_metric: GasMetric, + verbose: bool, + context: &mut EvmContext, + args: Vec, +) -> EvmCost { + let start = start_count(gas_metric); + let mut evm_gas = 0; + for i in 0..NUM_ITERATIONS { + if i == 0 { + evm_gas = context.evm_gas_counter.used_gas.as_u64(); + } else if i == 1 { + evm_gas = context.evm_gas_counter.used_gas.as_u64() - evm_gas; + } + let _ = context.call_function(args.clone()).unwrap(); + } + let end = end_count(gas_metric, &start); + EvmCost { evm_gas, cost: Ratio::new(end, NUM_ITERATIONS) } } /// Cost of all evm related pub fn cost_of_evm(gas_metric: GasMetric, verbose: bool) -> EvmCostCoef { - let evm_cost_config = EvmCostCoef { deploy_cost: measure_evm_deploy(gas_metric, verbose) }; + let evm_cost_config = EvmCostCoef { + deploy_cost: measure_evm_deploy(gas_metric, verbose), + funcall_cost: measure_evm_funcall(gas_metric, verbose), + }; evm_cost_config } @@ -313,6 +406,19 @@ pub fn cost_to_compile( (m, b) } +fn measurements_to_coef(measurements: Vec, verbose: bool) -> Coef { + let ratio = Ratio::new(0 as u64, 1); + let base = Ratio::new(u64::MAX, 1); + let b = measurements.iter().fold(base, |b, EvmCost { evm_gas: _, cost }| b.min(*cost)); + let m = measurements + .iter() + .fold(ratio, |r, EvmCost { evm_gas, cost }| r.max((*cost - b) / evm_gas)); + if verbose { + println!("raw data: ({},{})", m, b); + } + (m, b) +} + fn delete_all_data(wasm_bin: &mut Vec) -> Result<&Vec> { let m = &mut Module::from_buffer(wasm_bin)?; for id in get_ids(m.data.iter().map(|t| t.id())) { From 15445f4085e89a97496c6e4e8f62dafb6583b006 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Wed, 16 Sep 2020 17:20:49 -0700 Subject: [PATCH 17/61] all cost countings except bn256 precompiled functions --- runtime/near-evm-runner/src/lib.rs | 2 +- .../tests/build/ConstructorRevert.bin | 2 +- .../tests/build/Create2Factory.bin | 2 +- .../tests/build/PrecompiledFunction.abi | 159 +++++++++++++++++ .../tests/build/PrecompiledFunction.bin | 1 + .../tests/build/SelfDestruct.bin | 2 +- .../near-evm-runner/tests/build/SolTests.bin | 2 +- .../tests/build/SubContract.bin | 2 +- .../tests/contracts/SolTests.sol | 32 +++- runtime/near-runtime-fees/src/lib.rs | 41 +++++ runtime/runtime-params-estimator/src/cases.rs | 26 ++- .../src/vm_estimator.rs | 163 ++++++++++++++---- 12 files changed, 382 insertions(+), 52 deletions(-) create mode 100644 runtime/near-evm-runner/tests/build/PrecompiledFunction.abi create mode 100644 runtime/near-evm-runner/tests/build/PrecompiledFunction.bin diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 8f3d0b7f1d4..fa251320b3b 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -28,7 +28,7 @@ pub struct EvmContext<'a> { ext: &'a mut dyn External, predecessor_id: AccountId, current_amount: Balance, - attached_deposit: Balance, + pub attached_deposit: Balance, storage_usage: StorageUsage, pub logs: Vec, gas_counter: GasCounter, diff --git a/runtime/near-evm-runner/tests/build/ConstructorRevert.bin b/runtime/near-evm-runner/tests/build/ConstructorRevert.bin index eba8500764a..9aecd04cac3 100644 --- a/runtime/near-evm-runner/tests/build/ConstructorRevert.bin +++ b/runtime/near-evm-runner/tests/build/ConstructorRevert.bin @@ -1 +1 @@ -6080604052348015600f57600080fd5b5060056004146086576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f4572726f72204465706c6f79696e6720436f6e7472616374000000000000000081525060200191505060405180910390fd5b603e8060936000396000f3fe6080604052600080fdfea265627a7a723158203667e47f55606e5f72d16e0d9a81ed4435273fcfa1ee79bf9545dc524d930d2f64736f6c63430005100032 \ No newline at end of file +6080604052348015600f57600080fd5b5060056004146086576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f4572726f72204465706c6f79696e6720436f6e7472616374000000000000000081525060200191505060405180910390fd5b603e8060936000396000f3fe6080604052600080fdfea265627a7a723158204c0402b3a7eae0076263c6db45742f127c7bc67cbdef410b2d6d40f721e3896a64736f6c63430005100032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/Create2Factory.bin b/runtime/near-evm-runner/tests/build/Create2Factory.bin index da4baf5279f..5c18234a6ab 100644 --- a/runtime/near-evm-runner/tests/build/Create2Factory.bin +++ b/runtime/near-evm-runner/tests/build/Create2Factory.bin @@ -1 +1 @@ -608060405234801561001057600080fd5b50610758806100206000396000f3fe6080604052600436106100295760003560e01c80639f45e8151461002b578063cdcb760a14610108575b005b6100ee6004803603604081101561004157600080fd5b81019080803590602001909291908035906020019064010000000081111561006857600080fd5b82018360208201111561007a57600080fd5b8035906020019184600183028401116401000000008311171561009c57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061021a565b604051808215151515815260200191505060405180910390f35b34801561011457600080fd5b506101d86004803603604081101561012b57600080fd5b81019080803590602001909291908035906020019064010000000081111561015257600080fd5b82018360208201111561016457600080fd5b8035906020019184600183028401116401000000008311171561018657600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506106c7565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60008061022784846106c7565b905060008190508073ffffffffffffffffffffffffffffffffffffffff1663eef4c90f60056040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561028257600080fd5b505af1158015610296573d6000803e3d6000fd5b5050505060058173ffffffffffffffffffffffffffffffffffffffff16636e4d2a346040518163ffffffff1660e01b815260040160206040518083038186803b1580156102e257600080fd5b505afa1580156102f6573d6000803e3d6000fd5b505050506040513d602081101561030c57600080fd5b810190808051906020019092919050505014610390576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f7072652d6465737472756374696f6e2077726f6e672075696e7400000000000081525060200191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1663d37c6c9e6040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156103d857600080fd5b505af11580156103ec573d6000803e3d6000fd5b5050505060606103fb826106db565b90506000815114610474576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f706f73742d6465737472756374696f6e20636f6465206c656e6774680000000081525060200191505060405180910390fd5b61047e86866106c7565b5060008273ffffffffffffffffffffffffffffffffffffffff16636e4d2a346040518163ffffffff1660e01b815260040160206040518083038186803b1580156104c757600080fd5b505afa1580156104db573d6000803e3d6000fd5b505050506040513d60208110156104f157600080fd5b810190808051906020019092919050505014610575576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f706f73742d6465737472756374696f6e2077726f6e672075696e74000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff1663eef4c90f60036040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156105c957600080fd5b505af11580156105dd573d6000803e3d6000fd5b5050505060038273ffffffffffffffffffffffffffffffffffffffff16636e4d2a346040518163ffffffff1660e01b815260040160206040518083038186803b15801561062957600080fd5b505afa15801561063d573d6000803e3d6000fd5b505050506040513d602081101561065357600080fd5b8101908080519060200190929190505050146106ba576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806107026022913960400191505060405180910390fd5b6001935050505092915050565b6000828251602084016000f5905092915050565b60606040519050813b8082526020820181600082863c818352818101604052505091905056fe706f73742d6465737472756374696f6e2073746f7265642077726f6e672075696e74a265627a7a7231582057b6addf30c31c49aa94429f78664940ffa8f1922153be7c94c853fa4932031c64736f6c63430005100032 \ No newline at end of file +608060405234801561001057600080fd5b50610758806100206000396000f3fe6080604052600436106100295760003560e01c80639f45e8151461002b578063cdcb760a14610108575b005b6100ee6004803603604081101561004157600080fd5b81019080803590602001909291908035906020019064010000000081111561006857600080fd5b82018360208201111561007a57600080fd5b8035906020019184600183028401116401000000008311171561009c57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061021a565b604051808215151515815260200191505060405180910390f35b34801561011457600080fd5b506101d86004803603604081101561012b57600080fd5b81019080803590602001909291908035906020019064010000000081111561015257600080fd5b82018360208201111561016457600080fd5b8035906020019184600183028401116401000000008311171561018657600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506106c7565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b60008061022784846106c7565b905060008190508073ffffffffffffffffffffffffffffffffffffffff1663eef4c90f60056040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561028257600080fd5b505af1158015610296573d6000803e3d6000fd5b5050505060058173ffffffffffffffffffffffffffffffffffffffff16636e4d2a346040518163ffffffff1660e01b815260040160206040518083038186803b1580156102e257600080fd5b505afa1580156102f6573d6000803e3d6000fd5b505050506040513d602081101561030c57600080fd5b810190808051906020019092919050505014610390576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f7072652d6465737472756374696f6e2077726f6e672075696e7400000000000081525060200191505060405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1663d37c6c9e6040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156103d857600080fd5b505af11580156103ec573d6000803e3d6000fd5b5050505060606103fb826106db565b90506000815114610474576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f706f73742d6465737472756374696f6e20636f6465206c656e6774680000000081525060200191505060405180910390fd5b61047e86866106c7565b5060008273ffffffffffffffffffffffffffffffffffffffff16636e4d2a346040518163ffffffff1660e01b815260040160206040518083038186803b1580156104c757600080fd5b505afa1580156104db573d6000803e3d6000fd5b505050506040513d60208110156104f157600080fd5b810190808051906020019092919050505014610575576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f706f73742d6465737472756374696f6e2077726f6e672075696e74000000000081525060200191505060405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff1663eef4c90f60036040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156105c957600080fd5b505af11580156105dd573d6000803e3d6000fd5b5050505060038273ffffffffffffffffffffffffffffffffffffffff16636e4d2a346040518163ffffffff1660e01b815260040160206040518083038186803b15801561062957600080fd5b505afa15801561063d573d6000803e3d6000fd5b505050506040513d602081101561065357600080fd5b8101908080519060200190929190505050146106ba576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806107026022913960400191505060405180910390fd5b6001935050505092915050565b6000828251602084016000f5905092915050565b60606040519050813b8082526020820181600082863c818352818101604052505091905056fe706f73742d6465737472756374696f6e2073746f7265642077726f6e672075696e74a265627a7a72315820e8aa482dbb1ad5a50769172bb326b40795aaa96e6340d1443c2ce7fdf22f071564736f6c63430005100032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/PrecompiledFunction.abi b/runtime/near-evm-runner/tests/build/PrecompiledFunction.abi new file mode 100644 index 00000000000..4e03798cbd8 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/PrecompiledFunction.abi @@ -0,0 +1,159 @@ +[ + { + "inputs": [], + "payable": true, + "stateMutability": "payable", + "type": "constructor" + }, + { + "constant": true, + "inputs": [], + "name": "noop", + "outputs": [], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "testSha256", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "testEcrecover", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "testRipemd160", + "outputs": [ + { + "internalType": "bytes20", + "name": "", + "type": "bytes20" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "identity", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "test_identity", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "base", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "e", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "m", + "type": "uint256" + } + ], + "name": "modexp", + "outputs": [ + { + "internalType": "uint256", + "name": "o", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "testModExp", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "testBn128Add", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/PrecompiledFunction.bin b/runtime/near-evm-runner/tests/build/PrecompiledFunction.bin new file mode 100644 index 00000000000..36be42fb21b --- /dev/null +++ b/runtime/near-evm-runner/tests/build/PrecompiledFunction.bin @@ -0,0 +1 @@ +6080604052610627806100136000396000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c80638a6fa9da116100665780638a6fa9da146102a3578063a449e8eb146102c1578063a7d4bbe6146102df578063b7a0961a14610335578063e96cc75c1461037157610093565b80631d82afc714610098578063511636701461011b5780635dfc2e4a14610165578063840f61201461016f575b600080fd5b6100a061038f565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100e05780820151818401526020810190506100c5565b50505050905090810190601f16801561010d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101236103d4565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61016d6104a0565b005b6102286004803603602081101561018557600080fd5b81019080803590602001906401000000008111156101a257600080fd5b8201836020820111156101b457600080fd5b803590602001918460018302840111640100000000831117156101d657600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506104a2565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561026857808201518184015260208101905061024d565b50505050905090810190601f1680156102955780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102ab6104fe565b6040518082815260200191505060405180910390f35b6102c9610503565b6040518082815260200191505060405180910390f35b61031f600480360360608110156102f557600080fd5b81019080803590602001909291908035906020019092919080359060200190929190505050610558565b6040518082815260200191505060405180910390f35b61033d6105a3565b60405180826bffffffffffffffffffffffff19166bffffffffffffffffffffffff1916815260200191505060405180910390f35b6103796105dc565b6040518082815260200191505060405180910390f35b60606103cf6040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152506104a2565b905090565b60006001601b6040516000815260200160405260405180807f11111111111111111111111111111111111111111111111111111111111111118152506020018260ff168152602001807fb9f0bb08640d3c1c00761cdd0121209268f6fd3816bc98b9e6f3cc77bf82b698815250602001807f12ac7a61788a0fdc0e19180f14c945a8e1088a27d92a74dce81c0981fb6447448152506020019150506020604051602081039080840390855afa158015610491573d6000803e3d6000fd5b50505060206040510351905090565b565b60608082516040519080825280601f01601f1916602001820160405280156104d95781602001600182028038833980820191505090505b509050825180602083018260208701600060045af16104f457fe5b5080915050919050565b600090565b60006002604051806000019050602060405180830381855afa15801561052d573d6000803e3d6000fd5b5050506040513d602081101561054257600080fd5b8101908080519060200190929190505050905090565b600060405160208152602080820152602060408201528460608201528360808201528260a082015260208160c08360056107d05a03fa61059757600080fd5b80519150509392505050565b60006003604051806000019050602060405180830381855afa1580156105cd573d6000803e3d6000fd5b5050506040515160601b905090565b60006105ed61303960ad6065610558565b90509056fea265627a7a723158206718ad0764da1eb7d9b1547a52115ca6598c9725f9fc7c88300679d157bbb89c64736f6c63430005100032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/SelfDestruct.bin b/runtime/near-evm-runner/tests/build/SelfDestruct.bin index fdf024159ad..176353f70ea 100644 --- a/runtime/near-evm-runner/tests/build/SelfDestruct.bin +++ b/runtime/near-evm-runner/tests/build/SelfDestruct.bin @@ -1 +1 @@ -608060405234801561001057600080fd5b506101fc806100206000396000f3fe60806040526004361061004a5760003560e01c80636e4d2a341461004c5780638f63640e14610077578063d37c6c9e146100ce578063eef4c90f146100e5578063f2c4da9314610120575b005b34801561005857600080fd5b50610061610137565b6040518082815260200191505060405180910390f35b34801561008357600080fd5b5061008c61013d565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100da57600080fd5b506100e3610162565b005b3480156100f157600080fd5b5061011e6004803603602081101561010857600080fd5b810190808035906020019092919050505061017b565b005b34801561012c57600080fd5b50610135610185565b005b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b3373ffffffffffffffffffffffffffffffffffffffff16ff5b8060018190555050565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555056fea265627a7a7231582049134aca36ca008aa7d94838f31a297f561997c03ec02dedcb7b63aa26289cd664736f6c63430005100032 \ No newline at end of file +608060405234801561001057600080fd5b506101fc806100206000396000f3fe60806040526004361061004a5760003560e01c80636e4d2a341461004c5780638f63640e14610077578063d37c6c9e146100ce578063eef4c90f146100e5578063f2c4da9314610120575b005b34801561005857600080fd5b50610061610137565b6040518082815260200191505060405180910390f35b34801561008357600080fd5b5061008c61013d565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100da57600080fd5b506100e3610162565b005b3480156100f157600080fd5b5061011e6004803603602081101561010857600080fd5b810190808035906020019092919050505061017b565b005b34801561012c57600080fd5b50610135610185565b005b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b3373ffffffffffffffffffffffffffffffffffffffff16ff5b8060018190555050565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555056fea265627a7a72315820bc2518d7325b1a42a627271a1c315221090ec42188a01825fcea78176392f4c164736f6c63430005100032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/SolTests.bin b/runtime/near-evm-runner/tests/build/SolTests.bin index 186505b4e7f..dd6826bc417 100644 --- a/runtime/near-evm-runner/tests/build/SolTests.bin +++ b/runtime/near-evm-runner/tests/build/SolTests.bin @@ -1 +1 @@ -6080604052610a87806100136000396000f3fe6080604052600436106100705760003560e01c8063299fb0431161004e578063299fb043146101af5780632ccb1b30146101c65780639d9f9a6e14610235578063b69ef8a81461028657610070565b80630a84cba514610072578063111e0b12146100e757806314d54f541461015c575b005b61009e6004803603602081101561008857600080fd5b81019080803590602001909291905050506102b1565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b610113600480360360208110156100fd57600080fd5b8101908080359060200190929190505050610390565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b34801561016857600080fd5b506101956004803603602081101561017f57600080fd5b81019080803590602001909291905050506103dc565b604051808215151515815260200191505060405180910390f35b3480156101bb57600080fd5b506101c461041e565b005b3480156101d257600080fd5b5061021f600480360360408110156101e957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610756565b6040518082815260200191505060405180910390f35b61023d6107af565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b34801561029257600080fd5b5061029b610810565b6040518082815260200191505060405180910390f35b6000806000836040516102c390610818565b80828152602001915050604051809103906000f0801580156102e9573d6000803e3d6000fd5b5090508073ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f19350505050158015610332573d6000803e3d6000fd5b508073ffffffffffffffffffffffffffffffffffffffff167fa53ffc4fb91f5ca8287e168fc73db3b0b384a6ca275650f885a1740ef7a0bc1c346040518082815260200191505060405180910390a280348191509250925050915091565b600080600034846040516103a390610818565b808281526020019150506040518091039082f0801580156103c8573d6000803e3d6000fd5b509050905080348191509250925050915091565b60007f379340f64b65a8890c7ea4f6d86d2359beaf41080f36a7ea64b78a2c06eee3f0826040518082815260200191505060405180910390a160019050919050565b7fe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8556002604051806000019050602060405180830381855afa158015610467573d6000803e3d6000fd5b5050506040513d602081101561047c57600080fd5b810190808051906020019092919050505014610500576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f7368613220646967657374206d69736d6174636800000000000000000000000081525060200191505060405180910390fd5b7f9c1185a5c5e9fc54612808977ee8f548b2258d310000000000000000000000006003604051806000019050602060405180830381855afa158015610549573d6000803e3d6000fd5b5050506040515160601b6bffffffffffffffffffffffff1916146105d5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f726d6431363020646967657374206d69736d617463680000000000000000000081525060200191505060405180910390fd5b60006001601b6040516000815260200160405260405180807f11111111111111111111111111111111111111111111111111111111111111118152506020018260ff168152602001807fb9f0bb08640d3c1c00761cdd0121209268f6fd3816bc98b9e6f3cc77bf82b698815250602001807f12ac7a61788a0fdc0e19180f14c945a8e1088a27d92a74dce81c0981fb6447448152506020019150506020604051602081039080840390855afa158015610692573d6000803e3d6000fd5b505050602060405103519050731563915e194d8cfba1943570603f7606a311550873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610753576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f65637265636f766572206d69736d61746368000000000000000000000000000081525060200191505060405180910390fd5b50565b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561079e573d6000803e3d6000fd5b506107a7610810565b905092915050565b6000803373ffffffffffffffffffffffffffffffffffffffff166108fc600234816107d657fe5b049081150290604051600060405180830381858888f19350505050158015610802573d6000803e3d6000fd5b503334819150915091509091565b600047905090565b61022d806108268339019056fe6080604052600660005560405161022d38038061022d8339818101604052602081101561002b57600080fd5b810190808051906020019092919050505080600081905550506101da806100536000396000f3fe60806040526004361061003f5760003560e01c80632ccb1b301461004157806339c117a4146100b0578063b69ef8a8146100df578063e6a899b61461010a575b005b34801561004d57600080fd5b5061009a6004803603604081101561006457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610135565b6040518082815260200191505060405180910390f35b3480156100bc57600080fd5b506100c561018e565b604051808215151515815260200191505060405180910390f35b3480156100eb57600080fd5b506100f4610197565b6040518082815260200191505060405180910390f35b34801561011657600080fd5b5061011f61019f565b6040518082815260200191505060405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561017d573d6000803e3d6000fd5b50610186610197565b905092915050565b60006001905090565b600047905090565b6000548156fea265627a7a72315820bc102b3933ad6112eb436087a67714bf08814e4c202d3118307a3e280f47b6cb64736f6c63430005100032a265627a7a72315820fe8c0773a06b1128d9c03d755c55071d775ebea7ee4959a672d257e75225a51064736f6c63430005100032 \ No newline at end of file +6080604052610a87806100136000396000f3fe6080604052600436106100705760003560e01c8063299fb0431161004e578063299fb043146101af5780632ccb1b30146101c65780639d9f9a6e14610235578063b69ef8a81461028657610070565b80630a84cba514610072578063111e0b12146100e757806314d54f541461015c575b005b61009e6004803603602081101561008857600080fd5b81019080803590602001909291905050506102b1565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b610113600480360360208110156100fd57600080fd5b8101908080359060200190929190505050610390565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b34801561016857600080fd5b506101956004803603602081101561017f57600080fd5b81019080803590602001909291905050506103dc565b604051808215151515815260200191505060405180910390f35b3480156101bb57600080fd5b506101c461041e565b005b3480156101d257600080fd5b5061021f600480360360408110156101e957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610756565b6040518082815260200191505060405180910390f35b61023d6107af565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b34801561029257600080fd5b5061029b610810565b6040518082815260200191505060405180910390f35b6000806000836040516102c390610818565b80828152602001915050604051809103906000f0801580156102e9573d6000803e3d6000fd5b5090508073ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f19350505050158015610332573d6000803e3d6000fd5b508073ffffffffffffffffffffffffffffffffffffffff167fa53ffc4fb91f5ca8287e168fc73db3b0b384a6ca275650f885a1740ef7a0bc1c346040518082815260200191505060405180910390a280348191509250925050915091565b600080600034846040516103a390610818565b808281526020019150506040518091039082f0801580156103c8573d6000803e3d6000fd5b509050905080348191509250925050915091565b60007f379340f64b65a8890c7ea4f6d86d2359beaf41080f36a7ea64b78a2c06eee3f0826040518082815260200191505060405180910390a160019050919050565b7fe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8556002604051806000019050602060405180830381855afa158015610467573d6000803e3d6000fd5b5050506040513d602081101561047c57600080fd5b810190808051906020019092919050505014610500576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f7368613220646967657374206d69736d6174636800000000000000000000000081525060200191505060405180910390fd5b7f9c1185a5c5e9fc54612808977ee8f548b2258d310000000000000000000000006003604051806000019050602060405180830381855afa158015610549573d6000803e3d6000fd5b5050506040515160601b6bffffffffffffffffffffffff1916146105d5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f726d6431363020646967657374206d69736d617463680000000000000000000081525060200191505060405180910390fd5b60006001601b6040516000815260200160405260405180807f11111111111111111111111111111111111111111111111111111111111111118152506020018260ff168152602001807fb9f0bb08640d3c1c00761cdd0121209268f6fd3816bc98b9e6f3cc77bf82b698815250602001807f12ac7a61788a0fdc0e19180f14c945a8e1088a27d92a74dce81c0981fb6447448152506020019150506020604051602081039080840390855afa158015610692573d6000803e3d6000fd5b505050602060405103519050731563915e194d8cfba1943570603f7606a311550873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610753576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f65637265636f766572206d69736d61746368000000000000000000000000000081525060200191505060405180910390fd5b50565b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561079e573d6000803e3d6000fd5b506107a7610810565b905092915050565b6000803373ffffffffffffffffffffffffffffffffffffffff166108fc600234816107d657fe5b049081150290604051600060405180830381858888f19350505050158015610802573d6000803e3d6000fd5b503334819150915091509091565b600047905090565b61022d806108268339019056fe6080604052600660005560405161022d38038061022d8339818101604052602081101561002b57600080fd5b810190808051906020019092919050505080600081905550506101da806100536000396000f3fe60806040526004361061003f5760003560e01c80632ccb1b301461004157806339c117a4146100b0578063b69ef8a8146100df578063e6a899b61461010a575b005b34801561004d57600080fd5b5061009a6004803603604081101561006457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610135565b6040518082815260200191505060405180910390f35b3480156100bc57600080fd5b506100c561018e565b604051808215151515815260200191505060405180910390f35b3480156100eb57600080fd5b506100f4610197565b6040518082815260200191505060405180910390f35b34801561011657600080fd5b5061011f61019f565b6040518082815260200191505060405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561017d573d6000803e3d6000fd5b50610186610197565b905092915050565b60006001905090565b600047905090565b6000548156fea265627a7a72315820f6f44f505670bac22a9333cd975c317fbaa88dc23152a224b1341fc02dd8764264736f6c63430005100032a265627a7a723158205890404b6d6a9f080f4d5156523ec567b299609c5d3e45e4baf5c0ee35c7a68764736f6c63430005100032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/SubContract.bin b/runtime/near-evm-runner/tests/build/SubContract.bin index 54225e72d6b..2bab6cfd357 100644 --- a/runtime/near-evm-runner/tests/build/SubContract.bin +++ b/runtime/near-evm-runner/tests/build/SubContract.bin @@ -1 +1 @@ -6080604052600660005560405161022d38038061022d8339818101604052602081101561002b57600080fd5b810190808051906020019092919050505080600081905550506101da806100536000396000f3fe60806040526004361061003f5760003560e01c80632ccb1b301461004157806339c117a4146100b0578063b69ef8a8146100df578063e6a899b61461010a575b005b34801561004d57600080fd5b5061009a6004803603604081101561006457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610135565b6040518082815260200191505060405180910390f35b3480156100bc57600080fd5b506100c561018e565b604051808215151515815260200191505060405180910390f35b3480156100eb57600080fd5b506100f4610197565b6040518082815260200191505060405180910390f35b34801561011657600080fd5b5061011f61019f565b6040518082815260200191505060405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561017d573d6000803e3d6000fd5b50610186610197565b905092915050565b60006001905090565b600047905090565b6000548156fea265627a7a72315820bc102b3933ad6112eb436087a67714bf08814e4c202d3118307a3e280f47b6cb64736f6c63430005100032 \ No newline at end of file +6080604052600660005560405161022d38038061022d8339818101604052602081101561002b57600080fd5b810190808051906020019092919050505080600081905550506101da806100536000396000f3fe60806040526004361061003f5760003560e01c80632ccb1b301461004157806339c117a4146100b0578063b69ef8a8146100df578063e6a899b61461010a575b005b34801561004d57600080fd5b5061009a6004803603604081101561006457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610135565b6040518082815260200191505060405180910390f35b3480156100bc57600080fd5b506100c561018e565b604051808215151515815260200191505060405180910390f35b3480156100eb57600080fd5b506100f4610197565b6040518082815260200191505060405180910390f35b34801561011657600080fd5b5061011f61019f565b6040518082815260200191505060405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561017d573d6000803e3d6000fd5b50610186610197565b905092915050565b60006001905090565b600047905090565b6000548156fea265627a7a72315820f6f44f505670bac22a9333cd975c317fbaa88dc23152a224b1341fc02dd8764264736f6c63430005100032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/contracts/SolTests.sol b/runtime/near-evm-runner/tests/contracts/SolTests.sol index 480306e769d..686aaf2d815 100644 --- a/runtime/near-evm-runner/tests/contracts/SolTests.sol +++ b/runtime/near-evm-runner/tests/contracts/SolTests.sol @@ -86,11 +86,11 @@ contract PrecompiledFunction { } - function testSha256() public pure returns bytes32 { + function testSha256() public pure returns (bytes32) { return sha256(""); } - function testEcrecover() public pure returns address { + function testEcrecover() public pure returns (address) { return ecrecover( hex"1111111111111111111111111111111111111111111111111111111111111111", 27, @@ -99,12 +99,26 @@ contract PrecompiledFunction { ); } - function testRipemd160() public pure returns bytes20 { + function testRipemd160() public pure returns (bytes20) { return ripemd160(""); } - // TODO: identity function, etc. doesn't exist in solidity need to be tested with evm assembly. - + function identity(bytes memory data) public returns (bytes memory) { + bytes memory ret = new bytes(data.length); + assembly { + let len := mload(data) + if iszero(call(gas, 0x04, 0, add(data, 0x20), len, add(ret,0x20), len)) { + invalid() + } + } + + return ret; + } + + function test_identity() public returns (bytes memory) { + return identity("0"); + } + function modexp(uint base, uint e, uint m) public view returns (uint o) { assembly { // define pointer @@ -124,11 +138,11 @@ contract PrecompiledFunction { } } - function testModExp() public pure returns uint { - return expmod(12345, 173, 101); + function testModExp() public view returns (uint) { + return modexp(12345, 173, 101); } - function testBn128Add() public pure returns uint { - + function testBn128Add() public pure returns (uint) { + } } \ No newline at end of file diff --git a/runtime/near-runtime-fees/src/lib.rs b/runtime/near-runtime-fees/src/lib.rs index 6e484a2a4be..5dfa4f0e111 100644 --- a/runtime/near-runtime-fees/src/lib.rs +++ b/runtime/near-runtime-fees/src/lib.rs @@ -63,6 +63,9 @@ pub struct RuntimeFeesConfig { /// Pessimistic gas price inflation ratio. pub pessimistic_gas_price_inflation_ratio: Rational, + + /// Describes cost of running method of evm, include deploy code and call contract function + pub evm_config: EvmCostConfig, } /// Describes the cost of creating a data receipt, `DataReceipt`. @@ -135,6 +138,26 @@ pub struct StorageUsageConfig { pub num_extra_bytes_record: u64, } +/// Describe cost of evm +#[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)] +pub struct EvmCostConfig { + /// Base cost of instantiate an evm instance for any evm operation + pub bootstrap_cost: u64, + /// For every unit of gas used by evm in funcall, equivalent near gas cost + pub funcall_cost_per_evm_gas: u64, + // Base cost of instantiate an evm instance and deploy minimum contract + pub deploy_base_cost: u64, + /// For every unit of gas used by evm in deploy evm contract, equivalent near gas cost + pub deploy_cost_per_evm_gas: u64, + + /// Evm precompiled function costs + pub ecrecover_cost: u64, + pub sha256_cost: u64, + pub ripemd160_cost: u64, + pub identity_cost: u64, + pub modexp_cost: u64, +} + impl Default for RuntimeFeesConfig { fn default() -> Self { #[allow(clippy::unreadable_literal)] @@ -228,6 +251,15 @@ impl Default for RuntimeFeesConfig { }, burnt_gas_reward: Rational::new(3, 10), pessimistic_gas_price_inflation_ratio: Rational::new(103, 100), + evm_config: EvmCostConfig { + bootstrap_cost: 0, + per_evm_gas_cost: 0, + ecrecover_cost: 0, + sha256_cost: 0, + ripemd160_cost: 0, + identity_cost: 0, + modexp_cost: 0, + }, } } } @@ -263,6 +295,15 @@ impl RuntimeFeesConfig { }, burnt_gas_reward: Rational::from_integer(0), pessimistic_gas_price_inflation_ratio: Rational::from_integer(0), + evm_config: EvmCostConfig { + bootstrap_cost: 0, + per_evm_gas_cost: 0, + ecrecover_cost: 0, + sha256_cost: 0, + ripemd160_cost: 0, + identity_cost: 0, + modexp_cost: 0, + }, } } diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index 9578a1ddffd..e5e66d2e1e5 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -20,7 +20,7 @@ use crate::stats::Measurements; use crate::testbed::RuntimeTestbed; use crate::testbed_runners::GasMetric; use crate::testbed_runners::{get_account_id, measure_actions, measure_transactions, Config}; -use crate::vm_estimator::{cost_of_evm, cost_per_op, cost_to_compile}; +use crate::vm_estimator::{cost_of_evm, cost_per_op, cost_to_compile, near_cost_to_evm_gas}; use near_runtime_fees::{ AccessKeyCreationConfig, ActionCreationConfig, DataReceiptCreationConfig, Fee, RuntimeFeesConfig, @@ -165,10 +165,32 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon ratio_to_gas(config.metric, cost.deploy_cost.1) ); println!( - "EVM function call cost: {}, function cost cost per EVM gas: {}", + "EVM function call cost: {}, function call cost per EVM gas: {}", ratio_to_gas(config.metric, cost.funcall_cost.0), ratio_to_gas(config.metric, cost.funcall_cost.1) ); + println!("EVM precompiled function evm gas:"); + println!( + "ecrecover: {}", + near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.ecRecoverCost) + ); + println!( + "sha256: {}", + near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.sha256Cost) + ); + println!( + "ripemd160: {}", + near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.ripemd160Cost) + ); + println!( + "identity: {}", + near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.identityCost) + ); + println!( + "modexp: {}", + near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.modexpImplCost) + ); + process::exit(0); } config.block_sizes = vec![100]; diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index a9cf733fc10..db3c00b9222 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -13,6 +13,7 @@ use near_vm_logic::{VMConfig, VMContext, VMKind, VMOutcome}; use near_vm_runner::{compile_module, prepare, VMError}; use num_rational::Ratio; use std::collections::hash_map::DefaultHasher; +use std::convert::TryFrom; use std::fs; use std::{ hash::{Hash, Hasher}, @@ -183,19 +184,23 @@ const USING_LIGHTBEAM: bool = false; type Coef = (Ratio, Ratio); +pub struct EvmPrecompiledFunctionCost { + pub ecRecoverCost: Ratio, + pub sha256Cost: Ratio, + pub ripemd160Cost: Ratio, + pub identityCost: Ratio, + pub modexpImplCost: Ratio, + // pub bn128AddImplCost: Ratio, + // pub bn128MulImplCost: Ratio, + // pub bn128PairingImplCost: Ratio, + // pub blake2FImplCost: Ratio, + // pub lastPrecompileCost: Ratio, +} + pub struct EvmCostCoef { pub deploy_cost: Coef, pub funcall_cost: Coef, - // pub ecRecoverCost: Coef, - // pub sha256Cost: Coef, - // pub ripemd160Cost: Coef, - // pub identityCost: Coef, - // pub modexpImplCost: Coef, - // pub bn128AddImplCost: Coef, - // pub bn128MulImplCost: Coef, - // pub bn128PairingImplCost: Coef, - // pub blake2FImplCost: Coef, - // pub lastPrecompileCost: Coef, + pub precompiled_function_cost: EvmPrecompiledFunctionCost, } pub fn measure_evm_deploy(gas_metric: GasMetric, verbose: bool) -> Coef { @@ -235,15 +240,13 @@ pub fn measure_evm_deploy(gas_metric: GasMetric, verbose: bool) -> Coef { } use_contract!(soltest, "../near-evm-runner/tests/build/SolTests.abi"); -use_contract!(subcontract, "../near-evm-runner/tests/build/SubContract.abi"); -use_contract!(create2factory, "../near-evm-runner/tests/build/Create2Factory.abi"); -use_contract!(selfdestruct, "../near-evm-runner/tests/build/SelfDestruct.abi"); +use_contract!(precompiled_function, "../near-evm-runner/tests/build/PrecompiledFunction.abi"); lazy_static_include_str!(TEST, "../near-evm-runner/tests/build/SolTests.bin"); -lazy_static_include_str!(SUBCONTRACT_TEST, "../near-evm-runner/tests/build/SubContract.bin"); -lazy_static_include_str!(FACTORY_TEST, "../near-evm-runner/tests/build/Create2Factory.bin"); -lazy_static_include_str!(DESTRUCT_TEST, "../near-evm-runner/tests/build/SelfDestruct.bin"); -lazy_static_include_str!(CONSTRUCTOR_TEST, "../near-evm-runner/tests/build/ConstructorRevert.bin"); +lazy_static_include_str!( + PRECOMPILED_TEST, + "../near-evm-runner/tests/build/PrecompiledFunction.bin" +); pub fn create_evm_context<'a>( external: &'a mut MockedExternal, @@ -273,13 +276,6 @@ pub fn measure_evm_funcall(gas_metric: GasMetric, verbose: bool) -> Coef { let mut context = create_evm_context(&mut fake_external, &config, &fees, "alice".to_string(), 100); let sol_test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); - // TODO: this deploy always fail with empty string error message - // let factory_test_addr = context.deploy_code(hex::decode(&FACTORY_TEST).unwrap()).unwrap(); - // let destruct_test_addr = context.deploy_code(hex::decode(&DESTRUCT_TEST).unwrap()).unwrap(); - // let constructor_test_addr = - // context.deploy_code(hex::decode(&CONSTRUCTOR_TEST).unwrap()).unwrap(); - let subcontract_test_addr = - context.deploy_code(hex::decode(&SUBCONTRACT_TEST).unwrap()).unwrap(); let measurements = vec![ measure_evm_function( @@ -287,21 +283,14 @@ pub fn measure_evm_funcall(gas_metric: GasMetric, verbose: bool) -> Coef { verbose, &mut context, encode_call_function_args(sol_test_addr, soltest::functions::deploy_new_guy::call(8).0), - ), - measure_evm_function( - gas_metric, - verbose, - &mut context, - encode_call_function_args( - subcontract_test_addr, - subcontract::functions::a_number::call().0, - ), + "deploy_new_guy(8)", ), measure_evm_function( gas_metric, verbose, &mut context, encode_call_function_args(sol_test_addr, soltest::functions::pay_new_guy::call(8).0), + "pay_new_guy(8)", ), measure_evm_function( gas_metric, @@ -311,7 +300,19 @@ pub fn measure_evm_funcall(gas_metric: GasMetric, verbose: bool) -> Coef { sol_test_addr, soltest::functions::return_some_funds::call().0, ), + "return_some_funds()", ), + { + // function not payable must has zero deposit + context.attached_deposit = 0; + measure_evm_function( + gas_metric, + verbose, + &mut context, + encode_call_function_args(sol_test_addr, soltest::functions::emit_it::call(8).0), + "emit_it(8)", + ) + }, ]; measurements_to_coef(measurements, true) @@ -322,6 +323,7 @@ pub fn measure_evm_function( verbose: bool, context: &mut EvmContext, args: Vec, + test_name: &str, ) -> EvmCost { let start = start_count(gas_metric); let mut evm_gas = 0; @@ -334,7 +336,97 @@ pub fn measure_evm_function( let _ = context.call_function(args.clone()).unwrap(); } let end = end_count(gas_metric, &start); - EvmCost { evm_gas, cost: Ratio::new(end, NUM_ITERATIONS) } + let cost = Ratio::new(end, NUM_ITERATIONS); + if verbose { + println!("Testing call {}: ({}, {})", test_name, evm_gas, cost); + } + EvmCost { evm_gas, cost } +} + +pub fn measure_evm_precompiled(gas_metric: GasMetric, verbose: bool) -> EvmPrecompiledFunctionCost { + let mut fake_external = MockedExternal::new(); + let config = VMConfig::default(); + let fees = RuntimeFeesConfig::default(); + + let mut context = + create_evm_context(&mut fake_external, &config, &fees, "alice".to_string(), 0); + let precompiled_function_addr = + context.deploy_code(hex::decode(&PRECOMPILED_TEST).unwrap()).unwrap(); + + let measurements = vec![ + measure_evm_function( + gas_metric, + verbose, + &mut context, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::noop::call().0, + ), + "noop()", + ), + measure_evm_function( + gas_metric, + verbose, + &mut context, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_ecrecover::call().0, + ), + "test_ecrecover()", + ), + measure_evm_function( + gas_metric, + verbose, + &mut context, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_sha256::call().0, + ), + "test_sha256()", + ), + measure_evm_function( + gas_metric, + verbose, + &mut context, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_ripemd160::call().0, + ), + "test_ripemd160()", + ), + measure_evm_function( + gas_metric, + verbose, + &mut context, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_identity::call().0, + ), + "test_identity()", + ), + measure_evm_function( + gas_metric, + verbose, + &mut context, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_mod_exp::call().0, + ), + "test_mod_exp()", + ), + ]; + + EvmPrecompiledFunctionCost { + ecRecoverCost: measurements[1].cost - measurements[0].cost, + sha256Cost: measurements[2].cost - measurements[0].cost, + ripemd160Cost: measurements[3].cost - measurements[0].cost, + identityCost: measurements[4].cost - measurements[0].cost, + modexpImplCost: measurements[5].cost - measurements[0].cost, + } +} + +pub fn near_cost_to_evm_gas(funcall_cost: Coef, cost: Ratio) -> u64 { + return u64::try_from((cost / funcall_cost.0).to_integer()).unwrap(); } /// Cost of all evm related @@ -342,6 +434,7 @@ pub fn cost_of_evm(gas_metric: GasMetric, verbose: bool) -> EvmCostCoef { let evm_cost_config = EvmCostCoef { deploy_cost: measure_evm_deploy(gas_metric, verbose), funcall_cost: measure_evm_funcall(gas_metric, verbose), + precompiled_function_cost: measure_evm_precompiled(gas_metric, verbose), }; evm_cost_config } @@ -381,7 +474,7 @@ pub fn cost_to_compile( .filter(|path| fs::metadata(path).is_ok()) .map(|path| { if verbose { - print!("Testing {}: ", path.display()); + print!("Testing deploy {}: ", path.display()); }; if let Some((size, cost)) = load_and_compile(path, gas_metric, vm_kind) { if verbose { From 8752e6c9e722581df336b5c87c0f349bd9bf3bcb Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Wed, 16 Sep 2020 18:18:59 -0700 Subject: [PATCH 18/61] calc and deduct near gas from number given by evm gas --- runtime/near-evm-runner/src/lib.rs | 34 ++++++++++++++++++ runtime/near-runtime-fees/src/lib.rs | 46 +++++++++++++----------- runtime/near-vm-logic/src/gas_counter.rs | 4 +++ 3 files changed, 64 insertions(+), 20 deletions(-) diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index fa251320b3b..9a8fcc738e0 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -36,6 +36,13 @@ pub struct EvmContext<'a> { fees_config: &'a RuntimeFeesConfig, } +// Different kind of evm operations that result in different gas calculation +pub enum EvmOpForGas { + Deploy, + Funcall, + Other, +} + enum KeyPrefix { Account = 0, Contract = 1, @@ -347,6 +354,23 @@ impl<'a> EvmContext<'a> { .ok_or(VMLogicError::EvmError(EvmError::IntegerOverflow))?; self.gas_counter.pay_action_accumulated(burn_gas, use_gas, ActionCosts::new_receipt) } + + fn pay_gas_from_evm_gas(&mut self, op: EvmOpForGas) -> Result<()> { + let fee_cfg = &self.fees_config.evm_config; + let evm_gas = self.evm_gas_counter.used_gas.as_u64(); + let gas = match op { + EvmOpForGas::Deploy => { + evm_gas * fee_cfg.deploy_cost_per_evm_gas + fee_cfg.bootstrap_cost + } + EvmOpForGas::Funcall => { + evm_gas * fee_cfg.funcall_cost_per_evm_gas + + fee_cfg.funcall_cost_base + + fee_cfg.bootstrap_cost + } + EvmOpForGas::Other => fee_cfg.bootstrap_cost, + }; + self.gas_counter.pay_evm_gas(gas) + } } pub fn run_evm( @@ -392,6 +416,16 @@ pub fn run_evm( } _ => Err(VMLogicError::EvmError(EvmError::MethodNotFound)), }; + let pay_gas_result = context.pay_gas_from_evm_gas(match method_name.as_str() { + "deploy_code" => EvmOpForGas::Deploy, + "call_function" => EvmOpForGas::Funcall, + _ => EvmOpForGas::Other, + }); + if pay_gas_result.is_err() { + // TODO: state should be revert, if run out of gas, or, evm gas attached should be calculated from near gas attached + // so run out of gas should be caught by evm + panic!(); + } match result { Ok(value) => { let outcome = VMOutcome { diff --git a/runtime/near-runtime-fees/src/lib.rs b/runtime/near-runtime-fees/src/lib.rs index 5dfa4f0e111..bf161581cd5 100644 --- a/runtime/near-runtime-fees/src/lib.rs +++ b/runtime/near-runtime-fees/src/lib.rs @@ -142,20 +142,19 @@ pub struct StorageUsageConfig { #[derive(Debug, Serialize, Deserialize, Clone, Hash, PartialEq, Eq)] pub struct EvmCostConfig { /// Base cost of instantiate an evm instance for any evm operation - pub bootstrap_cost: u64, - /// For every unit of gas used by evm in funcall, equivalent near gas cost - pub funcall_cost_per_evm_gas: u64, - // Base cost of instantiate an evm instance and deploy minimum contract - pub deploy_base_cost: u64, + pub bootstrap_cost: Gas, /// For every unit of gas used by evm in deploy evm contract, equivalent near gas cost - pub deploy_cost_per_evm_gas: u64, - + pub deploy_cost_per_evm_gas: Gas, + /// For bootstrapped evm, base cost to invoke a contract function + pub funcall_cost_base: Gas, + /// For every unit of gas used by evm in funcall, equivalent near gas cost + pub funcall_cost_per_evm_gas: Gas, /// Evm precompiled function costs - pub ecrecover_cost: u64, - pub sha256_cost: u64, - pub ripemd160_cost: u64, - pub identity_cost: u64, - pub modexp_cost: u64, + pub ecrecover_cost: Gas, + pub sha256_cost: Gas, + pub ripemd160_cost: Gas, + pub identity_cost: Gas, + pub modexp_cost: Gas, } impl Default for RuntimeFeesConfig { @@ -252,13 +251,18 @@ impl Default for RuntimeFeesConfig { burnt_gas_reward: Rational::new(3, 10), pessimistic_gas_price_inflation_ratio: Rational::new(103, 100), evm_config: EvmCostConfig { - bootstrap_cost: 0, - per_evm_gas_cost: 0, - ecrecover_cost: 0, - sha256_cost: 0, - ripemd160_cost: 0, - identity_cost: 0, - modexp_cost: 0, + // Got inside emu-cost docker, numbers very slightly in different runs: + // cd /host/nearcore/runtime/near-evm-runner/tests + // ../../runtime-params-estimator/emu-cost/counter_plugin/qemu-x86_64 -cpu Westmere-v1 -plugin file=../../runtime-params-estimator/emu-cost/counter_plugin/libcounter.so ../../../target/release/runtime-params-estimator --home /tmp/data --accounts-num 2000 --iters 1 --warmup-iters 1 --evm-only + bootstrap_cost: 31618278, + deploy_cost_per_evm_gas: 11374412500, + funcall_cost_base: 352935, + funcall_cost_per_evm_gas: 19008337500, + ecrecover_cost: 792636, + sha256_cost: 21337, + ripemd160_cost: 19810, + identity_cost: 58391, + modexp_cost: 31967, }, } } @@ -297,7 +301,9 @@ impl RuntimeFeesConfig { pessimistic_gas_price_inflation_ratio: Rational::from_integer(0), evm_config: EvmCostConfig { bootstrap_cost: 0, - per_evm_gas_cost: 0, + deploy_cost_per_evm_gas: 0, + funcall_cost_base: 0, + funcall_cost_per_evm_gas: 0, ecrecover_cost: 0, sha256_cost: 0, ripemd160_cost: 0, diff --git a/runtime/near-vm-logic/src/gas_counter.rs b/runtime/near-vm-logic/src/gas_counter.rs index 7a99702f271..9602eca9829 100644 --- a/runtime/near-vm-logic/src/gas_counter.rs +++ b/runtime/near-vm-logic/src/gas_counter.rs @@ -117,6 +117,10 @@ impl GasCounter { self.deduct_gas(value, value) } + pub fn pay_evm_gas(&mut self, value: u64) -> Result<()> { + self.deduct_gas(value, value) + } + /// A helper function to pay per byte gas pub fn pay_per_byte(&mut self, cost: ExtCosts, num_bytes: u64) -> Result<()> { let use_gas = num_bytes From 97f794762bdfb834cfddd87352be549569c990e5 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Thu, 17 Sep 2020 10:07:22 -0700 Subject: [PATCH 19/61] address illia comments --- runtime/near-evm-runner/tests/standard_ops.rs | 17 +---------------- runtime/near-evm-runner/tests/utils.rs | 1 + runtime/near-vm-errors/src/lib.rs | 1 - 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/runtime/near-evm-runner/tests/standard_ops.rs b/runtime/near-evm-runner/tests/standard_ops.rs index 2d81381e81f..de2e86a981a 100644 --- a/runtime/near-evm-runner/tests/standard_ops.rs +++ b/runtime/near-evm-runner/tests/standard_ops.rs @@ -15,7 +15,7 @@ use near_vm_errors::{EvmError, VMLogicError}; use near_vm_logic::mocks::mock_external::MockedExternal; use near_vm_logic::VMConfig; -use crate::utils::{accounts, create_context, setup, show_evm_gas_used}; +use crate::utils::{accounts, create_context, setup}; mod utils; @@ -79,10 +79,8 @@ fn test_deploy_with_nonce() { let address = near_account_id_to_evm_address(&accounts(1)); assert_eq!(context.get_nonce(address.0.to_vec()).unwrap(), U256::from(0)); let address1 = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); - show_evm_gas_used(&context); assert_eq!(context.get_nonce(address.0.to_vec()).unwrap(), U256::from(1)); let address2 = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); - show_evm_gas_used(&context); assert_eq!(context.get_nonce(address.0.to_vec()).unwrap(), U256::from(2)); assert_ne!(address1, address2); } @@ -94,7 +92,6 @@ fn test_failed_deploy_returns_error() { if let Err(VMLogicError::EvmError(EvmError::DeployFail(_))) = context.deploy_code(hex::decode(&CONSTRUCTOR_TEST).unwrap()) { - show_evm_gas_used(&context); } else { panic!("Should fail"); } @@ -105,19 +102,16 @@ fn test_internal_create() { let (mut fake_external, vm_config, fees_config) = setup(); let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 0); let test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); - show_evm_gas_used(&context); assert_eq!(context.get_nonce(test_addr.0.to_vec()).unwrap(), U256::from(0)); // This should increment the nonce of the deploying contract let (input, _) = soltest::functions::deploy_new_guy::call(8); let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); - show_evm_gas_used(&context); assert_eq!(context.get_nonce(test_addr.0.to_vec()).unwrap(), U256::from(1)); let sub_addr = address_from_arr(&raw[12..32]); let (new_input, _) = subcontract::functions::a_number::call(); let new_raw = context.call_function(encode_call_function_args(sub_addr, new_input)).unwrap(); - show_evm_gas_used(&context); let output = subcontract::functions::a_number::decode_output(&new_raw).unwrap(); assert_eq!(output, U256::from(8)); } @@ -128,12 +122,10 @@ fn test_precompiles() { let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 100); let test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); - show_evm_gas_used(&context); let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 0); let (input, _) = soltest::functions::precompile_test::call(); let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); - show_evm_gas_used(&context); assert_eq!(raw.len(), 0); } @@ -142,7 +134,6 @@ fn setup_and_deploy_test() -> (MockedExternal, Address, VMConfig, RuntimeFeesCon let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 100); let test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); - show_evm_gas_used(&context); assert_eq!(context.get_balance(test_addr.0.to_vec()).unwrap(), U256::from(100)); (fake_external, test_addr, vm_config, fees_config) } @@ -157,7 +148,6 @@ fn test_deploy_and_transfer() { let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 100); let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); - show_evm_gas_used(&context); assert!(context.logs.len() > 0); // The sub_addr should have been transferred 100 yoctoN. @@ -176,7 +166,6 @@ fn test_deploy_with_value() { let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 100); let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); - show_evm_gas_used(&context); // The sub_addr should have been transferred 100 tokens. let sub_addr = raw[12..32].to_vec(); @@ -192,7 +181,6 @@ fn test_contract_to_eoa_transfer() { let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 100); let raw = context.call_function(encode_call_function_args(test_addr, input)).unwrap(); - show_evm_gas_used(&context); let sender_addr = raw[12..32].to_vec(); assert_eq!(context.get_balance(test_addr.0.to_vec()).unwrap(), U256::from(150)); @@ -224,7 +212,6 @@ fn test_view_call() { input, )) .unwrap(); - show_evm_gas_used(&context); assert_eq!(context.get_nonce(test_addr.0.to_vec()).unwrap(), U256::from(0)); let sub_addr = raw[12..32].to_vec(); @@ -244,13 +231,11 @@ fn test_solidity_accurate_storage_on_selfdestruct() { // Deploy CREATE2 Factory let mut context = create_context(&mut fake_external, &vm_config, &fees_config, accounts(1), 0); let factory_addr = context.deploy_code(hex::decode(&FACTORY_TEST).unwrap()).unwrap(); - show_evm_gas_used(&context); // Deploy + SelfDestruct in one transaction let salt = H256([0u8; 32]); let destruct_code = hex::decode(&DESTRUCT_TEST).unwrap(); let input = create2factory::functions::test_double_deploy::call(salt, destruct_code.clone()).0; let raw = context.call_function(encode_call_function_args(factory_addr, input)).unwrap(); - show_evm_gas_used(&context); assert!(create2factory::functions::test_double_deploy::decode_output(&raw).unwrap()); } diff --git a/runtime/near-evm-runner/tests/utils.rs b/runtime/near-evm-runner/tests/utils.rs index c8ddcc5d19d..3bc9180c008 100644 --- a/runtime/near-evm-runner/tests/utils.rs +++ b/runtime/near-evm-runner/tests/utils.rs @@ -35,6 +35,7 @@ pub fn create_context<'a>( ) } +#[cfg(test)] pub fn show_evm_gas_used(context: &EvmContext) { println!("Accumulated EVM gas used: {}", &context.evm_gas_counter.used_gas); } diff --git a/runtime/near-vm-errors/src/lib.rs b/runtime/near-vm-errors/src/lib.rs index cd96cdd3fb2..4def95f3cff 100644 --- a/runtime/near-vm-errors/src/lib.rs +++ b/runtime/near-vm-errors/src/lib.rs @@ -5,7 +5,6 @@ use serde::export::fmt::Error; use serde::export::Formatter; use serde::{Deserialize, Serialize}; -use ethereum_types::U256; use near_rpc_error_macro::RpcError; #[derive(Debug, Clone, PartialEq, Eq, BorshDeserialize, BorshSerialize, Deserialize, Serialize)] From 14e55ef3f6cccd59a51619d4776cb073a16d6c4d Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Thu, 17 Sep 2020 12:32:11 -0700 Subject: [PATCH 20/61] thread in prepaid function cost in evm --- runtime/near-evm-runner/src/builtins.rs | 31 +++++++++++++-- runtime/near-evm-runner/src/interpreter.rs | 44 +++++++++++++++++++--- runtime/near-evm-runner/src/lib.rs | 3 ++ runtime/near-evm-runner/src/near_ext.rs | 15 +++++++- runtime/near-runtime-fees/src/lib.rs | 13 ++++--- 5 files changed, 91 insertions(+), 15 deletions(-) diff --git a/runtime/near-evm-runner/src/builtins.rs b/runtime/near-evm-runner/src/builtins.rs index 73ee6345b1a..ef3221eecb3 100644 --- a/runtime/near-evm-runner/src/builtins.rs +++ b/runtime/near-evm-runner/src/builtins.rs @@ -6,6 +6,7 @@ use std::{ use byteorder::{BigEndian, ByteOrder, LittleEndian, ReadBytesExt}; use ethereum_types::{Address, H256, U256}; +use near_runtime_fees::EvmCostConfig; use num_bigint::BigUint; use num_traits::{FromPrimitive, One, ToPrimitive, Zero}; use parity_bytes::BytesRef; @@ -45,14 +46,19 @@ pub fn precompile(id: u64) -> Result, String> { }) } -pub fn process_precompile(addr: &Address, input: &[u8], gas: &U256) -> MessageCallResult { +pub fn process_precompile( + addr: &Address, + input: &[u8], + gas: &U256, + evm_gas_config: &EvmCostConfig, +) -> MessageCallResult { let f = match precompile(addr.to_low_u64_be()) { Ok(f) => f, Err(_) => return MessageCallResult::Failed, }; let mut bytes = vec![]; let mut output = parity_bytes::BytesRef::Flexible(&mut bytes); - let cost = f.gas(input); + let cost = f.gas(input, evm_gas_config); if cost > *gas { return MessageCallResult::Failed; @@ -132,7 +138,7 @@ pub struct Blake2FImpl; pub trait Impl: Send + Sync { /// execute this built-in on the given input, writing to the given output. fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), Error>; - fn gas(&self, _input: &[u8]) -> U256 { + fn gas(&self, _input: &[u8], _evm_gas_config: &EvmCostConfig) -> U256 { 0.into() } } @@ -142,6 +148,9 @@ impl Impl for Identity { output.write(0, input); Ok(()) } + fn gas(&self, _input: &[u8], evm_gas_config: &EvmCostConfig) -> U256 { + evm_gas_config.identity_cost.into() + } } impl Impl for EcRecover { @@ -181,6 +190,10 @@ impl Impl for EcRecover { Ok(()) } + + fn gas(&self, _input: &[u8], evm_gas_config: &EvmCostConfig) -> U256 { + evm_gas_config.ecrecover_cost.into() + } } impl Impl for Sha256 { @@ -190,6 +203,10 @@ impl Impl for Sha256 { output.write(0, &*d); Ok(()) } + + fn gas(&self, _input: &[u8], evm_gas_config: &EvmCostConfig) -> U256 { + evm_gas_config.sha256_cost.into() + } } impl Impl for Ripemd160 { @@ -199,6 +216,10 @@ impl Impl for Ripemd160 { output.write(12, &hash); Ok(()) } + + fn gas(&self, _input: &[u8], evm_gas_config: &EvmCostConfig) -> U256 { + evm_gas_config.ripemd160_cost.into() + } } // calculate modexp: left-to-right binary exponentiation to keep multiplicands lower @@ -307,6 +328,10 @@ impl Impl for ModexpImpl { Ok(()) } + + fn gas(&self, _input: &[u8], evm_gas_config: &EvmCostConfig) -> U256 { + evm_gas_config.modexp_cost.into() + } } fn read_fr(reader: &mut io::Chain<&[u8], io::Repeat>) -> Result<::bn::Fr, Error> { diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index 615244444ac..f17692c9818 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -2,6 +2,7 @@ use std::sync::Arc; use ethereum_types::{Address, U256}; use evm::{CreateContractAddress, Factory}; +use near_runtime_fees::EvmCostConfig; use vm::{ ActionParams, ActionValue, CallType, ContractCreateResult, Ext, GasLeft, MessageCallResult, ParamsType, ReturnData, Schedule, @@ -24,6 +25,7 @@ pub fn deploy_code( recreate: bool, code: &[u8], gas: &U256, + evm_gas_config: &EvmCostConfig, ) -> Result { let mut nonce = U256::default(); if address_type == CreateContractAddress::FromSenderAndNonce { @@ -37,8 +39,17 @@ pub fn deploy_code( return Err(VMLogicError::EvmError(EvmError::DuplicateContract(hex::encode(address.0)))); } - let (result, state_updates) = - _create(state, origin, sender, value, call_stack_depth, &address, code, gas)?; + let (result, state_updates) = _create( + state, + origin, + sender, + value, + call_stack_depth, + &address, + code, + gas, + evm_gas_config, + )?; // Apply known gas amount changes (all reverts are NeedsReturn) // Apply NeedsReturn changes if apply_state @@ -69,6 +80,7 @@ pub fn _create( address: &Address, code: &[u8], gas: &U256, + evm_gas_config: &EvmCostConfig, ) -> Result<(Option, Option)> { let mut store = StateStore::default(); let mut sub_state = SubState::new(sender, &mut store, state); @@ -90,7 +102,14 @@ pub fn _create( sub_state.transfer_balance(sender, address, value)?; - let mut ext = NearExt::new(*address, *origin, &mut sub_state, call_stack_depth + 1, false); + let mut ext = NearExt::new( + *address, + *origin, + &mut sub_state, + call_stack_depth + 1, + false, + evm_gas_config, + ); ext.info.gas_limit = U256::from(gas); ext.schedule = Schedule::new_constantinople(); @@ -112,6 +131,7 @@ pub fn call( input: &[u8], should_commit: bool, gas: &U256, + evm_gas_config: &EvmCostConfig, ) -> Result { run_and_commit_if_success( state, @@ -126,6 +146,7 @@ pub fn call( false, should_commit, gas, + evm_gas_config, ) } @@ -138,6 +159,7 @@ pub fn delegate_call( delegee: &Address, input: &[u8], gas: &U256, + evm_gas_config: &EvmCostConfig, ) -> Result { run_and_commit_if_success( state, @@ -152,6 +174,7 @@ pub fn delegate_call( false, true, gas, + evm_gas_config, ) } @@ -163,6 +186,7 @@ pub fn static_call( contract_address: &Address, input: &[u8], gas: &U256, + evm_gas_config: &EvmCostConfig, ) -> Result { run_and_commit_if_success( state, @@ -177,6 +201,7 @@ pub fn static_call( true, false, gas, + evm_gas_config, ) } @@ -194,6 +219,7 @@ fn run_and_commit_if_success( is_static: bool, should_commit: bool, gas: &U256, + evm_gas_config: &EvmCostConfig, ) -> Result { // run the interpreter and let (result, state_updates) = run_against_state( @@ -208,6 +234,7 @@ fn run_and_commit_if_success( input, is_static, gas, + evm_gas_config, )?; // Apply known gas amount changes (all reverts are NeedsReturn) @@ -248,6 +275,7 @@ fn run_against_state( input: &[u8], is_static: bool, gas: &U256, + evm_gas_config: &EvmCostConfig, ) -> Result<(Option, Option)> { let code = state.code_at(code_address)?.unwrap_or_else(Vec::new); @@ -275,8 +303,14 @@ fn run_against_state( sub_state.transfer_balance(sender, state_address, val)?; } - let mut ext = - NearExt::new(*state_address, *origin, &mut sub_state, call_stack_depth + 1, is_static); + let mut ext = NearExt::new( + *state_address, + *origin, + &mut sub_state, + call_stack_depth + 1, + is_static, + evm_gas_config, + ); // Gas limit is evm block gas limit, should at least prepaid gas. ext.info.gas_limit = *gas; ext.schedule = Schedule::new_constantinople(); diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 9a8fcc738e0..e0c317dc90e 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -166,6 +166,7 @@ impl<'a> EvmContext<'a> { false, &bytecode, &self.evm_gas_counter.gas_left(), + &self.fees_config.evm_config, )?; match r { ContractCreateResult::Created(address, gas_left) => { @@ -200,6 +201,7 @@ impl<'a> EvmContext<'a> { &input, true, &self.evm_gas_counter.gas_left(), + &self.fees_config.evm_config, )?; match rd { MessageCallResult::Success(gas_left, data) => { @@ -233,6 +235,7 @@ impl<'a> EvmContext<'a> { &args.args, false, &self.evm_gas_counter.gas_left(), + &self.fees_config.evm_config, )?; match rd { MessageCallResult::Success(gas_left, data) => { diff --git a/runtime/near-evm-runner/src/near_ext.rs b/runtime/near-evm-runner/src/near_ext.rs index 2e54b14b774..5094b8ceea8 100644 --- a/runtime/near-evm-runner/src/near_ext.rs +++ b/runtime/near-evm-runner/src/near_ext.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use ethereum_types::{Address, H160, H256, U256}; use evm::ActionParams; use keccak_hash::keccak; +use near_runtime_fees::EvmCostConfig; use parity_bytes::Bytes; use vm::{ CallType, ContractCreateResult, CreateContractAddress, EnvInfo, Error as VmError, @@ -25,6 +26,7 @@ pub struct NearExt<'a> { pub sub_state: &'a mut SubState<'a>, pub static_flag: bool, pub depth: usize, + pub evm_gas_config: &'a EvmCostConfig, } impl std::fmt::Debug for NearExt<'_> { @@ -46,6 +48,7 @@ impl<'a> NearExt<'a> { sub_state: &'a mut SubState<'a>, depth: usize, static_flag: bool, + evm_gas_config: &'a EvmCostConfig, ) -> Self { Self { info: Default::default(), @@ -56,6 +59,7 @@ impl<'a> NearExt<'a> { sub_state, static_flag, depth, + evm_gas_config, } } } @@ -143,6 +147,7 @@ impl<'a> vm::Ext for NearExt<'a> { true, &code.to_vec(), gas, + &self.evm_gas_config, ) .map_err(|_| TrapKind::Call(ActionParams::default())) } @@ -169,7 +174,12 @@ impl<'a> vm::Ext for NearExt<'a> { // hijack builtins if crate::builtins::is_precompile(receive_address) { - return Ok(crate::builtins::process_precompile(receive_address, data, gas)); + return Ok(crate::builtins::process_precompile( + receive_address, + data, + gas, + &self.evm_gas_config, + )); } let result = match call_type { @@ -187,6 +197,7 @@ impl<'a> vm::Ext for NearExt<'a> { &data.to_vec(), true, // should_commit gas, + &self.evm_gas_config, ), CallType::StaticCall => interpreter::static_call( self.sub_state, @@ -196,6 +207,7 @@ impl<'a> vm::Ext for NearExt<'a> { receive_address, &data.to_vec(), gas, + &self.evm_gas_config, ), CallType::CallCode => { // Call another contract using storage of the current contract. No longer used. @@ -210,6 +222,7 @@ impl<'a> vm::Ext for NearExt<'a> { code_address, &data.to_vec(), gas, + &self.evm_gas_config, ), }; result.map_err(|_| TrapKind::Call(ActionParams::default())) diff --git a/runtime/near-runtime-fees/src/lib.rs b/runtime/near-runtime-fees/src/lib.rs index bf161581cd5..f120989fb52 100644 --- a/runtime/near-runtime-fees/src/lib.rs +++ b/runtime/near-runtime-fees/src/lib.rs @@ -7,6 +7,7 @@ use num_rational::Rational; use serde::{Deserialize, Serialize}; pub type Gas = u64; +pub type EvmGas = u64; /// Costs associated with an object that can only be sent over the network (and executed /// by the receiver). @@ -149,12 +150,12 @@ pub struct EvmCostConfig { pub funcall_cost_base: Gas, /// For every unit of gas used by evm in funcall, equivalent near gas cost pub funcall_cost_per_evm_gas: Gas, - /// Evm precompiled function costs - pub ecrecover_cost: Gas, - pub sha256_cost: Gas, - pub ripemd160_cost: Gas, - pub identity_cost: Gas, - pub modexp_cost: Gas, + /// Evm precompiled function costs, note cost is in evm gas unit. + pub ecrecover_cost: EvmGas, + pub sha256_cost: EvmGas, + pub ripemd160_cost: EvmGas, + pub identity_cost: EvmGas, + pub modexp_cost: EvmGas, } impl Default for RuntimeFeesConfig { From fdb49b98a1a162403658c4c2d9f1a79b83d7b2fd Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Thu, 17 Sep 2020 16:19:00 -0700 Subject: [PATCH 21/61] fix random fee --- .../tests/runtime_group_tools/random_config.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/runtime/runtime/tests/runtime_group_tools/random_config.rs b/runtime/runtime/tests/runtime_group_tools/random_config.rs index ab78dd27438..4a4f71b0f56 100644 --- a/runtime/runtime/tests/runtime_group_tools/random_config.rs +++ b/runtime/runtime/tests/runtime_group_tools/random_config.rs @@ -1,5 +1,5 @@ use near_runtime_fees::{ - AccessKeyCreationConfig, ActionCreationConfig, DataReceiptCreationConfig, Fee, + AccessKeyCreationConfig, ActionCreationConfig, DataReceiptCreationConfig, EvmCostConfig, Fee, RuntimeFeesConfig, StorageUsageConfig, }; use node_runtime::config::RuntimeConfig; @@ -46,6 +46,17 @@ pub fn random_config() -> RuntimeConfig { (101 + rng.next_u32() % 10).try_into().unwrap(), 100, ), + evm_config: EvmCostConfig { + bootstrap_cost: rng.next_u64() % 1000, + deploy_cost_per_evm_gas: rng.next_u64() % 1000, + funcall_cost_base: rng.next_u64() % 1000, + funcall_cost_per_evm_gas: rng.next_u64() % 1000, + ecrecover_cost: rng.next_u64() % 1000, + sha256_cost: rng.next_u64() % 1000, + ripemd160_cost: rng.next_u64() % 1000, + identity_cost: rng.next_u64() % 1000, + modexp_cost: rng.next_u64() % 1000, + }, }, ..Default::default() } From c8e8449c0e475dcc3eb0a34f3b45245ad022d0c9 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Thu, 17 Sep 2020 17:09:44 -0700 Subject: [PATCH 22/61] convert prepaid near gas to evm gas so evm gas convert to near wont overflow --- runtime/near-evm-runner/src/lib.rs | 73 +++++++++++++++++++++----- runtime/near-evm-runner/tests/utils.rs | 1 + 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index e0c317dc90e..36dff17089d 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -6,7 +6,7 @@ use ethereum_types::{Address, H160, U256}; use evm::CreateContractAddress; use vm::{ContractCreateResult, MessageCallResult}; -use near_runtime_fees::RuntimeFeesConfig; +use near_runtime_fees::{EvmCostConfig, RuntimeFeesConfig}; use near_vm_errors::{EvmError, FunctionCallError, VMError}; use near_vm_logic::gas_counter::GasCounter; use near_vm_logic::types::{AccountId, Balance, Gas, ReturnData, StorageUsage}; @@ -128,6 +128,7 @@ impl<'a> EvmContext<'a> { storage_usage: StorageUsage, prepaid_gas: Gas, is_view: bool, + evm_gas: U256, ) -> Self { let max_gas_burnt = if is_view { config.limit_config.max_gas_burnt_view @@ -148,7 +149,7 @@ impl<'a> EvmContext<'a> { is_view, None, ), - evm_gas_counter: EvmGasCounter::new(0.into(), PREPAID_EVM_GAS.into()), + evm_gas_counter: EvmGasCounter::new(0.into(), evm_gas), fees_config, } } @@ -376,6 +377,41 @@ impl<'a> EvmContext<'a> { } } +fn max_evm_gas_from_near_gas( + near_gas: Gas, + evm_gas_config: &EvmCostConfig, + method_name: &str, +) -> Option { + match method_name { + "deploy_code" => { + if near_gas < evm_gas_config.bootstrap_cost { + return None; + } + Some( + ((near_gas - evm_gas_config.bootstrap_cost) + / evm_gas_config.deploy_cost_per_evm_gas) + .into(), + ) + } + "call_function" => { + if near_gas < evm_gas_config.bootstrap_cost + evm_gas_config.funcall_cost_base { + return None; + } + Some( + ((near_gas - evm_gas_config.bootstrap_cost - evm_gas_config.funcall_cost_base) + / evm_gas_config.funcall_cost_per_evm_gas) + .into(), + ) + } + _ => { + if near_gas < evm_gas_config.bootstrap_cost { + return None; + } + Some(evm_gas_config.bootstrap_cost.into()) + } + } +} + pub fn run_evm( ext: &mut dyn External, config: &VMConfig, @@ -389,6 +425,18 @@ pub fn run_evm( prepaid_gas: Gas, is_view: bool, ) -> (Option, Option, U256) { + let evm_gas_result = + max_evm_gas_from_near_gas(prepaid_gas, &fees_config.evm_config, &method_name); + if evm_gas_result.is_none() { + return ( + None, + Some(VMError::FunctionCallError(FunctionCallError::EvmError(EvmError::Revert( + "Not enough to run EVM".to_string(), + )))), + 0.into(), + ); + } + let evm_gas = evm_gas_result.unwrap(); let mut context = EvmContext::new( ext, config, @@ -401,6 +449,7 @@ pub fn run_evm( storage_usage, prepaid_gas, is_view, + evm_gas, ); let result = match method_name.as_str() { // Change the state methods. @@ -419,16 +468,16 @@ pub fn run_evm( } _ => Err(VMLogicError::EvmError(EvmError::MethodNotFound)), }; - let pay_gas_result = context.pay_gas_from_evm_gas(match method_name.as_str() { - "deploy_code" => EvmOpForGas::Deploy, - "call_function" => EvmOpForGas::Funcall, - _ => EvmOpForGas::Other, - }); - if pay_gas_result.is_err() { - // TODO: state should be revert, if run out of gas, or, evm gas attached should be calculated from near gas attached - // so run out of gas should be caught by evm - panic!(); - } + context + .pay_gas_from_evm_gas(match method_name.as_str() { + "deploy_code" => EvmOpForGas::Deploy, + "call_function" => EvmOpForGas::Funcall, + _ => EvmOpForGas::Other, + }) + // It's not possible deduct near gas underflow, because even use full evm gas it's less than prepaid near gas + // If full evm gas isn't enough for evm operation, evm will revert result and all near gas is used to pay for evm gas + .unwrap(); + match result { Ok(value) => { let outcome = VMOutcome { diff --git a/runtime/near-evm-runner/tests/utils.rs b/runtime/near-evm-runner/tests/utils.rs index 3bc9180c008..d6148b09b7d 100644 --- a/runtime/near-evm-runner/tests/utils.rs +++ b/runtime/near-evm-runner/tests/utils.rs @@ -32,6 +32,7 @@ pub fn create_context<'a>( 0, 10u64.pow(14), false, + 1_000_000_000.into(), ) } From c03b077205eb69974a67510d6bc4b427a576a064 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 18 Sep 2020 10:32:51 -0700 Subject: [PATCH 23/61] made mistake of reverse base cost and per_evm_gas cost, correct it --- runtime/near-runtime-fees/src/lib.rs | 8 ++++---- runtime/runtime-params-estimator/src/cases.rs | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/runtime/near-runtime-fees/src/lib.rs b/runtime/near-runtime-fees/src/lib.rs index f120989fb52..06ed31969bf 100644 --- a/runtime/near-runtime-fees/src/lib.rs +++ b/runtime/near-runtime-fees/src/lib.rs @@ -255,10 +255,10 @@ impl Default for RuntimeFeesConfig { // Got inside emu-cost docker, numbers very slightly in different runs: // cd /host/nearcore/runtime/near-evm-runner/tests // ../../runtime-params-estimator/emu-cost/counter_plugin/qemu-x86_64 -cpu Westmere-v1 -plugin file=../../runtime-params-estimator/emu-cost/counter_plugin/libcounter.so ../../../target/release/runtime-params-estimator --home /tmp/data --accounts-num 2000 --iters 1 --warmup-iters 1 --evm-only - bootstrap_cost: 31618278, - deploy_cost_per_evm_gas: 11374412500, - funcall_cost_base: 352935, - funcall_cost_per_evm_gas: 19008337500, + bootstrap_cost: 11374412500, + deploy_cost_per_evm_gas: 31618278, + funcall_cost_base: 19008337500, + funcall_cost_per_evm_gas: 352935, ecrecover_cost: 792636, sha256_cost: 21337, ripemd160_cost: 19810, diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index e5e66d2e1e5..0ab38dd973e 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -160,14 +160,14 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon } else if only_evm { let cost = cost_of_evm(config.metric, true); println!( - "EVM base deploy cost: {}, deploy cost per EVM gas: {}", - ratio_to_gas(config.metric, cost.deploy_cost.0), - ratio_to_gas(config.metric, cost.deploy_cost.1) + "EVM base deploy (and init evm instance) cost: {}, deploy cost per EVM gas: {}", + ratio_to_gas(config.metric, cost.deploy_cost.1), + ratio_to_gas(config.metric, cost.deploy_cost.0) ); println!( "EVM function call cost: {}, function call cost per EVM gas: {}", - ratio_to_gas(config.metric, cost.funcall_cost.0), - ratio_to_gas(config.metric, cost.funcall_cost.1) + ratio_to_gas(config.metric, cost.funcall_cost.1), + ratio_to_gas(config.metric, cost.funcall_cost.0) ); println!("EVM precompiled function evm gas:"); println!( From 05df01a8be5409e8935a95737353f4ce9df2024d Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 22 Sep 2020 23:34:30 -0700 Subject: [PATCH 24/61] wip measure evm include block cost, stuck in get account code hash same to EVM_CODE_HASH --- runtime/near-evm-runner/src/lib.rs | 33 ++-- runtime/near-vm-logic/src/gas_counter.rs | 25 ++- runtime/runtime-params-estimator/src/cases.rs | 5 +- .../src/vm_estimator.rs | 163 ++++++++++++------ runtime/runtime/src/actions.rs | 8 +- 5 files changed, 165 insertions(+), 69 deletions(-) diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 36dff17089d..fe80e550dcb 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -362,6 +362,7 @@ impl<'a> EvmContext<'a> { fn pay_gas_from_evm_gas(&mut self, op: EvmOpForGas) -> Result<()> { let fee_cfg = &self.fees_config.evm_config; let evm_gas = self.evm_gas_counter.used_gas.as_u64(); + self.gas_counter.inc_evm_gas_counter(evm_gas); let gas = match op { EvmOpForGas::Deploy => { evm_gas * fee_cfg.deploy_cost_per_evm_gas + fee_cfg.bootstrap_cost @@ -424,7 +425,7 @@ pub fn run_evm( args: Vec, prepaid_gas: Gas, is_view: bool, -) -> (Option, Option, U256) { +) -> (Option, Option) { let evm_gas_result = max_evm_gas_from_near_gas(prepaid_gas, &fees_config.evm_config, &method_name); if evm_gas_result.is_none() { @@ -433,7 +434,6 @@ pub fn run_evm( Some(VMError::FunctionCallError(FunctionCallError::EvmError(EvmError::Revert( "Not enough to run EVM".to_string(), )))), - 0.into(), ); } let evm_gas = evm_gas_result.unwrap(); @@ -488,18 +488,12 @@ pub fn run_evm( used_gas: context.gas_counter.used_gas(), logs: context.logs, }; - (Some(outcome), None, context.evm_gas_counter.used_gas) + (Some(outcome), None) } - Err(VMLogicError::EvmError(err)) => ( - None, - Some(VMError::FunctionCallError(FunctionCallError::EvmError(err))), - context.evm_gas_counter.used_gas, - ), - Err(_) => ( - None, - Some(VMError::FunctionCallError(FunctionCallError::WasmUnknownError)), - context.evm_gas_counter.used_gas, - ), + Err(VMLogicError::EvmError(err)) => { + (None, Some(VMError::FunctionCallError(FunctionCallError::EvmError(err)))) + } + Err(_) => (None, Some(VMError::FunctionCallError(FunctionCallError::WasmUnknownError))), } } @@ -524,7 +518,18 @@ mod tests { fees_config: &'a RuntimeFeesConfig, account_id: &str, ) -> EvmContext<'a> { - EvmContext::new(external, vm_config, fees_config, 0, account_id.to_string(), 0, 0, 0, false) + EvmContext::new( + external, + vm_config, + fees_config, + 0, + account_id.to_string(), + 0, + 0, + 0, + false, + 1_000_000_000.into(), + ) } #[test] diff --git a/runtime/near-vm-logic/src/gas_counter.rs b/runtime/near-vm-logic/src/gas_counter.rs index 9602eca9829..5a3edd6a495 100644 --- a/runtime/near-vm-logic/src/gas_counter.rs +++ b/runtime/near-vm-logic/src/gas_counter.rs @@ -1,12 +1,23 @@ use crate::config::{ActionCosts, ExtCosts, ExtCostsConfig}; use crate::types::{Gas, ProfileData}; use crate::{HostError, VMLogicError}; -use near_runtime_fees::Fee; +use near_runtime_fees::{EvmGas, Fee}; #[cfg(feature = "costs_counting")] thread_local! { pub static EXT_COSTS_COUNTER: std::cell::RefCell> = Default::default(); + + pub static EVM_GAS_COUNTER: std::cell::RefCell = Default::default(); +} + +pub fn reset_evm_gas_counter() -> u64 { + let mut ret = 0; + EVM_GAS_COUNTER.with(|f| { + ret = *f.borrow(); + *f.borrow_mut() = 0; + }); + ret } type Result = ::std::result::Result; @@ -73,6 +84,18 @@ impl GasCounter { } } + #[cfg(feature = "costs_counting")] + #[inline] + pub fn inc_evm_gas_counter(&mut self, value: EvmGas) { + EVM_GAS_COUNTER.with(|f| { + *f.borrow_mut() += value; + }) + } + + #[cfg(not(feature = "costs_counting"))] + #[inline] + pub fn inc_evm_gas_counter(&mut self, _value: EvmGas) {} + #[cfg(feature = "costs_counting")] #[inline] fn inc_ext_costs_counter(&mut self, cost: ExtCosts, value: u64) { diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index 0ab38dd973e..7ec04fb2b82 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -143,6 +143,8 @@ pub enum Metric { data_receipt_10b_1000, data_receipt_100kib_1000, cpu_ram_soak_test, + + deploy_evm_contract, } pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeConfig { @@ -158,7 +160,8 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon ); process::exit(0); } else if only_evm { - let cost = cost_of_evm(config.metric, true); + config.block_sizes = vec![100]; + let cost = cost_of_evm(&config, true); println!( "EVM base deploy (and init evm instance) cost: {}, deploy cost per EVM gas: {}", ratio_to_gas(config.metric, cost.deploy_cost.1), diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index db3c00b9222..3d2dc7e411c 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -1,20 +1,38 @@ +use crate::cases::Metric; +use crate::stats::Measurements; +use crate::testbed::RuntimeTestbed; use crate::testbed_runners::end_count; +use crate::testbed_runners::get_account_id; use crate::testbed_runners::start_count; +use crate::testbed_runners::Config; use crate::testbed_runners::GasMetric; use ethabi_contract::use_contract; use glob::glob; use lazy_static_include::lazy_static_include_str; +use near_crypto::{InMemorySigner, KeyType, PublicKey}; use near_evm_runner::utils::encode_call_function_args; use near_evm_runner::{run_evm, EvmContext}; +use near_primitives::account::{AccessKey, AccessKeyPermission, FunctionCallPermission}; +use near_primitives::hash::CryptoHash; +use near_primitives::transaction::{ + Action, AddKeyAction, CreateAccountAction, DeleteAccountAction, DeleteKeyAction, + DeployContractAction, FunctionCallAction, SignedTransaction, StakeAction, TransferAction, +}; +use near_primitives::utils::EVM_CODE_HASH; use near_primitives::version::PROTOCOL_VERSION; use near_runtime_fees::RuntimeFeesConfig; +use near_vm_logic::gas_counter::reset_evm_gas_counter; use near_vm_logic::mocks::mock_external::MockedExternal; use near_vm_logic::{VMConfig, VMContext, VMKind, VMOutcome}; use near_vm_runner::{compile_module, prepare, VMError}; use num_rational::Ratio; +use rand::seq::SliceRandom; +use rand::{Rng, SeedableRng}; use std::collections::hash_map::DefaultHasher; +use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; use std::fs; +use std::sync::Mutex; use std::{ hash::{Hash, Hasher}, path::PathBuf, @@ -141,38 +159,82 @@ pub struct EvmCost { pub cost: Ratio, } -fn deploy_evm_contract(code: &[u8], gas_metric: GasMetric) -> Option { - let mut fake_external = MockedExternal::new(); - let config = VMConfig::default(); - let fees = RuntimeFeesConfig::default(); - - let start = start_count(gas_metric); - let mut evm_gas = 0; - for _ in 0..NUM_ITERATIONS { - let (_, _, gas_used) = run_evm( - &mut fake_external, - &config, - &fees, - &"alice".to_string(), - 1000u128, - 0u128, - 0u64, - "deploy_code".to_string(), - hex::decode(&code).unwrap(), - 1_000_000_000u64, +fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { + let path = PathBuf::from(config.state_dump_path.as_str()); + println!("{:?}. Preparing testbed. Loading state.", config.metric); + let testbed = Mutex::new(RuntimeTestbed::from_state_dump(&path)); + let allow_failures = false; + let mut nonces: HashMap = HashMap::new(); + let mut accounts_deployed = HashSet::new(); + + let mut f = || { + let account_idx = loop { + let x = rand::thread_rng().gen::() % config.active_accounts; + if accounts_deployed.contains(&x) { + continue; + } + break x; + }; + accounts_deployed.insert(account_idx); + let account_id = get_account_id(account_idx); + let signer = InMemorySigner::from_seed(&account_id, KeyType::ED25519, &account_id); + let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); + let mut buf = [0; 32]; + buf[0] = 1; + + testbed.lock().unwrap().process_block( + &vec![SignedTransaction::from_actions( + nonce as u64, + account_id.clone(), + account_id.clone(), + &signer, + vec![Action::DeployContract(DeployContractAction { code: buf.into() })], + CryptoHash::default(), + )], false, ); - // All iterations use same amount of (evm) gas, it's safe to use any of them as gas_used. - // But we loop because we want avg of number of (near) gas_metric - evm_gas = gas_used.as_u64(); + + let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); + SignedTransaction::from_actions( + nonce as u64, + account_id.clone(), + account_id, + &signer, + vec![Action::FunctionCall(FunctionCallAction { + method_name: "deploy_code".to_string(), + args: code.into(), + gas: 10u64.pow(18), + deposit: 0, + })], + CryptoHash::default(), + ) + }; + + let mut evm_gas = 0; + let mut total_cost = 0; + for block_size in config.block_sizes.clone() { + // [100] + for _ in 0..config.iter_per_block { + // 0..10 + let block: Vec<_> = (0..block_size).map(|_| f()).collect(); + let mut testbed = testbed.lock().unwrap(); + let start = start_count(config.metric); + testbed.process_block(&block, allow_failures); + let cost = end_count(config.metric, &start); + total_cost += cost; + evm_gas = reset_evm_gas_counter(); + } } - let end = end_count(gas_metric, &start); - Some(EvmCost { evm_gas, cost: Ratio::new(end, NUM_ITERATIONS) }) + + Some(EvmCost { + evm_gas, + cost: Ratio::new(total_cost, (config.iter_per_block * config.block_sizes.len()) as u64), + }) } -fn load_and_deploy_evm_contract(path: &PathBuf, gas_metric: GasMetric) -> Option { +fn load_and_deploy_evm_contract(path: &PathBuf, config: &Config) -> Option { match fs::read(path) { - Ok(code) => deploy_evm_contract(&code, gas_metric), + Ok(code) => deploy_evm_contract(&code, config), _ => None, } } @@ -203,7 +265,7 @@ pub struct EvmCostCoef { pub precompiled_function_cost: EvmPrecompiledFunctionCost, } -pub fn measure_evm_deploy(gas_metric: GasMetric, verbose: bool) -> Coef { +pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef { let globbed_files = glob("./**/*.bin").expect("Failed to read glob pattern for bin files"); let paths = globbed_files .filter_map(|x| match x { @@ -220,8 +282,7 @@ pub fn measure_evm_deploy(gas_metric: GasMetric, verbose: bool) -> Coef { print!("Testing {}: ", path.display()); }; // Evm counted gas already count on size of the contract, therefore we look for cost = m*evm_gas + b. - if let Some(EvmCost { evm_gas, cost }) = load_and_deploy_evm_contract(path, gas_metric) - { + if let Some(EvmCost { evm_gas, cost }) = load_and_deploy_evm_contract(path, config) { if verbose { println!("({}, {})", evm_gas, cost); }; @@ -265,35 +326,36 @@ pub fn create_evm_context<'a>( 0, 10u64.pow(14), false, + 100_000_000.into(), ) } -pub fn measure_evm_funcall(gas_metric: GasMetric, verbose: bool) -> Coef { +pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { let mut fake_external = MockedExternal::new(); - let config = VMConfig::default(); + let vm_config = VMConfig::default(); let fees = RuntimeFeesConfig::default(); let mut context = - create_evm_context(&mut fake_external, &config, &fees, "alice".to_string(), 100); + create_evm_context(&mut fake_external, &vm_config, &fees, "alice".to_string(), 100); let sol_test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); let measurements = vec![ measure_evm_function( - gas_metric, + config, verbose, &mut context, encode_call_function_args(sol_test_addr, soltest::functions::deploy_new_guy::call(8).0), "deploy_new_guy(8)", ), measure_evm_function( - gas_metric, + config, verbose, &mut context, encode_call_function_args(sol_test_addr, soltest::functions::pay_new_guy::call(8).0), "pay_new_guy(8)", ), measure_evm_function( - gas_metric, + config, verbose, &mut context, encode_call_function_args( @@ -306,7 +368,7 @@ pub fn measure_evm_funcall(gas_metric: GasMetric, verbose: bool) -> Coef { // function not payable must has zero deposit context.attached_deposit = 0; measure_evm_function( - gas_metric, + config, verbose, &mut context, encode_call_function_args(sol_test_addr, soltest::functions::emit_it::call(8).0), @@ -319,12 +381,13 @@ pub fn measure_evm_funcall(gas_metric: GasMetric, verbose: bool) -> Coef { } pub fn measure_evm_function( - gas_metric: GasMetric, + config: &Config, verbose: bool, context: &mut EvmContext, args: Vec, test_name: &str, ) -> EvmCost { + let gas_metric = config.metric; let start = start_count(gas_metric); let mut evm_gas = 0; for i in 0..NUM_ITERATIONS { @@ -343,19 +406,19 @@ pub fn measure_evm_function( EvmCost { evm_gas, cost } } -pub fn measure_evm_precompiled(gas_metric: GasMetric, verbose: bool) -> EvmPrecompiledFunctionCost { +pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiledFunctionCost { let mut fake_external = MockedExternal::new(); - let config = VMConfig::default(); + let vm_config = VMConfig::default(); let fees = RuntimeFeesConfig::default(); let mut context = - create_evm_context(&mut fake_external, &config, &fees, "alice".to_string(), 0); + create_evm_context(&mut fake_external, &vm_config, &fees, "alice".to_string(), 0); let precompiled_function_addr = context.deploy_code(hex::decode(&PRECOMPILED_TEST).unwrap()).unwrap(); let measurements = vec![ measure_evm_function( - gas_metric, + config, verbose, &mut context, encode_call_function_args( @@ -365,7 +428,7 @@ pub fn measure_evm_precompiled(gas_metric: GasMetric, verbose: bool) -> EvmPreco "noop()", ), measure_evm_function( - gas_metric, + config, verbose, &mut context, encode_call_function_args( @@ -375,7 +438,7 @@ pub fn measure_evm_precompiled(gas_metric: GasMetric, verbose: bool) -> EvmPreco "test_ecrecover()", ), measure_evm_function( - gas_metric, + config, verbose, &mut context, encode_call_function_args( @@ -385,7 +448,7 @@ pub fn measure_evm_precompiled(gas_metric: GasMetric, verbose: bool) -> EvmPreco "test_sha256()", ), measure_evm_function( - gas_metric, + config, verbose, &mut context, encode_call_function_args( @@ -395,7 +458,7 @@ pub fn measure_evm_precompiled(gas_metric: GasMetric, verbose: bool) -> EvmPreco "test_ripemd160()", ), measure_evm_function( - gas_metric, + config, verbose, &mut context, encode_call_function_args( @@ -405,7 +468,7 @@ pub fn measure_evm_precompiled(gas_metric: GasMetric, verbose: bool) -> EvmPreco "test_identity()", ), measure_evm_function( - gas_metric, + config, verbose, &mut context, encode_call_function_args( @@ -430,11 +493,11 @@ pub fn near_cost_to_evm_gas(funcall_cost: Coef, cost: Ratio) -> u64 { } /// Cost of all evm related -pub fn cost_of_evm(gas_metric: GasMetric, verbose: bool) -> EvmCostCoef { +pub fn cost_of_evm(config: &Config, verbose: bool) -> EvmCostCoef { let evm_cost_config = EvmCostCoef { - deploy_cost: measure_evm_deploy(gas_metric, verbose), - funcall_cost: measure_evm_funcall(gas_metric, verbose), - precompiled_function_cost: measure_evm_precompiled(gas_metric, verbose), + deploy_cost: measure_evm_deploy(config, verbose), + funcall_cost: measure_evm_funcall(config, verbose), + precompiled_function_cost: measure_evm_precompiled(config, verbose), }; evm_cost_config } diff --git a/runtime/runtime/src/actions.rs b/runtime/runtime/src/actions.rs index d727caecb53..5672e8821cb 100644 --- a/runtime/runtime/src/actions.rs +++ b/runtime/runtime/src/actions.rs @@ -50,8 +50,10 @@ pub(crate) fn execute_function_call( is_last_action: bool, is_view: bool, ) -> (Option, Option) { + println!("account.code_hash {:?} EVM_CODE_HASH {:?}", account.code_hash, *EVM_CODE_HASH); if account.code_hash == *EVM_CODE_HASH { - let (outcome, error, _) = near_evm_runner::run_evm( + println!("evm!!!!"); + near_evm_runner::run_evm( runtime_ext, &config.wasm_config, &config.transaction_costs, @@ -63,9 +65,9 @@ pub(crate) fn execute_function_call( function_call.args.clone(), function_call.gas, is_view, - ); - (outcome, error) + ) } else { + println!("wasm!!!!"); let code = match runtime_ext.get_code(account.code_hash) { Ok(Some(code)) => code, Ok(None) => { From 521f87aa113a8a7245162cbb6de9b96971eef620 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Wed, 23 Sep 2020 22:48:07 -0700 Subject: [PATCH 25/61] deploy contract total cost calc works --- core/primitives/src/utils.rs | 3 ++- runtime/near-evm-runner/src/interpreter.rs | 14 +++++++++++++- runtime/near-evm-runner/src/lib.rs | 3 +++ .../runtime-params-estimator/src/vm_estimator.rs | 6 ++++-- runtime/runtime/src/actions.rs | 6 +++--- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/core/primitives/src/utils.rs b/core/primitives/src/utils.rs index 1fe621dfea5..c3cda9ae11d 100644 --- a/core/primitives/src/utils.rs +++ b/core/primitives/src/utils.rs @@ -28,7 +28,8 @@ lazy_static! { fn code_hash(num: u8) -> CryptoHash { let mut buf = [0; 32]; buf[0] = num; - return CryptoHash(Digest(buf)); + return hash(&buf); + // return CryptoHash(Digest(buf)); } pub fn get_block_shard_id(block_hash: &CryptoHash, shard_id: ShardId) -> Vec { diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index f17692c9818..42ff784cbb7 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -85,6 +85,10 @@ pub fn _create( let mut store = StateStore::default(); let mut sub_state = SubState::new(sender, &mut store, state); + // println!("========= code: {}", code.len()); + // println!("========= gas: {}", gas); + // println!("========= {:?}", evm_gas_config); + let params = ActionParams { code_address: *address, address: *address, @@ -99,6 +103,7 @@ pub fn _create( call_type: CallType::None, params_type: vm::ParamsType::Embedded, }; + // println!("========= {:?}", params); sub_state.transfer_balance(sender, address, value)?; @@ -117,7 +122,14 @@ pub fn _create( // Run the code let result = instance.exec(&mut ext); - Ok((result.ok().unwrap().ok(), Some(store))) + match result.ok().unwrap() { + Ok(a) => Ok((Some(a), Some(store))), + Err(e) => { + println!("============= {:?}", e); + Ok((None, Some(store))) + } + } + // Ok((result.ok().unwrap().ok(), Some(store))) } #[allow(clippy::too_many_arguments)] diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index fe80e550dcb..15f12f7963a 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -362,6 +362,7 @@ impl<'a> EvmContext<'a> { fn pay_gas_from_evm_gas(&mut self, op: EvmOpForGas) -> Result<()> { let fee_cfg = &self.fees_config.evm_config; let evm_gas = self.evm_gas_counter.used_gas.as_u64(); + println!("============== evm_gas {}", evm_gas); self.gas_counter.inc_evm_gas_counter(evm_gas); let gas = match op { EvmOpForGas::Deploy => { @@ -428,6 +429,8 @@ pub fn run_evm( ) -> (Option, Option) { let evm_gas_result = max_evm_gas_from_near_gas(prepaid_gas, &fees_config.evm_config, &method_name); + // println!("evm_gas_result: {:?}", evm_gas_result); + // let evm_gas_result = Some(1_000_000_000_000u64.into()); if evm_gas_result.is_none() { return ( None, diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 3d2dc7e411c..90727170632 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -193,16 +193,17 @@ fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { )], false, ); + // println!("deploy evm code"); let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); SignedTransaction::from_actions( nonce as u64, account_id.clone(), - account_id, + account_id.to_owned(), &signer, vec![Action::FunctionCall(FunctionCallAction { method_name: "deploy_code".to_string(), - args: code.into(), + args: hex::decode(code).unwrap(), gas: 10u64.pow(18), deposit: 0, })], @@ -223,6 +224,7 @@ fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { let cost = end_count(config.metric, &start); total_cost += cost; evm_gas = reset_evm_gas_counter(); + println!("+++ evm_gas {}", evm_gas); } } diff --git a/runtime/runtime/src/actions.rs b/runtime/runtime/src/actions.rs index 5672e8821cb..e6bb5216f98 100644 --- a/runtime/runtime/src/actions.rs +++ b/runtime/runtime/src/actions.rs @@ -50,9 +50,9 @@ pub(crate) fn execute_function_call( is_last_action: bool, is_view: bool, ) -> (Option, Option) { - println!("account.code_hash {:?} EVM_CODE_HASH {:?}", account.code_hash, *EVM_CODE_HASH); + // println!("account.code_hash {:?} EVM_CODE_HASH {:?}", account.code_hash, *EVM_CODE_HASH); if account.code_hash == *EVM_CODE_HASH { - println!("evm!!!!"); + // println!("evm!!!!"); near_evm_runner::run_evm( runtime_ext, &config.wasm_config, @@ -67,7 +67,7 @@ pub(crate) fn execute_function_call( is_view, ) } else { - println!("wasm!!!!"); + // println!("wasm!!!!"); let code = match runtime_ext.get_code(account.code_hash) { Ok(Some(code)) => code, Ok(None) => { From 4a39ee8b333f691217f6a7dc9205d5e0130a286d Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Thu, 24 Sep 2020 12:26:08 -0700 Subject: [PATCH 26/61] fix small errors after resolve conflict --- runtime/near-evm-runner/src/lib.rs | 14 ++++++++++++-- runtime/near-evm-runner/tests/utils.rs | 4 ---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 448ee7bd28c..d25c1b4845c 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -264,8 +264,18 @@ impl<'a> EvmContext<'a> { self.add_balance(&sender, U256::from(self.attached_deposit))?; let value = if self.attached_deposit == 0 { None } else { Some(U256::from(self.attached_deposit)) }; - interpreter::call(self, &sender, &sender, value, 0, &contract_address, &input, true) - .map(|rd| rd.to_vec()) + let rd = interpreter::call(self, &sender, &sender, value, 0, &contract_address, &input, true, &self.evm_gas_counter.gas_left(), &self.fees_config.evm_config)?; + match rd { + MessageCallResult::Success(gas_left, data) => { + self.evm_gas_counter.set_gas_left(gas_left); + Ok(data.to_vec()) + } + MessageCallResult::Reverted(gas_left, data) => { + self.evm_gas_counter.set_gas_left(gas_left); + Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) + } + _ => unreachable!(), + } } /// Make an EVM transaction. Calls `contract_address` with `encoded_input`. Execution diff --git a/runtime/near-evm-runner/tests/utils.rs b/runtime/near-evm-runner/tests/utils.rs index 25d5502dd88..651a1e5f2a2 100644 --- a/runtime/near-evm-runner/tests/utils.rs +++ b/runtime/near-evm-runner/tests/utils.rs @@ -43,14 +43,11 @@ pub fn create_context<'a>( 1_000_000_000.into(), ) } -<<<<<<< HEAD #[cfg(test)] pub fn show_evm_gas_used(context: &EvmContext) { println!("Accumulated EVM gas used: {}", &context.evm_gas_counter.used_gas); } -||||||| merged common ancestors -======= pub fn public_key_to_address(public_key: PublicKey) -> Address { match public_key { @@ -84,4 +81,3 @@ pub fn encode_meta_call_function_args( } } } ->>>>>>> evm-precompile From 71917fbc3440b21ce202e48252704a7bec67c9a4 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 25 Sep 2020 11:54:55 -0700 Subject: [PATCH 27/61] deploy cost works, function cost is 0, debug --- runtime/near-evm-runner/src/lib.rs | 16 +- .../tests/build/ConstructorRevert.bin | 1 - .../tests/build/SubContract.bin | 1 - .../src/vm_estimator.rs | 157 +++++++++++++----- runtime/runtime/src/actions.rs | 4 +- runtime/runtime/src/lib.rs | 23 +++ 6 files changed, 161 insertions(+), 41 deletions(-) delete mode 100644 runtime/near-evm-runner/tests/build/ConstructorRevert.bin delete mode 100644 runtime/near-evm-runner/tests/build/SubContract.bin diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index d25c1b4845c..810b8ff8650 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -214,6 +214,7 @@ impl<'a> EvmContext<'a> { self.add_balance(&sender, U256::from(self.attached_deposit))?; let value = if self.attached_deposit == 0 { None } else { Some(U256::from(self.attached_deposit)) }; + println!("gas attached: {}", &self.evm_gas_counter.gas_left()); let rd = interpreter::call( self, &sender, @@ -228,10 +229,12 @@ impl<'a> EvmContext<'a> { )?; match rd { MessageCallResult::Success(gas_left, data) => { + println!("success, gas left: {}", gas_left); self.evm_gas_counter.set_gas_left(gas_left); Ok(data.to_vec()) } MessageCallResult::Reverted(gas_left, data) => { + println!("reverted, gas left: {}", gas_left); self.evm_gas_counter.set_gas_left(gas_left); Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) } @@ -264,7 +267,18 @@ impl<'a> EvmContext<'a> { self.add_balance(&sender, U256::from(self.attached_deposit))?; let value = if self.attached_deposit == 0 { None } else { Some(U256::from(self.attached_deposit)) }; - let rd = interpreter::call(self, &sender, &sender, value, 0, &contract_address, &input, true, &self.evm_gas_counter.gas_left(), &self.fees_config.evm_config)?; + let rd = interpreter::call( + self, + &sender, + &sender, + value, + 0, + &contract_address, + &input, + true, + &self.evm_gas_counter.gas_left(), + &self.fees_config.evm_config, + )?; match rd { MessageCallResult::Success(gas_left, data) => { self.evm_gas_counter.set_gas_left(gas_left); diff --git a/runtime/near-evm-runner/tests/build/ConstructorRevert.bin b/runtime/near-evm-runner/tests/build/ConstructorRevert.bin deleted file mode 100644 index 9aecd04cac3..00000000000 --- a/runtime/near-evm-runner/tests/build/ConstructorRevert.bin +++ /dev/null @@ -1 +0,0 @@ -6080604052348015600f57600080fd5b5060056004146086576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260188152602001807f4572726f72204465706c6f79696e6720436f6e7472616374000000000000000081525060200191505060405180910390fd5b603e8060936000396000f3fe6080604052600080fdfea265627a7a723158204c0402b3a7eae0076263c6db45742f127c7bc67cbdef410b2d6d40f721e3896a64736f6c63430005100032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/SubContract.bin b/runtime/near-evm-runner/tests/build/SubContract.bin deleted file mode 100644 index 2bab6cfd357..00000000000 --- a/runtime/near-evm-runner/tests/build/SubContract.bin +++ /dev/null @@ -1 +0,0 @@ -6080604052600660005560405161022d38038061022d8339818101604052602081101561002b57600080fd5b810190808051906020019092919050505080600081905550506101da806100536000396000f3fe60806040526004361061003f5760003560e01c80632ccb1b301461004157806339c117a4146100b0578063b69ef8a8146100df578063e6a899b61461010a575b005b34801561004d57600080fd5b5061009a6004803603604081101561006457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610135565b6040518082815260200191505060405180910390f35b3480156100bc57600080fd5b506100c561018e565b604051808215151515815260200191505060405180910390f35b3480156100eb57600080fd5b506100f4610197565b6040518082815260200191505060405180910390f35b34801561011657600080fd5b5061011f61019f565b6040518082815260200191505060405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561017d573d6000803e3d6000fd5b50610186610197565b905092915050565b60006001905090565b600047905090565b6000548156fea265627a7a72315820f6f44f505670bac22a9333cd975c317fbaa88dc23152a224b1341fc02dd8764264736f6c63430005100032 \ No newline at end of file diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 90727170632..d018130bdb9 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -18,7 +18,6 @@ use near_primitives::transaction::{ Action, AddKeyAction, CreateAccountAction, DeleteAccountAction, DeleteKeyAction, DeployContractAction, FunctionCallAction, SignedTransaction, StakeAction, TransferAction, }; -use near_primitives::utils::EVM_CODE_HASH; use near_primitives::version::PROTOCOL_VERSION; use near_runtime_fees::RuntimeFeesConfig; use near_vm_logic::gas_counter::reset_evm_gas_counter; @@ -154,6 +153,7 @@ fn load_and_compile(path: &PathBuf, gas_metric: GasMetric, vm_kind: VMKind) -> O } } +#[derive(Debug)] pub struct EvmCost { pub evm_gas: u64, pub cost: Ratio, @@ -178,28 +178,29 @@ fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { accounts_deployed.insert(account_idx); let account_id = get_account_id(account_idx); let signer = InMemorySigner::from_seed(&account_id, KeyType::ED25519, &account_id); - let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); - let mut buf = [0; 32]; - buf[0] = 1; - testbed.lock().unwrap().process_block( - &vec![SignedTransaction::from_actions( - nonce as u64, - account_id.clone(), - account_id.clone(), - &signer, - vec![Action::DeployContract(DeployContractAction { code: buf.into() })], - CryptoHash::default(), - )], - false, - ); + // let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); + // let mut buf = [0; 32]; + // buf[0] = 1; + + // testbed.lock().unwrap().process_block( + // &vec![SignedTransaction::from_actions( + // nonce as u64, + // account_id.clone(), + // account_id.clone(), + // &signer, + // vec![Action::DeployContract(DeployContractAction { code: buf.into() })], + // CryptoHash::default(), + // )], + // false, + // ); // println!("deploy evm code"); let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); SignedTransaction::from_actions( nonce as u64, account_id.clone(), - account_id.to_owned(), + "evm".to_owned(), &signer, vec![Action::FunctionCall(FunctionCallAction { method_name: "deploy_code".to_string(), @@ -216,22 +217,25 @@ fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { for block_size in config.block_sizes.clone() { // [100] for _ in 0..config.iter_per_block { - // 0..10 + // 0..1 let block: Vec<_> = (0..block_size).map(|_| f()).collect(); let mut testbed = testbed.lock().unwrap(); let start = start_count(config.metric); testbed.process_block(&block, allow_failures); let cost = end_count(config.metric, &start); total_cost += cost; - evm_gas = reset_evm_gas_counter(); - println!("+++ evm_gas {}", evm_gas); } } + let start = start_count(config.metric); + testbed.lock().unwrap().process_blocks_until_no_receipts(allow_failures); + let cost = end_count(config.metric, &start); + total_cost += cost; + + let counts = (config.iter_per_block * config.block_sizes.iter().sum::()) as u64; + evm_gas = reset_evm_gas_counter() / counts; - Some(EvmCost { - evm_gas, - cost: Ratio::new(total_cost, (config.iter_per_block * config.block_sizes.len()) as u64), - }) + // evm_gas is times gas spent, so does cost + Some(EvmCost { evm_gas, cost: Ratio::new(total_cost, counts) }) } fn load_and_deploy_evm_contract(path: &PathBuf, config: &Config) -> Option { @@ -299,6 +303,7 @@ pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef { .filter(|x| x.is_some()) .map(|x| x.unwrap()) .collect::>(); + println!("{:?}", measurements); measurements_to_coef(measurements, true) } @@ -324,6 +329,8 @@ pub fn create_evm_context<'a>( fees_config, 1000, account_id.to_string(), + account_id.to_string(), + account_id.to_string(), attached_deposit, 0, 10u64.pow(14), @@ -378,6 +385,7 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { ) }, ]; + println!("{:?}", measurements); measurements_to_coef(measurements, true) } @@ -389,23 +397,98 @@ pub fn measure_evm_function( args: Vec, test_name: &str, ) -> EvmCost { - let gas_metric = config.metric; - let start = start_count(gas_metric); + // let gas_metric = config.metric; + // let start = start_count(gas_metric); + // let mut evm_gas = 0; + // for i in 0..NUM_ITERATIONS { + // if i == 0 { + // evm_gas = context.evm_gas_counter.used_gas.as_u64(); + // } else if i == 1 { + // evm_gas = context.evm_gas_counter.used_gas.as_u64() - evm_gas; + // } + // let _ = context.call_function(args.clone()).unwrap(); + // } + // let end = end_count(gas_metric, &start); + // let cost = Ratio::new(end, NUM_ITERATIONS); + // if verbose { + // println!("Testing call {}: ({}, {})", test_name, evm_gas, cost); + // } + // EvmCost { evm_gas, cost } + + let path = PathBuf::from(config.state_dump_path.as_str()); + println!("{:?}. Preparing testbed. Loading state.", config.metric); + let testbed = Mutex::new(RuntimeTestbed::from_state_dump(&path)); + let allow_failures = false; + let mut nonces: HashMap = HashMap::new(); + let mut accounts_deployed = HashSet::new(); + let code = hex::decode(&TEST).unwrap(); + + let mut f = || { + let account_idx = loop { + let x = rand::thread_rng().gen::() % config.active_accounts; + if accounts_deployed.contains(&x) { + continue; + } + break x; + }; + accounts_deployed.insert(account_idx); + let account_id = get_account_id(account_idx); + let signer = InMemorySigner::from_seed(&account_id, KeyType::ED25519, &account_id); + + let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); + testbed.lock().unwrap().process_block( + &vec![SignedTransaction::from_actions( + nonce as u64, + account_id.clone(), + account_id.clone(), + &signer, + vec![Action::DeployContract(DeployContractAction { code: code.clone() })], + CryptoHash::default(), + )], + false, + ); + testbed.lock().unwrap().process_blocks_until_no_receipts(allow_failures); + + let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); + SignedTransaction::from_actions( + nonce as u64, + account_id.clone(), + "evm".to_owned(), + &signer, + vec![Action::FunctionCall(FunctionCallAction { + method_name: "call_function".to_string(), + args: args.clone(), + gas: 10u64.pow(18), + deposit: 0, + })], + CryptoHash::default(), + ) + }; + let mut evm_gas = 0; - for i in 0..NUM_ITERATIONS { - if i == 0 { - evm_gas = context.evm_gas_counter.used_gas.as_u64(); - } else if i == 1 { - evm_gas = context.evm_gas_counter.used_gas.as_u64() - evm_gas; + let mut total_cost = 0; + for block_size in config.block_sizes.clone() { + // [100] + for _ in 0..config.iter_per_block { + // 0..1 + let block: Vec<_> = (0..block_size).map(|_| f()).collect(); + let mut testbed = testbed.lock().unwrap(); + let start = start_count(config.metric); + testbed.process_block(&block, allow_failures); + let cost = end_count(config.metric, &start); + total_cost += cost; } - let _ = context.call_function(args.clone()).unwrap(); } - let end = end_count(gas_metric, &start); - let cost = Ratio::new(end, NUM_ITERATIONS); - if verbose { - println!("Testing call {}: ({}, {})", test_name, evm_gas, cost); - } - EvmCost { evm_gas, cost } + let start = start_count(config.metric); + testbed.lock().unwrap().process_blocks_until_no_receipts(allow_failures); + let cost = end_count(config.metric, &start); + total_cost += cost; + + let counts = (config.iter_per_block * config.block_sizes.iter().sum::()) as u64; + evm_gas = reset_evm_gas_counter() / counts; + + // evm_gas is times gas spent, so does cost + EvmCost { evm_gas, cost: Ratio::new(total_cost, counts) } } pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiledFunctionCost { diff --git a/runtime/runtime/src/actions.rs b/runtime/runtime/src/actions.rs index db203abf95d..a3e58474050 100644 --- a/runtime/runtime/src/actions.rs +++ b/runtime/runtime/src/actions.rs @@ -52,6 +52,7 @@ pub(crate) fn execute_function_call( ) -> (Option, Option) { let account_id = runtime_ext.account_id(); if account_id == "evm" || account_id.ends_with(".evm") { + // println!("evm!!!!!"); near_evm_runner::run_evm( runtime_ext, &config.wasm_config, @@ -68,7 +69,7 @@ pub(crate) fn execute_function_call( is_view, ) } else { - // println!("wasm!!!!"); + println!("wasm!!!!"); let code = match runtime_ext.get_code(account.code_hash) { Ok(Some(code)) => code, Ok(None) => { @@ -150,6 +151,7 @@ pub(crate) fn action_function_call( is_last_action: bool, epoch_info_provider: &dyn EpochInfoProvider, ) -> Result<(), RuntimeError> { + // println!("aaaaaaaa"); if account.amount.checked_add(function_call.deposit).is_none() { return Err(StorageError::StorageInconsistentState( "Account balance integer overflow during function call deposit".to_string(), diff --git a/runtime/runtime/src/lib.rs b/runtime/runtime/src/lib.rs index 41c4686e8b6..8c077728f8e 100644 --- a/runtime/runtime/src/lib.rs +++ b/runtime/runtime/src/lib.rs @@ -241,6 +241,7 @@ impl Runtime { apply_state.current_protocol_version, ) { Ok(verification_result) => { + // println!("=== a"); near_metrics::inc_counter(&metrics::TRANSACTION_PROCESSED_SUCCESSFULLY_TOTAL); state_update.commit(StateChangeCause::TransactionProcessing { tx_hash: signed_transaction.get_hash(), @@ -275,6 +276,7 @@ impl Runtime { Ok((receipt, outcome)) } Err(e) => { + println!("=== b"); near_metrics::inc_counter(&metrics::TRANSACTION_PROCESSED_FAILED_TOTAL); state_update.rollback(); return Err(e); @@ -297,6 +299,7 @@ impl Runtime { actions: &[Action], epoch_info_provider: &dyn EpochInfoProvider, ) -> Result { + // println!("enter apply_action"); let mut result = ActionResult::default(); let exec_fees = exec_fee( &self.config.transaction_costs, @@ -456,6 +459,8 @@ impl Runtime { stats: &mut ApplyStats, epoch_info_provider: &dyn EpochInfoProvider, ) -> Result { + // println!("=== apply_action_receipt"); + let action_receipt = match receipt.receipt { ReceiptEnum::Action(ref action_receipt) => action_receipt, _ => unreachable!("given receipt should be an action receipt"), @@ -789,6 +794,7 @@ impl Runtime { stats: &mut ApplyStats, epoch_info_provider: &dyn EpochInfoProvider, ) -> Result, RuntimeError> { + // println!("=== process_receipt"); let account_id = &receipt.receiver_id; match receipt.receipt { ReceiptEnum::Data(ref data_receipt) => { @@ -1068,12 +1074,14 @@ impl Runtime { transactions: &[SignedTransaction], epoch_info_provider: &dyn EpochInfoProvider, ) -> Result { + // println!("=== 1"); let trie = Rc::new(trie); let initial_state = TrieUpdate::new(trie.clone(), root); let mut state_update = TrieUpdate::new(trie.clone(), root); let mut stats = ApplyStats::default(); + // println!("=== 2"); if let Some(validator_accounts_update) = validator_accounts_update { self.update_validator_accounts( &mut state_update, @@ -1088,6 +1096,8 @@ impl Runtime { let mut outcomes = vec![]; let mut total_gas_burnt = 0; + // println!("=== 3"); + for signed_transaction in transactions { let (receipt, outcome_with_id) = self.process_transaction( &mut state_update, @@ -1105,15 +1115,18 @@ impl Runtime { outcomes.push(outcome_with_id); } + // println!("=== 4"); let mut delayed_receipts_indices: DelayedReceiptIndices = get(&state_update, &TrieKey::DelayedReceiptIndices)?.unwrap_or_default(); let initial_delayed_receipt_indices = delayed_receipts_indices.clone(); + // println!("=== 5"); let mut process_receipt = |receipt: &Receipt, state_update: &mut TrieUpdate, total_gas_burnt: &mut Gas| -> Result<_, RuntimeError> { + // println!("=== process_receipt outer"); self.process_receipt( state_update, apply_state, @@ -1134,6 +1147,7 @@ impl Runtime { )?; Ok(()) }; + // println!("=== 6"); let gas_limit = apply_state.gas_limit.unwrap_or(Gas::max_value()); @@ -1142,11 +1156,16 @@ impl Runtime { if total_gas_burnt < gas_limit { // NOTE: We don't need to validate the local receipt, because it's just validated in // the `verify_and_charge_transaction`. + // println!("=== 6.1"); + process_receipt(&receipt, &mut state_update, &mut total_gas_burnt)?; } else { + // println!("=== 6.2"); + Self::delay_receipt(&mut state_update, &mut delayed_receipts_indices, receipt)?; } } + // println!("=== 7"); // Then we process the delayed receipts. It's a backlog of receipts from the past blocks. while delayed_receipts_indices.first_index < delayed_receipts_indices.next_available_index { @@ -1174,6 +1193,7 @@ impl Runtime { delayed_receipts_indices.first_index += 1; process_receipt(&receipt, &mut state_update, &mut total_gas_burnt)?; } + // println!("=== 8"); // And then we process the new incoming receipts. These are receipts from other shards. for receipt in incoming_receipts.iter() { @@ -1191,6 +1211,7 @@ impl Runtime { if delayed_receipts_indices != initial_delayed_receipt_indices { set(&mut state_update, TrieKey::DelayedReceiptIndices, &delayed_receipts_indices); } + // println!("=== 9"); check_balance( &self.config.transaction_costs, @@ -1207,6 +1228,7 @@ impl Runtime { state_update.commit(StateChangeCause::UpdatedDelayedReceipts); let (trie_changes, state_changes) = state_update.finalize()?; + // println!("=== 10"); // Dedup proposals from the same account. // The order is deterministically changed. @@ -1218,6 +1240,7 @@ impl Runtime { unique_proposals.push(proposal); } } + // println!("=== 11"); let state_root = trie_changes.new_root; let proof = trie.recorded_storage(); From 2c49248ee937c7ba4912a031ffbac092678c0b2e Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 25 Sep 2020 14:54:03 -0700 Subject: [PATCH 28/61] evm cost of function call --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 8 ++++---- runtime/near-evm-runner/Cargo.toml | 2 ++ runtime/near-evm-runner/src/evm_state.rs | 1 + runtime/near-evm-runner/src/lib.rs | 8 +++++--- runtime/near-vm-logic/src/gas_counter.rs | 7 +++++++ runtime/runtime-params-estimator/src/vm_estimator.rs | 11 ++++++++--- 7 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c9fa7cad25c..b1831eedcd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1162,6 +1162,17 @@ dependencies = [ "log", ] +[[package]] +name = "derivative" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" +dependencies = [ + "proc-macro2 1.0.20", + "quote 1.0.3", + "syn 1.0.38", +] + [[package]] name = "derive_more" version = "0.99.5" @@ -2858,6 +2869,7 @@ dependencies = [ "bn", "borsh", "byteorder", + "derivative", "enum-primitive-derive", "ethabi", "ethabi-contract", diff --git a/Cargo.toml b/Cargo.toml index 649369daac7..5194b790c68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,10 +76,10 @@ neard = { path = "./neard"} testlib = { path = "./test-utils/testlib" } -[profile.release] -lto = true # Enable full link-time optimization. -codegen-units = 1 # Use only 1 codegen-unit to enable full optimizations. -overflow-checks = true +# [profile.release] +# lto = true # Enable full link-time optimization. +# codegen-units = 1 # Use only 1 codegen-unit to enable full optimizations. +# overflow-checks = true [profile.bench] lto = true diff --git a/runtime/near-evm-runner/Cargo.toml b/runtime/near-evm-runner/Cargo.toml index 1fa458ab2ad..1ba78956b99 100644 --- a/runtime/near-evm-runner/Cargo.toml +++ b/runtime/near-evm-runner/Cargo.toml @@ -34,6 +34,8 @@ near-vm-logic = { path = "../near-vm-logic" } near-vm-errors = { path = "../near-vm-errors" } near-runtime-fees = { path = "../near-runtime-fees", version = "2.1.0" } +derivative = "2.1.1" + [dev-dependencies] ethabi = "8.0.0" ethabi-contract = "8.0.0" diff --git a/runtime/near-evm-runner/src/evm_state.rs b/runtime/near-evm-runner/src/evm_state.rs index 79b88014950..1942c585150 100644 --- a/runtime/near-evm-runner/src/evm_state.rs +++ b/runtime/near-evm-runner/src/evm_state.rs @@ -318,6 +318,7 @@ impl EvmState for SubState<'_> { } } +#[derive(Debug)] pub struct EvmGasCounter { pub used_gas: U256, pub max_gas: U256, diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 810b8ff8650..d14764e8fcd 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -214,7 +214,7 @@ impl<'a> EvmContext<'a> { self.add_balance(&sender, U256::from(self.attached_deposit))?; let value = if self.attached_deposit == 0 { None } else { Some(U256::from(self.attached_deposit)) }; - println!("gas attached: {}", &self.evm_gas_counter.gas_left()); + // println!("gas attached: {}", &self.evm_gas_counter.gas_left()); let rd = interpreter::call( self, &sender, @@ -229,7 +229,7 @@ impl<'a> EvmContext<'a> { )?; match rd { MessageCallResult::Success(gas_left, data) => { - println!("success, gas left: {}", gas_left); + // println!("success, gas left: {}", gas_left); self.evm_gas_counter.set_gas_left(gas_left); Ok(data.to_vec()) } @@ -437,7 +437,7 @@ impl<'a> EvmContext<'a> { fn pay_gas_from_evm_gas(&mut self, op: EvmOpForGas) -> Result<()> { let fee_cfg = &self.fees_config.evm_config; let evm_gas = self.evm_gas_counter.used_gas.as_u64(); - println!("============== evm_gas {}", evm_gas); + // println!("============== evm_gas {}", evm_gas); self.gas_counter.inc_evm_gas_counter(evm_gas); let gas = match op { EvmOpForGas::Deploy => { @@ -533,6 +533,7 @@ pub fn run_evm( is_view, evm_gas, ); + let result = match method_name.as_str() { // Change the state methods. "deploy_code" => context.deploy_code(args).map(|address| utils::address_to_vec(&address)), @@ -615,6 +616,7 @@ mod tests { 0, 0, false, + 1_000_000_000.into(), ) } diff --git a/runtime/near-vm-logic/src/gas_counter.rs b/runtime/near-vm-logic/src/gas_counter.rs index 5a3edd6a495..53c07da102b 100644 --- a/runtime/near-vm-logic/src/gas_counter.rs +++ b/runtime/near-vm-logic/src/gas_counter.rs @@ -37,6 +37,13 @@ pub struct GasCounter { profile: Option, } +use std::fmt; +impl fmt::Debug for GasCounter { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("").finish() + } +} + impl GasCounter { pub fn new( ext_costs_config: ExtCostsConfig, diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index d018130bdb9..6e68f1d6255 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -406,7 +406,7 @@ pub fn measure_evm_function( // } else if i == 1 { // evm_gas = context.evm_gas_counter.used_gas.as_u64() - evm_gas; // } - // let _ = context.call_function(args.clone()).unwrap(); + let _ = context.call_function(args.clone()).unwrap(); // } // let end = end_count(gas_metric, &start); // let cost = Ratio::new(end, NUM_ITERATIONS); @@ -440,9 +440,14 @@ pub fn measure_evm_function( &vec![SignedTransaction::from_actions( nonce as u64, account_id.clone(), - account_id.clone(), + "evm".to_owned(), &signer, - vec![Action::DeployContract(DeployContractAction { code: code.clone() })], + vec![Action::FunctionCall(FunctionCallAction { + method_name: "deploy_code".to_string(), + args: code.clone(), + gas: 10u64.pow(18), + deposit: 0, + })], CryptoHash::default(), )], false, From f4dcfa9a1cd573f73f35cde0d93b6191f46219bd Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 25 Sep 2020 14:55:21 -0700 Subject: [PATCH 29/61] comment --- runtime/runtime-params-estimator/src/vm_estimator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 6e68f1d6255..412e92a2d30 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -406,7 +406,7 @@ pub fn measure_evm_function( // } else if i == 1 { // evm_gas = context.evm_gas_counter.used_gas.as_u64() - evm_gas; // } - let _ = context.call_function(args.clone()).unwrap(); + // let _ = context.call_function(args.clone()).unwrap(); // } // let end = end_count(gas_metric, &start); // let cost = Ratio::new(end, NUM_ITERATIONS); From dcf1c70ceac5237762db09f55695487bca011a8d Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 25 Sep 2020 17:00:35 -0700 Subject: [PATCH 30/61] deduct action fee and todo on get correct evm addr to function call --- runtime/near-evm-runner/src/interpreter.rs | 14 +--- runtime/near-evm-runner/src/lib.rs | 7 +- .../src/vm_estimator.rs | 78 +++++++------------ 3 files changed, 30 insertions(+), 69 deletions(-) diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index 42ff784cbb7..f17692c9818 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -85,10 +85,6 @@ pub fn _create( let mut store = StateStore::default(); let mut sub_state = SubState::new(sender, &mut store, state); - // println!("========= code: {}", code.len()); - // println!("========= gas: {}", gas); - // println!("========= {:?}", evm_gas_config); - let params = ActionParams { code_address: *address, address: *address, @@ -103,7 +99,6 @@ pub fn _create( call_type: CallType::None, params_type: vm::ParamsType::Embedded, }; - // println!("========= {:?}", params); sub_state.transfer_balance(sender, address, value)?; @@ -122,14 +117,7 @@ pub fn _create( // Run the code let result = instance.exec(&mut ext); - match result.ok().unwrap() { - Ok(a) => Ok((Some(a), Some(store))), - Err(e) => { - println!("============= {:?}", e); - Ok((None, Some(store))) - } - } - // Ok((result.ok().unwrap().ok(), Some(store))) + Ok((result.ok().unwrap().ok(), Some(store))) } #[allow(clippy::too_many_arguments)] diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index d14764e8fcd..feab98a5f58 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -214,7 +214,6 @@ impl<'a> EvmContext<'a> { self.add_balance(&sender, U256::from(self.attached_deposit))?; let value = if self.attached_deposit == 0 { None } else { Some(U256::from(self.attached_deposit)) }; - // println!("gas attached: {}", &self.evm_gas_counter.gas_left()); let rd = interpreter::call( self, &sender, @@ -229,12 +228,10 @@ impl<'a> EvmContext<'a> { )?; match rd { MessageCallResult::Success(gas_left, data) => { - // println!("success, gas left: {}", gas_left); self.evm_gas_counter.set_gas_left(gas_left); Ok(data.to_vec()) } MessageCallResult::Reverted(gas_left, data) => { - println!("reverted, gas left: {}", gas_left); self.evm_gas_counter.set_gas_left(gas_left); Err(VMLogicError::EvmError(EvmError::Revert(hex::encode(data.to_vec())))) } @@ -437,7 +434,6 @@ impl<'a> EvmContext<'a> { fn pay_gas_from_evm_gas(&mut self, op: EvmOpForGas) -> Result<()> { let fee_cfg = &self.fees_config.evm_config; let evm_gas = self.evm_gas_counter.used_gas.as_u64(); - // println!("============== evm_gas {}", evm_gas); self.gas_counter.inc_evm_gas_counter(evm_gas); let gas = match op { EvmOpForGas::Deploy => { @@ -506,8 +502,7 @@ pub fn run_evm( ) -> (Option, Option) { let evm_gas_result = max_evm_gas_from_near_gas(prepaid_gas, &fees_config.evm_config, &method_name); - // println!("evm_gas_result: {:?}", evm_gas_result); - // let evm_gas_result = Some(1_000_000_000_000u64.into()); + if evm_gas_result.is_none() { return ( None, diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 412e92a2d30..94dc123d355 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -179,23 +179,6 @@ fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { let account_id = get_account_id(account_idx); let signer = InMemorySigner::from_seed(&account_id, KeyType::ED25519, &account_id); - // let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); - // let mut buf = [0; 32]; - // buf[0] = 1; - - // testbed.lock().unwrap().process_block( - // &vec![SignedTransaction::from_actions( - // nonce as u64, - // account_id.clone(), - // account_id.clone(), - // &signer, - // vec![Action::DeployContract(DeployContractAction { code: buf.into() })], - // CryptoHash::default(), - // )], - // false, - // ); - // println!("deploy evm code"); - let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); SignedTransaction::from_actions( nonce as u64, @@ -222,14 +205,11 @@ fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { let mut testbed = testbed.lock().unwrap(); let start = start_count(config.metric); testbed.process_block(&block, allow_failures); + testbed.process_blocks_until_no_receipts(allow_failures); let cost = end_count(config.metric, &start); total_cost += cost; } } - let start = start_count(config.metric); - testbed.lock().unwrap().process_blocks_until_no_receipts(allow_failures); - let cost = end_count(config.metric, &start); - total_cost += cost; let counts = (config.iter_per_block * config.block_sizes.iter().sum::()) as u64; evm_gas = reset_evm_gas_counter() / counts; @@ -273,6 +253,7 @@ pub struct EvmCostCoef { pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef { let globbed_files = glob("./**/*.bin").expect("Failed to read glob pattern for bin files"); + let fees = RuntimeFeesConfig::default(); let paths = globbed_files .filter_map(|x| match x { Ok(p) => Some(p), @@ -302,8 +283,8 @@ pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef { }) .filter(|x| x.is_some()) .map(|x| x.unwrap()) + .map(|measure| deduct_action_receipt_fee(&fees, &measure)) .collect::>(); - println!("{:?}", measurements); measurements_to_coef(measurements, true) } @@ -346,7 +327,8 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { let mut context = create_evm_context(&mut fake_external, &vm_config, &fees, "alice".to_string(), 100); - let sol_test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); + // TODO: this is wrong, figure out the correct addr from deploy step returned. + // let sol_test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); let measurements = vec![ measure_evm_function( @@ -384,12 +366,25 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { "emit_it(8)", ) }, - ]; + ] + .iter() + .map(|measure| deduct_action_receipt_fee(&fees, measure)) + .collect::>(); println!("{:?}", measurements); - measurements_to_coef(measurements, true) } +fn deduct_action_receipt_fee(fees: &RuntimeFeesConfig, evm_cost: &EvmCost) -> EvmCost { + // Because run --only-evm, don't have aggreggated metrics of Metric::noop and Metric::Receipt, so just deduct + // ReceiptFees::ActionFunctionCallBase from last run without --only-evm + EvmCost { + evm_gas: evm_cost.evm_gas, + cost: evm_cost.cost + - fees.action_creation_config.function_call_cost.execution + - fees.action_creation_config.function_call_cost.send_not_sir, + } +} + pub fn measure_evm_function( config: &Config, verbose: bool, @@ -397,24 +392,6 @@ pub fn measure_evm_function( args: Vec, test_name: &str, ) -> EvmCost { - // let gas_metric = config.metric; - // let start = start_count(gas_metric); - // let mut evm_gas = 0; - // for i in 0..NUM_ITERATIONS { - // if i == 0 { - // evm_gas = context.evm_gas_counter.used_gas.as_u64(); - // } else if i == 1 { - // evm_gas = context.evm_gas_counter.used_gas.as_u64() - evm_gas; - // } - // let _ = context.call_function(args.clone()).unwrap(); - // } - // let end = end_count(gas_metric, &start); - // let cost = Ratio::new(end, NUM_ITERATIONS); - // if verbose { - // println!("Testing call {}: ({}, {})", test_name, evm_gas, cost); - // } - // EvmCost { evm_gas, cost } - let path = PathBuf::from(config.state_dump_path.as_str()); println!("{:?}. Preparing testbed. Loading state.", config.metric); let testbed = Mutex::new(RuntimeTestbed::from_state_dump(&path)); @@ -470,6 +447,7 @@ pub fn measure_evm_function( ) }; + reset_evm_gas_counter(); let mut evm_gas = 0; let mut total_cost = 0; for block_size in config.block_sizes.clone() { @@ -480,20 +458,20 @@ pub fn measure_evm_function( let mut testbed = testbed.lock().unwrap(); let start = start_count(config.metric); testbed.process_block(&block, allow_failures); + testbed.process_blocks_until_no_receipts(allow_failures); let cost = end_count(config.metric, &start); total_cost += cost; } } - let start = start_count(config.metric); - testbed.lock().unwrap().process_blocks_until_no_receipts(allow_failures); - let cost = end_count(config.metric, &start); - total_cost += cost; let counts = (config.iter_per_block * config.block_sizes.iter().sum::()) as u64; evm_gas = reset_evm_gas_counter() / counts; - // evm_gas is times gas spent, so does cost - EvmCost { evm_gas, cost: Ratio::new(total_cost, counts) } + let cost = Ratio::new(total_cost, counts); + if verbose { + println!("Testing call {}: ({}, {})", test_name, evm_gas, cost); + } + EvmCost { evm_gas, cost } } pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiledFunctionCost { @@ -609,7 +587,7 @@ pub fn cost_to_compile( let base = Ratio::new(u64::MAX, 1); if verbose { println!( - "Abount to compile {}", + "About to compile {}", match vm_kind { VMKind::Wasmer => "wasmer", VMKind::Wasmtime => { From 7b21ee77d49726d1bc98701ddac271481b4efdb6 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 25 Sep 2020 21:55:55 -0700 Subject: [PATCH 31/61] fix deploy evm addr --- Cargo.lock | 1 + Cargo.toml | 4 +- runtime/near-evm-runner/Cargo.toml | 6 +- runtime/near-evm-runner/src/lib.rs | 22 +++- runtime/runtime-params-estimator/Cargo.toml | 3 +- .../src/vm_estimator.rs | 119 ++++++++++-------- 6 files changed, 100 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b1831eedcd5..64dc7372938 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4403,6 +4403,7 @@ dependencies = [ "ethabi", "ethabi-contract", "ethabi-derive", + "ethereum-types", "glob 0.3.0", "gnuplot", "hex", diff --git a/Cargo.toml b/Cargo.toml index 5194b790c68..1542a0b9f2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,10 +76,10 @@ neard = { path = "./neard"} testlib = { path = "./test-utils/testlib" } -# [profile.release] +[profile.release] # lto = true # Enable full link-time optimization. # codegen-units = 1 # Use only 1 codegen-unit to enable full optimizations. -# overflow-checks = true +overflow-checks = true [profile.bench] lto = true diff --git a/runtime/near-evm-runner/Cargo.toml b/runtime/near-evm-runner/Cargo.toml index 1ba78956b99..3c800f278d8 100644 --- a/runtime/near-evm-runner/Cargo.toml +++ b/runtime/near-evm-runner/Cargo.toml @@ -43,4 +43,8 @@ ethabi-derive = "8.0.0" lazy_static = "1.4" lazy-static-include = "2.2.2" -near-crypto = { path = "../../core/crypto" } \ No newline at end of file +near-crypto = { path = "../../core/crypto" } + +[features] +default = [] +costs_counting = [] \ No newline at end of file diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index feab98a5f58..e6d9bfd22ef 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -61,6 +61,11 @@ fn address_to_key(prefix: KeyPrefix, address: &H160) -> Vec { result } +#[cfg(feature = "costs_counting")] +thread_local! { + static EVM_LAST_DEPLOYED: std::cell::RefCell = Default::default(); +} + impl<'a> EvmState for EvmContext<'a> { fn code_at(&self, address: &H160) -> Result>> { self.ext @@ -485,6 +490,15 @@ fn max_evm_gas_from_near_gas( } } +#[cfg(feature = "costs_counting")] +pub fn evm_last_deployed_addr() -> H160 { + let mut ret = Default::default(); + EVM_LAST_DEPLOYED.with(|addr| { + ret = addr.borrow().clone(); + }); + ret +} + pub fn run_evm( ext: &mut dyn External, config: &VMConfig, @@ -531,7 +545,13 @@ pub fn run_evm( let result = match method_name.as_str() { // Change the state methods. - "deploy_code" => context.deploy_code(args).map(|address| utils::address_to_vec(&address)), + "deploy_code" => context.deploy_code(args).map(|address| { + #[cfg(feature = "costs_counting")] + EVM_LAST_DEPLOYED.with(|addr| { + *addr.borrow_mut() = address.clone(); + }); + utils::address_to_vec(&address) + }), "call_function" => context.call_function(args), "call" => context.call_function(args), "meta_call" => context.meta_call_function(args), diff --git a/runtime/runtime-params-estimator/Cargo.toml b/runtime/runtime-params-estimator/Cargo.toml index 744a80b3f21..f248ee76e2a 100644 --- a/runtime/runtime-params-estimator/Cargo.toml +++ b/runtime/runtime-params-estimator/Cargo.toml @@ -28,11 +28,12 @@ neard = { path = "../../neard" } rocksdb = { git = "https://github.com/nearprotocol/rust-rocksdb", branch="disable-thread" } glob = "0.3.0" walrus = "0.18.0" -near-evm-runner = { path = "../../runtime/near-evm-runner" } +near-evm-runner = { path = "../../runtime/near-evm-runner", features = ["costs_counting"] } hex = "0.4" ethabi = "8.0.0" ethabi-contract = "8.0.0" ethabi-derive = "8.0.0" +ethereum-types = "0.6.0" lazy-static-include = "2.2.2" [features] diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 94dc123d355..59fa175fc12 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -7,11 +7,12 @@ use crate::testbed_runners::start_count; use crate::testbed_runners::Config; use crate::testbed_runners::GasMetric; use ethabi_contract::use_contract; +use ethereum_types::H160; use glob::glob; use lazy_static_include::lazy_static_include_str; use near_crypto::{InMemorySigner, KeyType, PublicKey}; use near_evm_runner::utils::encode_call_function_args; -use near_evm_runner::{run_evm, EvmContext}; +use near_evm_runner::{evm_last_deployed_addr, run_evm, EvmContext}; use near_primitives::account::{AccessKey, AccessKeyPermission, FunctionCallPermission}; use near_primitives::hash::CryptoHash; use near_primitives::transaction::{ @@ -283,9 +284,8 @@ pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef { }) .filter(|x| x.is_some()) .map(|x| x.unwrap()) - .map(|measure| deduct_action_receipt_fee(&fees, &measure)) .collect::>(); - measurements_to_coef(measurements, true) + deduct_action_receipt_fee(&fees, measurements_to_coef(measurements, true)) } use_contract!(soltest, "../near-evm-runner/tests/build/SolTests.abi"); @@ -328,31 +328,40 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { let mut context = create_evm_context(&mut fake_external, &vm_config, &fees, "alice".to_string(), 100); // TODO: this is wrong, figure out the correct addr from deploy step returned. - // let sol_test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); + let sol_test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); let measurements = vec![ measure_evm_function( config, verbose, &mut context, - encode_call_function_args(sol_test_addr, soltest::functions::deploy_new_guy::call(8).0), + |sol_test_addr| { + encode_call_function_args( + sol_test_addr, + soltest::functions::deploy_new_guy::call(8).0, + ) + }, "deploy_new_guy(8)", ), measure_evm_function( config, verbose, &mut context, - encode_call_function_args(sol_test_addr, soltest::functions::pay_new_guy::call(8).0), + |sol_test_addr| { + encode_call_function_args(sol_test_addr, soltest::functions::pay_new_guy::call(8).0) + }, "pay_new_guy(8)", ), measure_evm_function( config, verbose, &mut context, - encode_call_function_args( - sol_test_addr, - soltest::functions::return_some_funds::call().0, - ), + |sol_test_addr| { + encode_call_function_args( + sol_test_addr, + soltest::functions::return_some_funds::call().0, + ) + }, "return_some_funds()", ), { @@ -362,34 +371,33 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { config, verbose, &mut context, - encode_call_function_args(sol_test_addr, soltest::functions::emit_it::call(8).0), + |sol_test_addr| { + encode_call_function_args(sol_test_addr, soltest::functions::emit_it::call(8).0) + }, "emit_it(8)", ) }, - ] - .iter() - .map(|measure| deduct_action_receipt_fee(&fees, measure)) - .collect::>(); + ]; println!("{:?}", measurements); - measurements_to_coef(measurements, true) + deduct_action_receipt_fee(&fees, measurements_to_coef(measurements, true)) } -fn deduct_action_receipt_fee(fees: &RuntimeFeesConfig, evm_cost: &EvmCost) -> EvmCost { +fn deduct_action_receipt_fee(fees: &RuntimeFeesConfig, evm_cost: Coef) -> Coef { // Because run --only-evm, don't have aggreggated metrics of Metric::noop and Metric::Receipt, so just deduct // ReceiptFees::ActionFunctionCallBase from last run without --only-evm - EvmCost { - evm_gas: evm_cost.evm_gas, - cost: evm_cost.cost + ( + evm_cost.0, + evm_cost.1 - fees.action_creation_config.function_call_cost.execution - fees.action_creation_config.function_call_cost.send_not_sir, - } + ) } -pub fn measure_evm_function( +pub fn measure_evm_function Vec + Copy>( config: &Config, verbose: bool, context: &mut EvmContext, - args: Vec, + args_encoder: F, test_name: &str, ) -> EvmCost { let path = PathBuf::from(config.state_dump_path.as_str()); @@ -430,6 +438,7 @@ pub fn measure_evm_function( false, ); testbed.lock().unwrap().process_blocks_until_no_receipts(allow_failures); + let addr = evm_last_deployed_addr(); let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); SignedTransaction::from_actions( @@ -439,7 +448,7 @@ pub fn measure_evm_function( &signer, vec![Action::FunctionCall(FunctionCallAction { method_name: "call_function".to_string(), - args: args.clone(), + args: args_encoder(addr), gas: 10u64.pow(18), deposit: 0, })], @@ -481,68 +490,78 @@ pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiled let mut context = create_evm_context(&mut fake_external, &vm_config, &fees, "alice".to_string(), 0); - let precompiled_function_addr = - context.deploy_code(hex::decode(&PRECOMPILED_TEST).unwrap()).unwrap(); let measurements = vec![ measure_evm_function( config, verbose, &mut context, - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::noop::call().0, - ), + |precompiled_function_addr| { + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::noop::call().0, + ) + }, "noop()", ), measure_evm_function( config, verbose, &mut context, - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::test_ecrecover::call().0, - ), + |precompiled_function_addr| { + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_ecrecover::call().0, + ) + }, "test_ecrecover()", ), measure_evm_function( config, verbose, &mut context, - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::test_sha256::call().0, - ), + |precompiled_function_addr| { + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_sha256::call().0, + ) + }, "test_sha256()", ), measure_evm_function( config, verbose, &mut context, - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::test_ripemd160::call().0, - ), + |precompiled_function_addr| { + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_ripemd160::call().0, + ) + }, "test_ripemd160()", ), measure_evm_function( config, verbose, &mut context, - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::test_identity::call().0, - ), + |precompiled_function_addr| { + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_identity::call().0, + ) + }, "test_identity()", ), measure_evm_function( config, verbose, &mut context, - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::test_mod_exp::call().0, - ), + |precompiled_function_addr| { + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_mod_exp::call().0, + ) + }, "test_mod_exp()", ), ]; From 53c39f87b392023c3a98994a5af9dba796e5d9b1 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Sat, 26 Sep 2020 00:48:01 -0700 Subject: [PATCH 32/61] correct deduct action receipt cost --- runtime/runtime-params-estimator/src/cases.rs | 14 +- .../src/vm_estimator.rs | 150 +++++++++--------- 2 files changed, 84 insertions(+), 80 deletions(-) diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index 7ec04fb2b82..c0aa946f72a 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -20,7 +20,9 @@ use crate::stats::Measurements; use crate::testbed::RuntimeTestbed; use crate::testbed_runners::GasMetric; use crate::testbed_runners::{get_account_id, measure_actions, measure_transactions, Config}; -use crate::vm_estimator::{cost_of_evm, cost_per_op, cost_to_compile, near_cost_to_evm_gas}; +use crate::vm_estimator::{ + action_receipt_fee, cost_of_evm, cost_per_op, cost_to_compile, near_cost_to_evm_gas, +}; use near_runtime_fees::{ AccessKeyCreationConfig, ActionCreationConfig, DataReceiptCreationConfig, Fee, RuntimeFeesConfig, @@ -164,13 +166,13 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon let cost = cost_of_evm(&config, true); println!( "EVM base deploy (and init evm instance) cost: {}, deploy cost per EVM gas: {}", - ratio_to_gas(config.metric, cost.deploy_cost.1), - ratio_to_gas(config.metric, cost.deploy_cost.0) + ratio_to_gas(config.metric, cost.deploy_cost.1) - action_receipt_fee(), + ratio_to_gas(config.metric, cost.deploy_cost.0), ); println!( - "EVM function call cost: {}, function call cost per EVM gas: {}", - ratio_to_gas(config.metric, cost.funcall_cost.1), - ratio_to_gas(config.metric, cost.funcall_cost.0) + "EVM base function call cost: {}, function call cost per EVM gas: {}", + ratio_to_gas(config.metric, cost.funcall_cost.1) - action_receipt_fee(), + ratio_to_gas(config.metric, cost.funcall_cost.0), ); println!("EVM precompiled function evm gas:"); println!( diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 59fa175fc12..1cf0bf35d65 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -285,7 +285,7 @@ pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef { .filter(|x| x.is_some()) .map(|x| x.unwrap()) .collect::>(); - deduct_action_receipt_fee(&fees, measurements_to_coef(measurements, true)) + measurements_to_coef(measurements, true) } use_contract!(soltest, "../near-evm-runner/tests/build/SolTests.abi"); @@ -325,16 +325,10 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { let vm_config = VMConfig::default(); let fees = RuntimeFeesConfig::default(); - let mut context = - create_evm_context(&mut fake_external, &vm_config, &fees, "alice".to_string(), 100); - // TODO: this is wrong, figure out the correct addr from deploy step returned. - let sol_test_addr = context.deploy_code(hex::decode(&TEST).unwrap()).unwrap(); - let measurements = vec![ measure_evm_function( config, verbose, - &mut context, |sol_test_addr| { encode_call_function_args( sol_test_addr, @@ -346,7 +340,6 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { measure_evm_function( config, verbose, - &mut context, |sol_test_addr| { encode_call_function_args(sol_test_addr, soltest::functions::pay_new_guy::call(8).0) }, @@ -355,7 +348,6 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { measure_evm_function( config, verbose, - &mut context, |sol_test_addr| { encode_call_function_args( sol_test_addr, @@ -364,39 +356,59 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { }, "return_some_funds()", ), - { - // function not payable must has zero deposit - context.attached_deposit = 0; - measure_evm_function( - config, - verbose, - &mut context, - |sol_test_addr| { - encode_call_function_args(sol_test_addr, soltest::functions::emit_it::call(8).0) - }, - "emit_it(8)", - ) - }, + measure_evm_function( + config, + verbose, + |sol_test_addr| { + encode_call_function_args(sol_test_addr, soltest::functions::emit_it::call(8).0) + }, + "emit_it(8)", + ), ]; println!("{:?}", measurements); - deduct_action_receipt_fee(&fees, measurements_to_coef(measurements, true)) + measurements_to_coef(measurements, true) } -fn deduct_action_receipt_fee(fees: &RuntimeFeesConfig, evm_cost: Coef) -> Coef { +pub fn action_receipt_fee() -> u64 { // Because run --only-evm, don't have aggreggated metrics of Metric::noop and Metric::Receipt, so just deduct - // ReceiptFees::ActionFunctionCallBase from last run without --only-evm - ( - evm_cost.0, - evm_cost.1 - - fees.action_creation_config.function_call_cost.execution - - fees.action_creation_config.function_call_cost.send_not_sir, - ) + // ReceiptFees::ActionFunctionCallBase from last run without --only-evm, which is this function returns + // TODO: it should be updated to only function_call_cost, after #3279 is merged into upstream branch: evm-precompile + let fees = RuntimeFeesConfig::default(); + + fees.action_receipt_creation_config.execution + fees.action_receipt_creation_config.send_not_sir } -pub fn measure_evm_function Vec + Copy>( +pub fn measure_evm_precompile_function( config: &Config, verbose: bool, context: &mut EvmContext, + args: Vec, + test_name: &str, +) -> EvmCost { + // adding action receipt etc is too big compare too evm precompile function itself and cause the error is bigger + // than evm precompile function cost, so measure this cost in evm context level to be precise + let gas_metric = config.metric; + let start = start_count(gas_metric); + let mut evm_gas = 0; + for i in 0..NUM_ITERATIONS { + if i == 0 { + evm_gas = context.evm_gas_counter.used_gas.as_u64(); + } else if i == 1 { + evm_gas = context.evm_gas_counter.used_gas.as_u64() - evm_gas; + } + let _ = context.call_function(args.clone()).unwrap(); + } + let end = end_count(gas_metric, &start); + let cost = Ratio::new(end, NUM_ITERATIONS); + if verbose { + println!("Testing call {}: ({}, {})", test_name, evm_gas, cost); + } + EvmCost { evm_gas, cost } +} + +pub fn measure_evm_function Vec + Copy>( + config: &Config, + verbose: bool, args_encoder: F, test_name: &str, ) -> EvmCost { @@ -490,78 +502,68 @@ pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiled let mut context = create_evm_context(&mut fake_external, &vm_config, &fees, "alice".to_string(), 0); + let precompiled_function_addr = + context.deploy_code(hex::decode(&PRECOMPILED_TEST).unwrap()).unwrap(); let measurements = vec![ - measure_evm_function( + measure_evm_precompile_function( config, verbose, &mut context, - |precompiled_function_addr| { - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::noop::call().0, - ) - }, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::noop::call().0, + ), "noop()", ), - measure_evm_function( + measure_evm_precompile_function( config, verbose, &mut context, - |precompiled_function_addr| { - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::test_ecrecover::call().0, - ) - }, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_ecrecover::call().0, + ), "test_ecrecover()", ), - measure_evm_function( + measure_evm_precompile_function( config, verbose, &mut context, - |precompiled_function_addr| { - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::test_sha256::call().0, - ) - }, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_sha256::call().0, + ), "test_sha256()", ), - measure_evm_function( + measure_evm_precompile_function( config, verbose, &mut context, - |precompiled_function_addr| { - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::test_ripemd160::call().0, - ) - }, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_ripemd160::call().0, + ), "test_ripemd160()", ), - measure_evm_function( + measure_evm_precompile_function( config, verbose, &mut context, - |precompiled_function_addr| { - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::test_identity::call().0, - ) - }, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_identity::call().0, + ), "test_identity()", ), - measure_evm_function( + measure_evm_precompile_function( config, verbose, &mut context, - |precompiled_function_addr| { - encode_call_function_args( - precompiled_function_addr, - precompiled_function::functions::test_mod_exp::call().0, - ) - }, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_mod_exp::call().0, + ), "test_mod_exp()", ), ]; From d7dd8c5b14ff89f0b24b3478f0d4ad81055d099f Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 28 Sep 2020 09:22:43 -0700 Subject: [PATCH 33/61] saturating sub --- runtime/near-evm-runner/src/evm_state.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/near-evm-runner/src/evm_state.rs b/runtime/near-evm-runner/src/evm_state.rs index 1942c585150..b080ed9d5f4 100644 --- a/runtime/near-evm-runner/src/evm_state.rs +++ b/runtime/near-evm-runner/src/evm_state.rs @@ -330,12 +330,12 @@ impl EvmGasCounter { } pub fn pay_gas(&mut self, amount: U256) { - // TODO: return error if gas not sufficient + debug_assert!(self.used_gas + amount <= self.max_gas); self.used_gas += amount; } pub fn set_gas_left(&mut self, left: U256) { - self.used_gas = self.max_gas - left; + self.used_gas = self.max_gas.saturating_sub(left); } pub fn gas_left(&self) -> U256 { From f831b07cb28caf9cd5d6df437c20ed6457cf1b2c Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 29 Sep 2020 09:45:41 -0700 Subject: [PATCH 34/61] adding warmup --- runtime/near-runtime-fees/src/lib.rs | 18 +++--- .../src/testbed_runners.rs | 2 +- .../src/vm_estimator.rs | 60 ++++++++++--------- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/runtime/near-runtime-fees/src/lib.rs b/runtime/near-runtime-fees/src/lib.rs index 06ed31969bf..88da238338f 100644 --- a/runtime/near-runtime-fees/src/lib.rs +++ b/runtime/near-runtime-fees/src/lib.rs @@ -255,15 +255,15 @@ impl Default for RuntimeFeesConfig { // Got inside emu-cost docker, numbers very slightly in different runs: // cd /host/nearcore/runtime/near-evm-runner/tests // ../../runtime-params-estimator/emu-cost/counter_plugin/qemu-x86_64 -cpu Westmere-v1 -plugin file=../../runtime-params-estimator/emu-cost/counter_plugin/libcounter.so ../../../target/release/runtime-params-estimator --home /tmp/data --accounts-num 2000 --iters 1 --warmup-iters 1 --evm-only - bootstrap_cost: 11374412500, - deploy_cost_per_evm_gas: 31618278, - funcall_cost_base: 19008337500, - funcall_cost_per_evm_gas: 352935, - ecrecover_cost: 792636, - sha256_cost: 21337, - ripemd160_cost: 19810, - identity_cost: 58391, - modexp_cost: 31967, + bootstrap_cost: 29513857500, + deploy_cost_per_evm_gas: 29008902, + funcall_cost_base: 108890282500, + funcall_cost_per_evm_gas: 35070059, + ecrecover_cost: 8005, + sha256_cost: 215, + ripemd160_cost: 200, + identity_cost: 591, + modexp_cost: 330, }, } } diff --git a/runtime/runtime-params-estimator/src/testbed_runners.rs b/runtime/runtime-params-estimator/src/testbed_runners.rs index 11a9b842dc6..fc265e08229 100644 --- a/runtime/runtime-params-estimator/src/testbed_runners.rs +++ b/runtime/runtime-params-estimator/src/testbed_runners.rs @@ -18,7 +18,7 @@ pub fn get_account_id(account_index: usize) -> String { } /// Total number of transactions that we need to prepare. -fn total_transactions(config: &Config) -> usize { +pub fn total_transactions(config: &Config) -> usize { config.block_sizes.iter().sum::() * config.iter_per_block } diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 1cf0bf35d65..4154ce717c1 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -1,24 +1,19 @@ -use crate::cases::Metric; -use crate::stats::Measurements; use crate::testbed::RuntimeTestbed; use crate::testbed_runners::end_count; use crate::testbed_runners::get_account_id; use crate::testbed_runners::start_count; +use crate::testbed_runners::total_transactions; use crate::testbed_runners::Config; use crate::testbed_runners::GasMetric; use ethabi_contract::use_contract; use ethereum_types::H160; use glob::glob; use lazy_static_include::lazy_static_include_str; -use near_crypto::{InMemorySigner, KeyType, PublicKey}; +use near_crypto::{InMemorySigner, KeyType}; use near_evm_runner::utils::encode_call_function_args; -use near_evm_runner::{evm_last_deployed_addr, run_evm, EvmContext}; -use near_primitives::account::{AccessKey, AccessKeyPermission, FunctionCallPermission}; +use near_evm_runner::{evm_last_deployed_addr, EvmContext}; use near_primitives::hash::CryptoHash; -use near_primitives::transaction::{ - Action, AddKeyAction, CreateAccountAction, DeleteAccountAction, DeleteKeyAction, - DeployContractAction, FunctionCallAction, SignedTransaction, StakeAction, TransferAction, -}; +use near_primitives::transaction::{Action, FunctionCallAction, SignedTransaction}; use near_primitives::version::PROTOCOL_VERSION; use near_runtime_fees::RuntimeFeesConfig; use near_vm_logic::gas_counter::reset_evm_gas_counter; @@ -26,8 +21,7 @@ use near_vm_logic::mocks::mock_external::MockedExternal; use near_vm_logic::{VMConfig, VMContext, VMKind, VMOutcome}; use near_vm_runner::{compile_module, prepare, VMError}; use num_rational::Ratio; -use rand::seq::SliceRandom; -use rand::{Rng, SeedableRng}; +use rand::Rng; use std::collections::hash_map::DefaultHasher; use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; @@ -196,12 +190,19 @@ fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { ) }; + for _ in 0..config.warmup_iters_per_block { + for block_size in config.block_sizes.clone() { + let block: Vec<_> = (0..block_size).map(|_| f()).collect(); + let mut testbed = testbed.lock().unwrap(); + testbed.process_block(&block, allow_failures); + testbed.process_blocks_until_no_receipts(allow_failures); + } + } + reset_evm_gas_counter(); let mut evm_gas = 0; let mut total_cost = 0; - for block_size in config.block_sizes.clone() { - // [100] - for _ in 0..config.iter_per_block { - // 0..1 + for _ in 0..config.iter_per_block { + for block_size in config.block_sizes.clone() { let block: Vec<_> = (0..block_size).map(|_| f()).collect(); let mut testbed = testbed.lock().unwrap(); let start = start_count(config.metric); @@ -209,11 +210,12 @@ fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { testbed.process_blocks_until_no_receipts(allow_failures); let cost = end_count(config.metric, &start); total_cost += cost; + evm_gas += reset_evm_gas_counter(); } } - let counts = (config.iter_per_block * config.block_sizes.iter().sum::()) as u64; - evm_gas = reset_evm_gas_counter() / counts; + let counts = total_transactions(config) as u64; + evm_gas /= counts; // evm_gas is times gas spent, so does cost Some(EvmCost { evm_gas, cost: Ratio::new(total_cost, counts) }) @@ -254,7 +256,6 @@ pub struct EvmCostCoef { pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef { let globbed_files = glob("./**/*.bin").expect("Failed to read glob pattern for bin files"); - let fees = RuntimeFeesConfig::default(); let paths = globbed_files .filter_map(|x| match x { Ok(p) => Some(p), @@ -321,10 +322,6 @@ pub fn create_evm_context<'a>( } pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { - let mut fake_external = MockedExternal::new(); - let vm_config = VMConfig::default(); - let fees = RuntimeFeesConfig::default(); - let measurements = vec![ measure_evm_function( config, @@ -468,13 +465,19 @@ pub fn measure_evm_function Vec + Copy>( ) }; + for _ in 0..config.warmup_iters_per_block { + for block_size in config.block_sizes.clone() { + let block: Vec<_> = (0..block_size).map(|_| f()).collect(); + let mut testbed = testbed.lock().unwrap(); + testbed.process_block(&block, allow_failures); + testbed.process_blocks_until_no_receipts(allow_failures); + } + } reset_evm_gas_counter(); let mut evm_gas = 0; let mut total_cost = 0; - for block_size in config.block_sizes.clone() { - // [100] - for _ in 0..config.iter_per_block { - // 0..1 + for _ in 0..config.iter_per_block { + for block_size in config.block_sizes.clone() { let block: Vec<_> = (0..block_size).map(|_| f()).collect(); let mut testbed = testbed.lock().unwrap(); let start = start_count(config.metric); @@ -482,11 +485,12 @@ pub fn measure_evm_function Vec + Copy>( testbed.process_blocks_until_no_receipts(allow_failures); let cost = end_count(config.metric, &start); total_cost += cost; + evm_gas += reset_evm_gas_counter(); } } - let counts = (config.iter_per_block * config.block_sizes.iter().sum::()) as u64; - evm_gas = reset_evm_gas_counter() / counts; + let counts = total_transactions(config) as u64; + evm_gas /= counts; let cost = Ratio::new(total_cost, counts); if verbose { From 6ca3489fc2c06d18c87e118853c2ed0b2ab54c8b Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 29 Sep 2020 11:30:20 -0700 Subject: [PATCH 35/61] remove some debug prints --- runtime/runtime/src/lib.rs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/runtime/runtime/src/lib.rs b/runtime/runtime/src/lib.rs index 8c077728f8e..b006e2dc5c7 100644 --- a/runtime/runtime/src/lib.rs +++ b/runtime/runtime/src/lib.rs @@ -1074,14 +1074,12 @@ impl Runtime { transactions: &[SignedTransaction], epoch_info_provider: &dyn EpochInfoProvider, ) -> Result { - // println!("=== 1"); let trie = Rc::new(trie); let initial_state = TrieUpdate::new(trie.clone(), root); let mut state_update = TrieUpdate::new(trie.clone(), root); let mut stats = ApplyStats::default(); - // println!("=== 2"); if let Some(validator_accounts_update) = validator_accounts_update { self.update_validator_accounts( &mut state_update, @@ -1096,8 +1094,6 @@ impl Runtime { let mut outcomes = vec![]; let mut total_gas_burnt = 0; - // println!("=== 3"); - for signed_transaction in transactions { let (receipt, outcome_with_id) = self.process_transaction( &mut state_update, @@ -1115,18 +1111,15 @@ impl Runtime { outcomes.push(outcome_with_id); } - // println!("=== 4"); let mut delayed_receipts_indices: DelayedReceiptIndices = get(&state_update, &TrieKey::DelayedReceiptIndices)?.unwrap_or_default(); let initial_delayed_receipt_indices = delayed_receipts_indices.clone(); - // println!("=== 5"); let mut process_receipt = |receipt: &Receipt, state_update: &mut TrieUpdate, total_gas_burnt: &mut Gas| -> Result<_, RuntimeError> { - // println!("=== process_receipt outer"); self.process_receipt( state_update, apply_state, @@ -1147,7 +1140,6 @@ impl Runtime { )?; Ok(()) }; - // println!("=== 6"); let gas_limit = apply_state.gas_limit.unwrap_or(Gas::max_value()); @@ -1156,16 +1148,11 @@ impl Runtime { if total_gas_burnt < gas_limit { // NOTE: We don't need to validate the local receipt, because it's just validated in // the `verify_and_charge_transaction`. - // println!("=== 6.1"); - process_receipt(&receipt, &mut state_update, &mut total_gas_burnt)?; } else { - // println!("=== 6.2"); - Self::delay_receipt(&mut state_update, &mut delayed_receipts_indices, receipt)?; } } - // println!("=== 7"); // Then we process the delayed receipts. It's a backlog of receipts from the past blocks. while delayed_receipts_indices.first_index < delayed_receipts_indices.next_available_index { @@ -1193,7 +1180,6 @@ impl Runtime { delayed_receipts_indices.first_index += 1; process_receipt(&receipt, &mut state_update, &mut total_gas_burnt)?; } - // println!("=== 8"); // And then we process the new incoming receipts. These are receipts from other shards. for receipt in incoming_receipts.iter() { @@ -1211,7 +1197,6 @@ impl Runtime { if delayed_receipts_indices != initial_delayed_receipt_indices { set(&mut state_update, TrieKey::DelayedReceiptIndices, &delayed_receipts_indices); } - // println!("=== 9"); check_balance( &self.config.transaction_costs, @@ -1228,7 +1213,6 @@ impl Runtime { state_update.commit(StateChangeCause::UpdatedDelayedReceipts); let (trie_changes, state_changes) = state_update.finalize()?; - // println!("=== 10"); // Dedup proposals from the same account. // The order is deterministically changed. @@ -1240,7 +1224,6 @@ impl Runtime { unique_proposals.push(proposal); } } - // println!("=== 11"); let state_root = trie_changes.new_root; let proof = trie.recorded_storage(); From 0e1bb66cd793177f6f3d285c511b0754aa50d4f0 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 29 Sep 2020 22:01:33 -0700 Subject: [PATCH 36/61] costs counting only on recet sevm gas counter --- runtime/near-vm-logic/src/gas_counter.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/near-vm-logic/src/gas_counter.rs b/runtime/near-vm-logic/src/gas_counter.rs index 53c07da102b..557f7dcf7a0 100644 --- a/runtime/near-vm-logic/src/gas_counter.rs +++ b/runtime/near-vm-logic/src/gas_counter.rs @@ -11,6 +11,7 @@ thread_local! { pub static EVM_GAS_COUNTER: std::cell::RefCell = Default::default(); } +#[cfg(feature = "costs_counting")] pub fn reset_evm_gas_counter() -> u64 { let mut ret = 0; EVM_GAS_COUNTER.with(|f| { From f4e9b767e041b343d2fad16b1d424e6276f732e5 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Wed, 30 Sep 2020 09:35:03 -0700 Subject: [PATCH 37/61] some fixes --- runtime/near-evm-runner/src/builtins.rs | 3 +-- runtime/near-evm-runner/src/interpreter.rs | 7 +++---- runtime/near-evm-runner/src/near_ext.rs | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/runtime/near-evm-runner/src/builtins.rs b/runtime/near-evm-runner/src/builtins.rs index 6dfb09c8afd..c3d86f6278a 100644 --- a/runtime/near-evm-runner/src/builtins.rs +++ b/runtime/near-evm-runner/src/builtins.rs @@ -4,7 +4,6 @@ use std::{ mem::size_of, }; -// use bn::arith::U256; use byteorder::{BigEndian, ByteOrder, LittleEndian, ReadBytesExt}; use ethereum_types::{Address, H256, U256}; use near_runtime_fees::EvmCostConfig; @@ -463,7 +462,7 @@ impl Bn128PairingImpl { }; let mut buf = [0u8; 32]; - ret_val.to_big_endian(&mut buf).expect("Can't fail"); + ret_val.to_big_endian(&mut buf); output.write(0, &buf); Ok(()) diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index 8a0e4a2705a..203ff7fa823 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -4,8 +4,8 @@ use ethereum_types::{Address, U256}; use evm::{CreateContractAddress, Factory}; use near_runtime_fees::EvmCostConfig; use vm::{ - ActionParams, ActionValue, CallType, ContractCreateResult, ExecTrapResult, Ext, GasLeft, MessageCallResult, - ParamsType, ReturnData, Schedule, + ActionParams, ActionValue, CallType, ContractCreateResult, ExecTrapResult, Ext, GasLeft, + MessageCallResult, ParamsType, ReturnData, Schedule, }; use near_vm_errors::{EvmError, VMLogicError}; @@ -59,8 +59,7 @@ pub fn deploy_code( Some(GasLeft::NeedsReturn { gas_left: left, data, apply_state }) => { (data, apply_state, left) } - Ok(Err(err)) => return Err(convert_vm_error(err)), - Err(_) => return Err(VMLogicError::EvmError(EvmError::Reverted)), + None => return Err(VMLogicError::EvmError(EvmError::Reverted)), }; if apply { diff --git a/runtime/near-evm-runner/src/near_ext.rs b/runtime/near-evm-runner/src/near_ext.rs index 2c6dc2bd308..5a92d7797e3 100644 --- a/runtime/near-evm-runner/src/near_ext.rs +++ b/runtime/near-evm-runner/src/near_ext.rs @@ -185,7 +185,7 @@ impl<'a> vm::Ext for NearExt<'a> { // Is not used. return Err(TrapKind::Call(ActionParams::default())); } - CallType::Call => iPrelnterpreter::call( + CallType::Call => interpreter::call( self.sub_state, &self.origin, sender_address, From 901e34160a0307789a55f1841d59123e2bd5a4d0 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Wed, 30 Sep 2020 11:54:52 -0700 Subject: [PATCH 38/61] fix errors in semantic conflicts happens in merge --- runtime/near-evm-runner/src/interpreter.rs | 26 ++++++++++--------- .../src/vm_estimator.rs | 3 +++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index 203ff7fa823..d503dfa87a7 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -55,11 +55,12 @@ pub fn deploy_code( // Apply NeedsReturn changes if apply_state // Return the result unmodified let (return_data, apply, gas_left) = match result { - Some(GasLeft::Known(left)) => (ReturnData::empty(), true, left), - Some(GasLeft::NeedsReturn { gas_left: left, data, apply_state }) => { + Ok(Ok(GasLeft::Known(left))) => (ReturnData::empty(), true, left), + Ok(Ok(GasLeft::NeedsReturn { gas_left: left, data, apply_state })) => { (data, apply_state, left) } - None => return Err(VMLogicError::EvmError(EvmError::Reverted)), + Ok(Err(err)) => return Err(convert_vm_error(err)), + Err(_) => return Err(VMLogicError::EvmError(EvmError::Reverted)), }; if apply { @@ -81,7 +82,7 @@ pub fn _create( code: &[u8], gas: &U256, evm_gas_config: &EvmCostConfig, -) -> Result<(Option, Option)> { +) -> Result<(ExecTrapResult, Option)> { let mut store = StateStore::default(); let mut sub_state = SubState::new(sender, &mut store, state); @@ -117,7 +118,7 @@ pub fn _create( // Run the code let result = instance.exec(&mut ext); - Ok((result.ok().unwrap().ok(), Some(store))) + Ok((result, Some(store))) } #[allow(clippy::too_many_arguments)] @@ -242,18 +243,20 @@ fn run_and_commit_if_success( // Return the result unmodified let mut should_apply_state = true; let return_data = match result { - Some(GasLeft::Known(gas_left)) => { + Ok(Ok(GasLeft::Known(gas_left))) => { Ok(MessageCallResult::Success(gas_left, ReturnData::empty())) } - Some(GasLeft::NeedsReturn { gas_left, data, apply_state: true }) => { + Ok(Ok(GasLeft::NeedsReturn { gas_left, data, apply_state: true })) => { Ok(MessageCallResult::Success(gas_left, data)) } - Some(GasLeft::NeedsReturn { gas_left, data, apply_state: false }) => { + Ok(Ok(GasLeft::NeedsReturn { gas_left, data, apply_state: false })) => { should_apply_state = false; Ok(MessageCallResult::Reverted(gas_left, data)) } - _ => return Err(VMLogicError::EvmError(EvmError::UnknownError)), + Ok(Err(err)) => Err(convert_vm_error(err)), + Err(_) => Err(VMLogicError::EvmError(EvmError::Reverted)), }; + // Don't apply changes from a static context (these _should_ error in the ext) if !is_static && return_data.is_ok() && should_apply_state && should_commit { state.commit_changes(&state_updates.unwrap())?; @@ -276,7 +279,7 @@ fn run_against_state( is_static: bool, gas: &U256, evm_gas_config: &EvmCostConfig, -) -> Result<(Option, Option)> { +) -> Result<(ExecTrapResult, Option)> { let code = state.code_at(code_address)?.unwrap_or_else(Vec::new); // Check that if there are arguments this is contract call. @@ -325,6 +328,5 @@ fn run_against_state( // Run the code let result = instance.exec(&mut ext); - let r = result.ok(); - Ok((r.unwrap().ok(), Some(store))) + Ok((result, Some(store))) } diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 24b06dc6217..ff32df9eb87 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -302,6 +302,8 @@ lazy_static_include_str!( "../near-evm-runner/tests/build/PrecompiledFunction.bin" ); +const CHAIN_ID: u128 = 0x99; + pub fn create_evm_context<'a>( external: &'a mut MockedExternal, vm_config: &'a VMConfig, @@ -311,6 +313,7 @@ pub fn create_evm_context<'a>( ) -> EvmContext<'a> { EvmContext::new( external, + CHAIN_ID, vm_config, fees_config, 1000, From f8ebf3cf2c4ccb32c4219efdcffbde7dc302a049 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 5 Oct 2020 14:18:15 -0700 Subject: [PATCH 39/61] delete --- runtime/near-evm-runner/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 3222c0c7627..12b47dcb0c6 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -53,8 +53,6 @@ enum KeyPrefix { Contract = 1, } -pub const PREPAID_EVM_GAS: u128 = 1_000_000_000; - fn address_to_key(prefix: KeyPrefix, address: &H160) -> Vec { let mut result = Vec::with_capacity(21); result.push(prefix as u8); From 79fea3c16baa1bf4e3417ee47dc528217965db27 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 5 Oct 2020 14:20:51 -0700 Subject: [PATCH 40/61] nit --- runtime/near-evm-runner/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 12b47dcb0c6..28b567b57dc 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -182,7 +182,7 @@ impl<'a> EvmContext<'a> { pub fn deploy_code(&mut self, bytecode: Vec) -> Result
{ let sender = utils::near_account_id_to_evm_address(&self.predecessor_id); self.add_balance(&sender, U256::from(self.attached_deposit))?; - let r = interpreter::deploy_code( + match interpreter::deploy_code( self, &sender, &sender, @@ -193,8 +193,7 @@ impl<'a> EvmContext<'a> { &bytecode, &self.evm_gas_counter.gas_left(), &self.fees_config.evm_config, - )?; - match r { + )? { ContractCreateResult::Created(address, gas_left) => { self.evm_gas_counter.set_gas_left(gas_left); Ok(address) From 4c6721e9d25c022707f80147c44804ac300dd8ba Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 5 Oct 2020 14:21:25 -0700 Subject: [PATCH 41/61] nit --- runtime/near-evm-runner/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 28b567b57dc..69117a9c9e8 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -220,7 +220,7 @@ impl<'a> EvmContext<'a> { self.add_balance(&sender, U256::from(self.attached_deposit))?; let value = if self.attached_deposit == 0 { None } else { Some(U256::from(self.attached_deposit)) }; - let rd = interpreter::call( + let result = interpreter::call( self, &sender, &sender, @@ -232,7 +232,7 @@ impl<'a> EvmContext<'a> { &self.evm_gas_counter.gas_left(), &self.fees_config.evm_config, )?; - match rd { + match result { MessageCallResult::Success(gas_left, data) => { self.evm_gas_counter.set_gas_left(gas_left); Ok(data.to_vec()) @@ -274,7 +274,7 @@ impl<'a> EvmContext<'a> { self.add_balance(&sender, U256::from(self.attached_deposit))?; let value = if self.attached_deposit == 0 { None } else { Some(U256::from(self.attached_deposit)) }; - let rd = interpreter::call( + let result = interpreter::call( self, &sender, &sender, @@ -286,7 +286,7 @@ impl<'a> EvmContext<'a> { &self.evm_gas_counter.gas_left(), &self.fees_config.evm_config, )?; - match rd { + match result { MessageCallResult::Success(gas_left, data) => { self.evm_gas_counter.set_gas_left(gas_left); Ok(data.to_vec()) @@ -310,7 +310,7 @@ impl<'a> EvmContext<'a> { let sender = Address::from(&args.sender); let attached_amount = U256::from(args.amount); self.add_balance(&sender, attached_amount)?; - let rd = interpreter::call( + let result = interpreter::call( self, &sender, &sender, @@ -322,7 +322,7 @@ impl<'a> EvmContext<'a> { &self.evm_gas_counter.gas_left(), &self.fees_config.evm_config, )?; - let result = match rd { + let result = match result { MessageCallResult::Success(gas_left, data) => { self.evm_gas_counter.set_gas_left(gas_left); Ok(data.to_vec()) From 759e89fd7cd3aea4af56af75ff687038f5465232 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 5 Oct 2020 14:27:16 -0700 Subject: [PATCH 42/61] nit --- runtime/runtime-params-estimator/src/cases.rs | 10 +++++----- .../runtime-params-estimator/src/vm_estimator.rs | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index 3e0fd400827..0f450ba253f 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -180,23 +180,23 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon println!("EVM precompiled function evm gas:"); println!( "ecrecover: {}", - near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.ecRecoverCost) + near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.ec_recover_cost) ); println!( "sha256: {}", - near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.sha256Cost) + near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.sha256_cost) ); println!( "ripemd160: {}", - near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.ripemd160Cost) + near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.ripemd160_cost) ); println!( "identity: {}", - near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.identityCost) + near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.identity_cost) ); println!( "modexp: {}", - near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.modexpImplCost) + near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.modexp_impl_cost) ); process::exit(0); diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index ff32df9eb87..e9f696c1a0a 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -240,11 +240,11 @@ const USING_LIGHTBEAM: bool = false; type Coef = (Ratio, Ratio); pub struct EvmPrecompiledFunctionCost { - pub ecRecoverCost: Ratio, - pub sha256Cost: Ratio, - pub ripemd160Cost: Ratio, - pub identityCost: Ratio, - pub modexpImplCost: Ratio, + pub ec_recover_cost: Ratio, + pub sha256_cost: Ratio, + pub ripemd160_cost: Ratio, + pub identity_cost: Ratio, + pub modexp_impl_cost: Ratio, // pub bn128AddImplCost: Ratio, // pub bn128MulImplCost: Ratio, // pub bn128PairingImplCost: Ratio, @@ -580,10 +580,10 @@ pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiled ]; EvmPrecompiledFunctionCost { - ecRecoverCost: measurements[1].cost - measurements[0].cost, - sha256Cost: measurements[2].cost - measurements[0].cost, + ec_recover_cost: measurements[1].cost - measurements[0].cost, + sha256_cost: measurements[2].cost - measurements[0].cost, ripemd160Cost: measurements[3].cost - measurements[0].cost, - identityCost: measurements[4].cost - measurements[0].cost, + identity_cost: measurements[4].cost - measurements[0].cost, modexpImplCost: measurements[5].cost - measurements[0].cost, } } From 329754caee5060987aab270448906be53f395645 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 5 Oct 2020 14:28:27 -0700 Subject: [PATCH 43/61] nit --- runtime/runtime/src/actions.rs | 1 - runtime/runtime/src/lib.rs | 4 ---- 2 files changed, 5 deletions(-) diff --git a/runtime/runtime/src/actions.rs b/runtime/runtime/src/actions.rs index df979967140..720d755554a 100644 --- a/runtime/runtime/src/actions.rs +++ b/runtime/runtime/src/actions.rs @@ -148,7 +148,6 @@ pub(crate) fn action_function_call( is_last_action: bool, epoch_info_provider: &dyn EpochInfoProvider, ) -> Result<(), RuntimeError> { - // println!("aaaaaaaa"); if account.amount.checked_add(function_call.deposit).is_none() { return Err(StorageError::StorageInconsistentState( "Account balance integer overflow during function call deposit".to_string(), diff --git a/runtime/runtime/src/lib.rs b/runtime/runtime/src/lib.rs index 5fcf96ec295..409bca2300c 100644 --- a/runtime/runtime/src/lib.rs +++ b/runtime/runtime/src/lib.rs @@ -246,7 +246,6 @@ impl Runtime { apply_state.current_protocol_version, ) { Ok(verification_result) => { - // println!("=== a"); near_metrics::inc_counter(&metrics::TRANSACTION_PROCESSED_SUCCESSFULLY_TOTAL); state_update.commit(StateChangeCause::TransactionProcessing { tx_hash: signed_transaction.get_hash(), @@ -286,7 +285,6 @@ impl Runtime { Ok((receipt, outcome)) } Err(e) => { - println!("=== b"); near_metrics::inc_counter(&metrics::TRANSACTION_PROCESSED_FAILED_TOTAL); state_update.rollback(); return Err(e); @@ -469,7 +467,6 @@ impl Runtime { stats: &mut ApplyStats, epoch_info_provider: &dyn EpochInfoProvider, ) -> Result { - // println!("=== apply_action_receipt"); let action_receipt = match receipt.receipt { ReceiptEnum::Action(ref action_receipt) => action_receipt, @@ -817,7 +814,6 @@ impl Runtime { stats: &mut ApplyStats, epoch_info_provider: &dyn EpochInfoProvider, ) -> Result, RuntimeError> { - // println!("=== process_receipt"); let account_id = &receipt.receiver_id; match receipt.receipt { ReceiptEnum::Data(ref data_receipt) => { From 8d39d07d2b8825fe69a02714cefe419bd1291f59 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 6 Oct 2020 23:11:47 -0700 Subject: [PATCH 44/61] refactor use test-utils.testlib to get evm contract addr --- Cargo.lock | 3 + runtime/near-evm-runner/src/lib.rs | 9 --- .../tests/build/zombieAttack.bin | 1 - runtime/runtime-params-estimator/Cargo.toml | 3 + .../runtime-params-estimator/src/testbed.rs | 10 ++- .../src/vm_estimator.rs | 73 ++++++++++--------- runtime/runtime/src/lib.rs | 2 +- test-utils/state-viewer/src/lib.rs | 2 + 8 files changed, 55 insertions(+), 48 deletions(-) delete mode 100644 runtime/near-evm-runner/tests/build/zombieAttack.bin create mode 100644 test-utils/state-viewer/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index e9915c08a0c..94440669ab0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4420,6 +4420,7 @@ dependencies = [ "hex", "indicatif 0.15.0", "lazy-static-include", + "near-chain-configs", "near-crypto", "near-evm-runner", "near-primitives", @@ -4434,7 +4435,9 @@ dependencies = [ "rand_xorshift 0.2.0", "rocksdb", "serde_json", + "state-viewer", "tempfile", + "testlib", "walrus", ] diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 69117a9c9e8..85d823ea660 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -535,15 +535,6 @@ fn max_evm_gas_from_near_gas( } } -#[cfg(feature = "costs_counting")] -pub fn evm_last_deployed_addr() -> H160 { - let mut ret = Default::default(); - EVM_LAST_DEPLOYED.with(|addr| { - ret = addr.borrow().clone(); - }); - ret -} - pub fn run_evm( ext: &mut dyn External, chain_id: u128, diff --git a/runtime/near-evm-runner/tests/build/zombieAttack.bin b/runtime/near-evm-runner/tests/build/zombieAttack.bin deleted file mode 100644 index 3e21cb25c22..00000000000 --- a/runtime/near-evm-runner/tests/build/zombieAttack.bin +++ /dev/null @@ -1 +0,0 @@ -60606040526010600155600154600a0a6002556201518060035566038d7ea4c6800060085560006009556046600a55336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506119d28061007d6000396000f3006060604052600436106100d0576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630ce90ec2146100d557806317a7f4cc146100ed5780632052465e146101195780633ccfd60b1461021d5780634412e10414610232578063528b7b8f146102c05780635f4623f1146103235780635faf28801461035c5780637bff0a01146103885780638da5cb5b146103e5578063c39cbef11461043a578063ccf670f814610471578063e1fa763814610494578063f2fde38b146104c0575b600080fd5b6100eb60048080359060200190919050506104f9565b005b34156100f857600080fd5b6101176004808035906020019091908035906020019091905050610565565b005b341561012457600080fd5b61013a60048080359060200190919050506106d2565b60405180806020018781526020018663ffffffff1663ffffffff1681526020018563ffffffff1663ffffffff1681526020018461ffff1661ffff1681526020018361ffff1661ffff1681526020018281038252888181546001816001161561010002031660029004815260200191508054600181600116156101000203166002900480156102095780601f106101de57610100808354040283529160200191610209565b820191906000526020600020905b8154815290600101906020018083116101ec57829003601f168201915b505097505050505050505060405180910390f35b341561022857600080fd5b610230610758565b005b341561023d57600080fd5b610269600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061082d565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156102ac578082015181840152602081019050610291565b505050509050019250505060405180910390f35b34156102cb57600080fd5b6102e1600480803590602001909190505061095b565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561032e57600080fd5b61035a600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061098e565b005b341561036757600080fd5b6103866004808035906020019091908035906020019091905050610a2d565b005b341561039357600080fd5b6103e3600480803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610b0f565b005b34156103f057600080fd5b6103f8610b88565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561044557600080fd5b61046f60048080359060200190919080359060200190820180359060200191909192905050610bad565b005b341561047c57600080fd5b6104926004808035906020019091905050610c9b565b005b341561049f57600080fd5b6104be6004808035906020019091908035906020019091905050610d00565b005b34156104cb57600080fd5b6104f7600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610f93565b005b6008543414151561050957600080fd5b60048181548110151561051857fe5b9060005260206000209060030201600201600081819054906101000a900463ffffffff168092919060010191906101000a81548163ffffffff021916908363ffffffff1602179055505050565b6000600760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663e98b7f4d83600060405161014001526040518263ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004018082815260200191505061014060405180830381600087803b151561060257600080fd5b6102c65a03f1151561061357600080fd5b50505060405180519060200180519060200180519060200180519060200180519060200180519060200180519060200180519060200180519060200180519050909192939495969798509091929394959697509091929394959650909192939495509091929394509091929350909192509091509050809150506106cd83826040805190810160405280600581526020017f6b697474790000000000000000000000000000000000000000000000000000008152506110e8565b505050565b6004818154811015156106e157fe5b906000526020600020906003020160009150905080600001908060010154908060020160009054906101000a900463ffffffff16908060020160049054906101000a900463ffffffff16908060020160089054906101000a900461ffff169080600201600a9054906101000a900461ffff16905086565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156107b357600080fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc3073ffffffffffffffffffffffffffffffffffffffff16319081150290604051600060405180830381858888f19350505050151561082b57600080fd5b565b610835611764565b61083d611764565b600080600660008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205460405180591061088d5750595b9080825280602002602001820160405250925060009150600090505b600480549050811015610950578473ffffffffffffffffffffffffffffffffffffffff166005600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614156109435780838381518110151561092c57fe5b906020019060200201818152505081806001019250505b80806001019150506108a9565b829350505050919050565b60056020528060005260406000206000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156109e957600080fd5b80600760006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60148281600482815481101515610a4057fe5b906000526020600020906003020160020160009054906101000a900463ffffffff1663ffffffff1610151515610a7557600080fd5b836005600082815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610ae357600080fd5b83600486815481101515610af357fe5b9060005260206000209060030201600101819055505050505050565b600080600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054141515610b5e57600080fd5b610b67826112bd565b9050606481811515610b7557fe5b0681039050610b84828261133f565b5050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60028381600482815481101515610bc057fe5b906000526020600020906003020160020160009054906101000a900463ffffffff1663ffffffff1610151515610bf557600080fd5b846005600082815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610c6357600080fd5b8484600488815481101515610c7457fe5b90600052602060002090600302016000019190610c92929190611778565b50505050505050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610cf657600080fd5b8060088190555050565b6000806000846005600082815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610d7357600080fd5b600486815481101515610d8257fe5b90600052602060002090600302019350600485815481101515610da157fe5b90600052602060002090600302019250610dbb606461160e565b9150600a5482111515610ef157610df260018560020160089054906101000a900461ffff1661ffff166116a590919063ffffffff16565b8460020160086101000a81548161ffff021916908361ffff160217905550610e3e60018560020160009054906101000a900463ffffffff1663ffffffff166116cb90919063ffffffff16565b8460020160006101000a81548163ffffffff021916908363ffffffff160217905550610e8a600184600201600a9054906101000a900461ffff1661ffff166116a590919063ffffffff16565b83600201600a6101000a81548161ffff021916908361ffff160217905550610eec8684600101546040805190810160405280600681526020017f7a6f6d62696500000000000000000000000000000000000000000000000000008152506110e8565b610f8b565b610f1b600185600201600a9054906101000a900461ffff1661ffff166116a590919063ffffffff16565b84600201600a6101000a81548161ffff021916908361ffff160217905550610f6360018460020160089054906101000a900461ffff1661ffff166116a590919063ffffffff16565b8360020160086101000a81548161ffff021916908361ffff160217905550610f8a846116f5565b5b505050505050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141515610fee57600080fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415151561102a57600080fd5b8073ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600080846005600082815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561115957600080fd5b60048681548110151561116857fe5b906000526020600020906003020192506111818361171f565b151561118c57600080fd5b6002548581151561119957fe5b0694506002858460010154018115156111ae57fe5b04915060405180807f6b697474790000000000000000000000000000000000000000000000000000008152506005019050604051809103902060001916846040518082805190602001908083835b60208310151561122157805182526020820191506020810190506020830392506111fc565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051809103902060001916141561126d57606360648381151561126657fe5b0683030191505b6112ac6040805190810160405280600681526020017f4e6f4e616d6500000000000000000000000000000000000000000000000000008152508361133f565b6112b5836116f5565b505050505050565b600080826040518082805190602001908083835b6020831015156112f657805182526020820191506020810190506020830392506112d1565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405180910390206001900490506002548181151561133657fe5b06915050919050565b600060016004805480600101828161135791906117f8565b9160005260206000209060030201600060c060405190810160405280888152602001878152602001600163ffffffff168152602001600354420163ffffffff168152602001600061ffff168152602001600061ffff16815250909190915060008201518160000190805190602001906113d192919061182a565b506020820151816001015560408201518160020160006101000a81548163ffffffff021916908363ffffffff16021790555060608201518160020160046101000a81548163ffffffff021916908363ffffffff16021790555060808201518160020160086101000a81548161ffff021916908361ffff16021790555060a082015181600201600a6101000a81548161ffff021916908361ffff1602179055505050039050336005600083815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061151a6001600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205461174690919063ffffffff16565b600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055507f88f026aacbbecc90c18411df4b1185fd8d9be2470f1962f192bf84a27d0704b78184846040518084815260200180602001838152602001828103825284818151815260200191508051906020019080838360005b838110156115cd5780820151818401526020810190506115b2565b50505050905090810190601f1680156115fa5780820380516001836020036101000a031916815260200191505b5094505050505060405180910390a1505050565b6000611626600160095461174690919063ffffffff16565b600981905550814233600954604051808481526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166c01000000000000000000000000028152601401828152602001935050505060405180910390206001900481151561169d57fe5b069050919050565b60008082840190508361ffff168161ffff16101515156116c157fe5b8091505092915050565b60008082840190508363ffffffff168163ffffffff16101515156116eb57fe5b8091505092915050565b60035442018160020160046101000a81548163ffffffff021916908363ffffffff16021790555050565b6000428260020160049054906101000a900463ffffffff1663ffffffff1611159050919050565b600080828401905083811015151561175a57fe5b8091505092915050565b602060405190810160405280600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106117b957803560ff19168380011785556117e7565b828001600101855582156117e7579182015b828111156117e65782358255916020019190600101906117cb565b5b5090506117f491906118aa565b5090565b8154818355818115116118255760030281600302836000526020600020918201910161182491906118cf565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061186b57805160ff1916838001178555611899565b82800160010185558215611899579182015b8281111561189857825182559160200191906001019061187d565b5b5090506118a691906118aa565b5090565b6118cc91905b808211156118c85760008160009055506001016118b0565b5090565b90565b61195b91905b8082111561195757600080820160006118ee919061195e565b60018201600090556002820160006101000a81549063ffffffff02191690556002820160046101000a81549063ffffffff02191690556002820160086101000a81549061ffff021916905560028201600a6101000a81549061ffff0219169055506003016118d5565b5090565b90565b50805460018160011615610100020316600290046000825580601f1061198457506119a3565b601f0160209004906000526020600020908101906119a291906118aa565b5b505600a165627a7a72305820132b51da42f560f7184ac5aae47f26c9658881610ed4c49b0c5c00f7456864e60029 \ No newline at end of file diff --git a/runtime/runtime-params-estimator/Cargo.toml b/runtime/runtime-params-estimator/Cargo.toml index f248ee76e2a..a6b1f80d287 100644 --- a/runtime/runtime-params-estimator/Cargo.toml +++ b/runtime/runtime-params-estimator/Cargo.toml @@ -24,6 +24,9 @@ near-vm-runner = {path = "../../runtime/near-vm-runner" , features = ["costs_cou node-runtime = { path = "../../runtime/runtime" , features = ["costs_counting", "no_cache"]} near-store = { path = "../../core/store", features = ["no_cache", "single_thread_rocksdb"]} near-primitives = { path = "../../core/primitives" } +testlib = { path = "../../test-utils/testlib" } +state-viewer = { path = "../../test-utils/state-viewer" } +near-chain-configs = { path = "../../core/chain-configs" } neard = { path = "../../neard" } rocksdb = { git = "https://github.com/nearprotocol/rust-rocksdb", branch="disable-thread" } glob = "0.3.0" diff --git a/runtime/runtime-params-estimator/src/testbed.rs b/runtime/runtime-params-estimator/src/testbed.rs index d66198666a7..00deadbcf7d 100644 --- a/runtime/runtime-params-estimator/src/testbed.rs +++ b/runtime/runtime-params-estimator/src/testbed.rs @@ -4,6 +4,7 @@ use std::path::Path; use borsh::BorshDeserialize; +use near_chain_configs::Genesis; use near_primitives::receipt::Receipt; use near_primitives::test_utils::MockEpochInfoProvider; use near_primitives::transaction::{ExecutionStatus, SignedTransaction}; @@ -22,9 +23,10 @@ pub struct RuntimeTestbed { /// Directory where we temporarily keep the storage. #[allow(dead_code)] workdir: tempfile::TempDir, - tries: ShardTries, - root: MerkleHash, - runtime: Runtime, + pub tries: ShardTries, + pub root: MerkleHash, + pub runtime: Runtime, + pub genesis: Genesis, prev_receipts: Vec, apply_state: ApplyState, epoch_info_provider: MockEpochInfoProvider, @@ -38,6 +40,7 @@ impl RuntimeTestbed { let store = create_store(&get_store_path(workdir.path())); let tries = ShardTries::new(store.clone(), 1); + let genesis = Genesis::from_file(dump_dir.join("genesis.json")); let mut state_file = dump_dir.to_path_buf(); state_file.push(STATE_DUMP_FILE); store.load_from_file(ColState, state_file.as_path()).expect("Failed to read state dump"); @@ -96,6 +99,7 @@ impl RuntimeTestbed { prev_receipts, apply_state, epoch_info_provider: MockEpochInfoProvider::default(), + genesis, } } diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index e9f696c1a0a..84a8fdff06b 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -11,7 +11,7 @@ use glob::glob; use lazy_static_include::lazy_static_include_str; use near_crypto::{InMemorySigner, KeyType}; use near_evm_runner::utils::encode_call_function_args; -use near_evm_runner::{evm_last_deployed_addr, EvmContext}; +use near_evm_runner::EvmContext; use near_primitives::hash::CryptoHash; use near_primitives::transaction::{Action, FunctionCallAction, SignedTransaction}; use near_primitives::version::PROTOCOL_VERSION; @@ -26,11 +26,13 @@ use std::collections::hash_map::DefaultHasher; use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; use std::fs; -use std::sync::Mutex; +use std::sync::{Arc, Mutex, RwLock}; use std::{ hash::{Hash, Hasher}, path::PathBuf, }; +use testlib::node::{Node, RuntimeNode}; +use testlib::user::runtime_user::MockClient; use walrus::{Module, Result}; const CURRENT_ACCOUNT_ID: &str = "alice"; @@ -334,10 +336,7 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { config, verbose, |sol_test_addr| { - encode_call_function_args( - sol_test_addr, - soltest::functions::deploy_new_guy::call(8).0, - ) + vec![sol_test_addr, soltest::functions::deploy_new_guy::call(8).0].concat() }, "deploy_new_guy(8)", ), @@ -345,7 +344,7 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { config, verbose, |sol_test_addr| { - encode_call_function_args(sol_test_addr, soltest::functions::pay_new_guy::call(8).0) + vec![sol_test_addr, soltest::functions::pay_new_guy::call(8).0].concat() }, "pay_new_guy(8)", ), @@ -353,19 +352,14 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { config, verbose, |sol_test_addr| { - encode_call_function_args( - sol_test_addr, - soltest::functions::return_some_funds::call().0, - ) + vec![sol_test_addr, soltest::functions::return_some_funds::call().0].concat() }, "return_some_funds()", ), measure_evm_function( config, verbose, - |sol_test_addr| { - encode_call_function_args(sol_test_addr, soltest::functions::emit_it::call(8).0) - }, + |sol_test_addr| vec![sol_test_addr, soltest::functions::emit_it::call(8).0].concat(), "emit_it(8)", ), ]; @@ -410,7 +404,7 @@ pub fn measure_evm_precompile_function( EvmCost { evm_gas, cost } } -pub fn measure_evm_function Vec + Copy>( +pub fn measure_evm_function) -> Vec + Copy>( config: &Config, verbose: bool, args_encoder: F, @@ -436,25 +430,36 @@ pub fn measure_evm_function Vec + Copy>( let account_id = get_account_id(account_idx); let signer = InMemorySigner::from_seed(&account_id, KeyType::ED25519, &account_id); + let mut testbed = testbed.lock().unwrap(); + let runtime_node = RuntimeNode { + signer: Arc::new(signer.clone()), + client: Arc::new(RwLock::new(MockClient { + runtime: testbed.runtime.clone(), + tries: testbed.tries.clone(), + state_root: testbed.root, + epoch_length: testbed.genesis.config.epoch_length, + })), + genesis: testbed.genesis.clone(), + }; + let node_user = runtime_node.user(); let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); - testbed.lock().unwrap().process_block( - &vec![SignedTransaction::from_actions( - nonce as u64, + let addr = node_user + .function_call( account_id.clone(), - "evm".to_owned(), - &signer, - vec![Action::FunctionCall(FunctionCallAction { - method_name: "deploy_code".to_string(), - args: code.clone(), - gas: 10u64.pow(18), - deposit: 0, - })], - CryptoHash::default(), - )], - false, - ); - testbed.lock().unwrap().process_blocks_until_no_receipts(allow_failures); - let addr = evm_last_deployed_addr(); + "evm".to_string(), + "deploy_code", + code.clone(), + 10u64.pow(14), + 10, + ) + .unwrap() + .status + .as_success_decoded() + .unwrap(); + + testbed.tries = runtime_node.client.read().unwrap().tries.clone(); + testbed.root = runtime_node.client.read().unwrap().state_root; + testbed.runtime = runtime_node.client.read().unwrap().runtime.clone(); let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); SignedTransaction::from_actions( @@ -582,9 +587,9 @@ pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiled EvmPrecompiledFunctionCost { ec_recover_cost: measurements[1].cost - measurements[0].cost, sha256_cost: measurements[2].cost - measurements[0].cost, - ripemd160Cost: measurements[3].cost - measurements[0].cost, + ripemd160_cost: measurements[3].cost - measurements[0].cost, identity_cost: measurements[4].cost - measurements[0].cost, - modexpImplCost: measurements[5].cost - measurements[0].cost, + modexp_impl_cost: measurements[5].cost - measurements[0].cost, } } diff --git a/runtime/runtime/src/lib.rs b/runtime/runtime/src/lib.rs index 409bca2300c..726700cd659 100644 --- a/runtime/runtime/src/lib.rs +++ b/runtime/runtime/src/lib.rs @@ -197,6 +197,7 @@ impl Default for ActionResult { } } +#[derive(Clone)] pub struct Runtime { pub config: RuntimeConfig, } @@ -467,7 +468,6 @@ impl Runtime { stats: &mut ApplyStats, epoch_info_provider: &dyn EpochInfoProvider, ) -> Result { - let action_receipt = match receipt.receipt { ReceiptEnum::Action(ref action_receipt) => action_receipt, _ => unreachable!("given receipt should be an action receipt"), diff --git a/test-utils/state-viewer/src/lib.rs b/test-utils/state-viewer/src/lib.rs new file mode 100644 index 00000000000..c54d8b02d76 --- /dev/null +++ b/test-utils/state-viewer/src/lib.rs @@ -0,0 +1,2 @@ +mod state_dump; +pub use crate::state_dump::state_dump; From 1896a50973f6abe7a6698a40e01247bc5afbcbb4 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Thu, 8 Oct 2020 19:16:47 -0700 Subject: [PATCH 45/61] evm deploy cost based on both evm gas and contract size --- Cargo.lock | 130 ++++++++++++++++++ runtime/runtime-params-estimator/Cargo.toml | 3 + runtime/runtime-params-estimator/src/cases.rs | 16 ++- .../src/vm_estimator.rs | 48 +++++-- 4 files changed, 181 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 94440669ab0..1dd0500b1c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -343,6 +343,15 @@ version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f" +[[package]] +name = "approx" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0e60b75072ecd4168020818c0107f2857bb6c4e64252d8d3983f6263b40a5c3" +dependencies = [ + "num-traits", +] + [[package]] name = "arc-swap" version = "0.4.6" @@ -567,6 +576,18 @@ dependencies = [ "digest 0.8.1", ] +[[package]] +name = "blas-src" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7b894d1cc14af76750a80f64387f7986fe93a9d3786a9a8926a340ae50b2c51" + +[[package]] +name = "blas-src" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a25f136d1bcc6fc28330077511a0646aaf75bc894e5532b1a33a93d814272328" + [[package]] name = "block-buffer" version = "0.7.3" @@ -760,6 +781,27 @@ dependencies = [ "cc", ] +[[package]] +name = "cauchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c505375a294ec7cf79430c4ccb91ee1fab5f6390da3a264932fd303832a2de7" +dependencies = [ + "num-complex", + "num-traits", + "rand 0.5.6", + "serde", +] + +[[package]] +name = "cblas-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6feecd82cce51b0204cf063f0041d69f24ce83f680d87514b004248e7b0fa65" +dependencies = [ + "libc", +] + [[package]] name = "cc" version = "1.0.52" @@ -2352,6 +2394,32 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" +[[package]] +name = "lapack-src" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92b348b4b770b1092add976188242941b92272f3bad95cfbacadbfcb0c8923eb" + +[[package]] +name = "lapacke" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bce9d3464fe3be72376bcbe3dc4df22dd368ca228b62e8415d2c7b09bb58677" +dependencies = [ + "lapacke-sys", + "libc", + "num-complex", +] + +[[package]] +name = "lapacke-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f7d0817c6f4a6029f3b153de01d6498dcf9df659a7536c58bd8df5cd3ccaa6e" +dependencies = [ + "libc", +] + [[package]] name = "lazy-static-include" version = "2.3.0" @@ -2556,6 +2624,15 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +[[package]] +name = "matrixmultiply" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4f7ec66360130972f34830bfad9ef05c6610a43938a467bcc9ab9369ab3478f" +dependencies = [ + "rawpointer", +] + [[package]] name = "maybe-uninit" version = "2.0.0" @@ -2709,6 +2786,38 @@ dependencies = [ "tempfile", ] +[[package]] +name = "ndarray" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac06db03ec2f46ee0ecdca1a1c34a99c0d188a0d83439b84bf0cb4b386e4ab09" +dependencies = [ + "approx", + "blas-src 0.2.1", + "cblas-sys", + "matrixmultiply", + "num-complex", + "num-integer", + "num-traits", + "rawpointer", +] + +[[package]] +name = "ndarray-linalg" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6892e51e159690d3d3d9fe2b052ff80b638c7d0f7ce634818c84ab7aea09e01c" +dependencies = [ + "blas-src 0.6.1", + "cauchy", + "lapack-src", + "lapacke", + "ndarray", + "num-complex", + "num-traits", + "rand 0.5.6", +] + [[package]] name = "near-actix-utils" version = "0.1.0" @@ -3423,6 +3532,18 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-complex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" +dependencies = [ + "autocfg 1.0.0", + "num-traits", + "rand 0.5.6", + "serde", +] + [[package]] name = "num-integer" version = "0.1.42" @@ -4178,6 +4299,12 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" + [[package]] name = "rayon" version = "1.3.0" @@ -4420,6 +4547,8 @@ dependencies = [ "hex", "indicatif 0.15.0", "lazy-static-include", + "ndarray", + "ndarray-linalg", "near-chain-configs", "near-crypto", "near-evm-runner", @@ -4431,6 +4560,7 @@ dependencies = [ "neard", "node-runtime", "num-rational 0.3.0", + "num-traits", "rand 0.7.3", "rand_xorshift 0.2.0", "rocksdb", diff --git a/runtime/runtime-params-estimator/Cargo.toml b/runtime/runtime-params-estimator/Cargo.toml index a6b1f80d287..d9093267034 100644 --- a/runtime/runtime-params-estimator/Cargo.toml +++ b/runtime/runtime-params-estimator/Cargo.toml @@ -38,6 +38,9 @@ ethabi-contract = "8.0.0" ethabi-derive = "8.0.0" ethereum-types = "0.6.0" lazy-static-include = "2.2.2" +ndarray = "0.13.1" +ndarray-linalg = "0.12.1" +num-traits = "0.2.12" [features] default = [] diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index 0f450ba253f..5ff64d366c4 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -1,4 +1,5 @@ use num_rational::Ratio; +use num_traits::cast::FromPrimitive; use rand::seq::SliceRandom; use rand::{Rng, SeedableRng}; use std::cell::RefCell; @@ -21,7 +22,8 @@ use crate::testbed::RuntimeTestbed; use crate::testbed_runners::GasMetric; use crate::testbed_runners::{get_account_id, measure_actions, measure_transactions, Config}; use crate::vm_estimator::{ - action_receipt_fee, cost_of_evm, cost_per_op, cost_to_compile, near_cost_to_evm_gas, load_and_compile + action_receipt_fee, cost_of_evm, cost_per_op, cost_to_compile, load_and_compile, + near_cost_to_evm_gas, }; use near_runtime_fees::{ AccessKeyCreationConfig, ActionCreationConfig, DataReceiptCreationConfig, Fee, @@ -168,9 +170,10 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon config.block_sizes = vec![100]; let cost = cost_of_evm(&config, true); println!( - "EVM base deploy (and init evm instance) cost: {}, deploy cost per EVM gas: {}", - ratio_to_gas(config.metric, cost.deploy_cost.1) - action_receipt_fee(), - ratio_to_gas(config.metric, cost.deploy_cost.0), + "EVM base deploy (and init evm instance) cost: {}, deploy cost per EVM gas: {}, deploy cost per byte: {}", + ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.2).unwrap()) - action_receipt_fee(), + ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.0).unwrap()), + ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.1).unwrap()), ); println!( "EVM base function call cost: {}, function call cost per EVM gas: {}", @@ -196,7 +199,10 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon ); println!( "modexp: {}", - near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.modexp_impl_cost) + near_cost_to_evm_gas( + cost.funcall_cost, + cost.precompiled_function_cost.modexp_impl_cost + ) ); process::exit(0); diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 84a8fdff06b..3a48ad40a1e 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -9,6 +9,9 @@ use ethabi_contract::use_contract; use ethereum_types::H160; use glob::glob; use lazy_static_include::lazy_static_include_str; +use ndarray::prelude::*; +use ndarray::Array; +use ndarray_linalg::{LeastSquaresSvd, LeastSquaresSvdInPlace, LeastSquaresSvdInto}; use near_crypto::{InMemorySigner, KeyType}; use near_evm_runner::utils::encode_call_function_args; use near_evm_runner::EvmContext; @@ -21,6 +24,7 @@ use near_vm_logic::mocks::mock_external::MockedExternal; use near_vm_logic::{VMConfig, VMContext, VMKind, VMOutcome}; use near_vm_runner::{compile_module, prepare, VMError}; use num_rational::Ratio; +use num_traits::cast::ToPrimitive; use rand::Rng; use std::collections::hash_map::DefaultHasher; use std::collections::{HashMap, HashSet}; @@ -157,6 +161,7 @@ pub fn load_and_compile( #[derive(Debug)] pub struct EvmCost { pub evm_gas: u64, + pub size: u64, pub cost: Ratio, } @@ -224,7 +229,8 @@ fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { evm_gas /= counts; // evm_gas is times gas spent, so does cost - Some(EvmCost { evm_gas, cost: Ratio::new(total_cost, counts) }) + // Some(EvmCost { evm_gas, cost: Ratio::new(total_cost, counts) }) + Some(EvmCost { evm_gas, size: code.len() as u64, cost: Ratio::new(total_cost, counts) }) } fn load_and_deploy_evm_contract(path: &PathBuf, config: &Config) -> Option { @@ -241,6 +247,8 @@ const USING_LIGHTBEAM: bool = false; type Coef = (Ratio, Ratio); +type Coef2D = (f64, f64, f64); + pub struct EvmPrecompiledFunctionCost { pub ec_recover_cost: Ratio, pub sha256_cost: Ratio, @@ -255,12 +263,12 @@ pub struct EvmPrecompiledFunctionCost { } pub struct EvmCostCoef { - pub deploy_cost: Coef, + pub deploy_cost: Coef2D, pub funcall_cost: Coef, pub precompiled_function_cost: EvmPrecompiledFunctionCost, } -pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef { +pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef2D { let globbed_files = glob("./**/*.bin").expect("Failed to read glob pattern for bin files"); let paths = globbed_files .filter_map(|x| match x { @@ -277,11 +285,13 @@ pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef { print!("Testing {}: ", path.display()); }; // Evm counted gas already count on size of the contract, therefore we look for cost = m*evm_gas + b. - if let Some(EvmCost { evm_gas, cost }) = load_and_deploy_evm_contract(path, config) { + if let Some(EvmCost { evm_gas, size, cost }) = + load_and_deploy_evm_contract(path, config) + { if verbose { - println!("({}, {})", evm_gas, cost); + println!("({}, {}, {}),", evm_gas, size, cost); }; - Some(EvmCost { evm_gas, cost }) + Some(EvmCost { evm_gas, size, cost }) } else { if verbose { println!("FAILED") @@ -292,7 +302,7 @@ pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef { .filter(|x| x.is_some()) .map(|x| x.unwrap()) .collect::>(); - measurements_to_coef(measurements, true) + measurements_to_coef_2d(measurements, true) } use_contract!(soltest, "../near-evm-runner/tests/build/SolTests.abi"); @@ -401,7 +411,7 @@ pub fn measure_evm_precompile_function( if verbose { println!("Testing call {}: ({}, {})", test_name, evm_gas, cost); } - EvmCost { evm_gas, cost } + EvmCost { size: 0, evm_gas, cost } } pub fn measure_evm_function) -> Vec + Copy>( @@ -508,7 +518,7 @@ pub fn measure_evm_function) -> Vec + Copy>( if verbose { println!("Testing call {}: ({}, {})", test_name, evm_gas, cost); } - EvmCost { evm_gas, cost } + EvmCost { evm_gas, size: 0, cost } } pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiledFunctionCost { @@ -667,13 +677,29 @@ pub fn cost_to_compile( (m, b) } +fn measurements_to_coef_2d(measurements: Vec, verbose: bool) -> Coef2D { + let mut a = Array::::zeros((measurements.len(), 2).f()); + let mut b = Array::::zeros((measurements.len(), 1).f()); + for (i, m) in measurements.iter().enumerate() { + a[[i, 0]] = m.evm_gas as f64; + a[[i, 1]] = m.size as f64; + b[[i]] = m.cost.to_f64().unwrap(); + } + let result = a.least_squares(&b).unwrap(); + // println!("{:?}", result.solution); + + let delta: Array = &b - a.dot(&result.solution); + let n = delta.len(); + (result.solution[[0]], result.solution[[1]], delta.sum() / n) +} + fn measurements_to_coef(measurements: Vec, verbose: bool) -> Coef { let ratio = Ratio::new(0 as u64, 1); let base = Ratio::new(u64::MAX, 1); - let b = measurements.iter().fold(base, |b, EvmCost { evm_gas: _, cost }| b.min(*cost)); + let b = measurements.iter().fold(base, |b, EvmCost { evm_gas: _, size: _, cost }| b.min(*cost)); let m = measurements .iter() - .fold(ratio, |r, EvmCost { evm_gas, cost }| r.max((*cost - b) / evm_gas)); + .fold(ratio, |r, EvmCost { evm_gas, size: _, cost }| r.max((*cost - b) / evm_gas)); if verbose { println!("raw data: ({},{})", m, b); } From 0423b636d7dfd9919e2989f3006a248b6a8738a1 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 13 Oct 2020 10:30:13 -0700 Subject: [PATCH 46/61] lsq compiles --- Cargo.lock | 12 ++++++++++++ runtime/runtime-params-estimator/Cargo.toml | 2 +- runtime/runtime-params-estimator/src/vm_estimator.rs | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1dd0500b1c0..dbf90cdc58c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -587,6 +587,9 @@ name = "blas-src" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a25f136d1bcc6fc28330077511a0646aaf75bc894e5532b1a33a93d814272328" +dependencies = [ + "openblas-src", +] [[package]] name = "block-buffer" @@ -2399,6 +2402,9 @@ name = "lapack-src" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92b348b4b770b1092add976188242941b92272f3bad95cfbacadbfcb0c8923eb" +dependencies = [ + "openblas-src", +] [[package]] name = "lapacke" @@ -3622,6 +3628,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "openblas-src" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84629d1d4f9f40d3f9e4756dae33c6af50d3c2fcc186558dac65bf55141ade6b" + [[package]] name = "openssl" version = "0.10.29" diff --git a/runtime/runtime-params-estimator/Cargo.toml b/runtime/runtime-params-estimator/Cargo.toml index d9093267034..a72759d388a 100644 --- a/runtime/runtime-params-estimator/Cargo.toml +++ b/runtime/runtime-params-estimator/Cargo.toml @@ -39,7 +39,7 @@ ethabi-derive = "8.0.0" ethereum-types = "0.6.0" lazy-static-include = "2.2.2" ndarray = "0.13.1" -ndarray-linalg = "0.12.1" +ndarray-linalg = { version = "0.12.1", features = ["openblas"] } num-traits = "0.2.12" [features] diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 3a48ad40a1e..55c68dd0207 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -683,7 +683,7 @@ fn measurements_to_coef_2d(measurements: Vec, verbose: bool) -> Coef2D for (i, m) in measurements.iter().enumerate() { a[[i, 0]] = m.evm_gas as f64; a[[i, 1]] = m.size as f64; - b[[i]] = m.cost.to_f64().unwrap(); + b[[i, 0]] = m.cost.to_f64().unwrap(); } let result = a.least_squares(&b).unwrap(); // println!("{:?}", result.solution); From 3ac79ac8a69f0a0f697ae9b4f59a23de6eb951ea Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 13 Oct 2020 12:00:45 -0700 Subject: [PATCH 47/61] lsq compiles --- .../src/vm_estimator.rs | 58 +++++++++++++++---- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 55c68dd0207..86e52705a98 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -677,20 +677,54 @@ pub fn cost_to_compile( (m, b) } -fn measurements_to_coef_2d(measurements: Vec, verbose: bool) -> Coef2D { - let mut a = Array::::zeros((measurements.len(), 2).f()); - let mut b = Array::::zeros((measurements.len(), 1).f()); - for (i, m) in measurements.iter().enumerate() { - a[[i, 0]] = m.evm_gas as f64; - a[[i, 1]] = m.size as f64; - b[[i, 0]] = m.cost.to_f64().unwrap(); +fn dot(v1: &Vec, v2: &Vec) -> f64 { + let mut ret = 0.0; + for (i, u) in v1.iter().enumerate() { + ret += u * v2[i]; } - let result = a.least_squares(&b).unwrap(); - // println!("{:?}", result.solution); + ret +} + +struct Matrix2x2 { + a: f64, + b: f64, + c: f64, + d: f64, +} + +fn inverse2x2(m: Matrix2x2) -> Matrix2x2 { + let Matrix2x2 { a, b, c, d } = m; + let delta = a * d - b * c; + Matrix2x2 { a: d / delta, b: -b / delta, c: -c / delta, d: a / delta } +} - let delta: Array = &b - a.dot(&result.solution); - let n = delta.len(); - (result.solution[[0]], result.solution[[1]], delta.sum() / n) +fn measurements_to_coef_2d(measurements: Vec, verbose: bool) -> Coef2D { + let v1: Vec<_> = measurements.iter().map(|m| m.evm_gas as f64).collect(); + let v2: Vec<_> = measurements.iter().map(|m| m.size as f64).collect(); + let a = dot(&v1, &v1); + let b = dot(&v1, &v2); + let c = dot(&v2, &v1); + let d = dot(&v2, &v2); + + let xt_x_inverse = inverse2x2(Matrix2x2 { a, b, c, d }); + let xt_x_inverse_xt1: Vec<_> = measurements + .iter() + .map(|m| (m.evm_gas as f64) * xt_x_inverse.a + (m.size as f64) * xt_x_inverse.b) + .collect(); + let xt_x_inverse_xt2: Vec<_> = measurements + .iter() + .map(|m| (m.evm_gas as f64) * xt_x_inverse.c + (m.size as f64) * xt_x_inverse.d) + .collect(); + + let y: Vec<_> = measurements.iter().map(|m| m.cost.to_f64().unwrap()).collect(); + let beta1 = dot(&xt_x_inverse_xt1, &y); + let beta2 = dot(&xt_x_inverse_xt2, &y); + + let delta: Vec<_> = measurements + .iter() + .map(|m| m.cost.to_f64().unwrap() - (m.evm_gas as f64) * beta1 - (m.size as f64) * beta2) + .collect(); + (beta1, beta2, delta.iter().sum::() / delta.len() as f64) } fn measurements_to_coef(measurements: Vec, verbose: bool) -> Coef { From 940904f8cb3e3b155753a55f101ae6d49ed02a97 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 13 Oct 2020 22:46:28 -0700 Subject: [PATCH 48/61] my rust impl of 2d lsq, end result stable but lsq is incorrect --- runtime/runtime-params-estimator/src/cases.rs | 5 +++-- runtime/runtime-params-estimator/src/vm_estimator.rs | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index 5ff64d366c4..0b9df6d93f8 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -170,8 +170,9 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon config.block_sizes = vec![100]; let cost = cost_of_evm(&config, true); println!( - "EVM base deploy (and init evm instance) cost: {}, deploy cost per EVM gas: {}, deploy cost per byte: {}", - ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.2).unwrap()) - action_receipt_fee(), + "EVM base deploy (and init evm instance) cost: {}, action receipt fee: {}, deploy cost per EVM gas: {}, deploy cost per byte: {}", + ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.2).unwrap()), + action_receipt_fee(), ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.0).unwrap()), ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.1).unwrap()), ); diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 86e52705a98..4bd7ba51252 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -724,7 +724,9 @@ fn measurements_to_coef_2d(measurements: Vec, verbose: bool) -> Coef2D .iter() .map(|m| m.cost.to_f64().unwrap() - (m.evm_gas as f64) * beta1 - (m.size as f64) * beta2) .collect(); - (beta1, beta2, delta.iter().sum::() / delta.len() as f64) + let r = (beta1, beta2, delta.iter().sum::() / delta.len() as f64); + println!("evm calc data {:?}", r); + r } fn measurements_to_coef(measurements: Vec, verbose: bool) -> Coef { From 6e151d4f41c983c233f1ce242a27bd2e7dd5a6be Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Wed, 14 Oct 2020 09:43:43 -0700 Subject: [PATCH 49/61] simplify --- .../src/vm_estimator.rs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 4bd7ba51252..0c3618ca21f 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -707,18 +707,21 @@ fn measurements_to_coef_2d(measurements: Vec, verbose: bool) -> Coef2D let d = dot(&v2, &v2); let xt_x_inverse = inverse2x2(Matrix2x2 { a, b, c, d }); - let xt_x_inverse_xt1: Vec<_> = measurements - .iter() - .map(|m| (m.evm_gas as f64) * xt_x_inverse.a + (m.size as f64) * xt_x_inverse.b) - .collect(); - let xt_x_inverse_xt2: Vec<_> = measurements - .iter() - .map(|m| (m.evm_gas as f64) * xt_x_inverse.c + (m.size as f64) * xt_x_inverse.d) - .collect(); + // let xt_x_inverse_xt1: Vec<_> = measurements + // .iter() + // .map(|m| (m.evm_gas as f64) * xt_x_inverse.a + (m.size as f64) * xt_x_inverse.b) + // .collect(); + // let xt_x_inverse_xt2: Vec<_> = measurements + // .iter() + // .map(|m| (m.evm_gas as f64) * xt_x_inverse.c + (m.size as f64) * xt_x_inverse.d) + // .collect(); let y: Vec<_> = measurements.iter().map(|m| m.cost.to_f64().unwrap()).collect(); - let beta1 = dot(&xt_x_inverse_xt1, &y); - let beta2 = dot(&xt_x_inverse_xt2, &y); + let xt_y1 = dot(&v1, &y); + let xt_y2 = dot(&v2, &y); + + let beta1 = xt_x_inverse.a*xt_y1 + xt_x_inverse.b*xt_y2; + let beta2 = xt_x_inverse.c*xt_y1 + xt_x_inverse.d*xt_y2; let delta: Vec<_> = measurements .iter() @@ -726,6 +729,7 @@ fn measurements_to_coef_2d(measurements: Vec, verbose: bool) -> Coef2D .collect(); let r = (beta1, beta2, delta.iter().sum::() / delta.len() as f64); println!("evm calc data {:?}", r); + println!("delta: {:?}", delta); r } From 36b06024f63bff48ecaed101f11efc66737eec54 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Wed, 14 Oct 2020 14:35:42 -0700 Subject: [PATCH 50/61] accurate evm deploy base cost, per evm gas and per byte --- runtime/runtime-params-estimator/src/cases.rs | 5 ++--- .../src/vm_estimator.rs | 22 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index 0b9df6d93f8..5ff64d366c4 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -170,9 +170,8 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon config.block_sizes = vec![100]; let cost = cost_of_evm(&config, true); println!( - "EVM base deploy (and init evm instance) cost: {}, action receipt fee: {}, deploy cost per EVM gas: {}, deploy cost per byte: {}", - ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.2).unwrap()), - action_receipt_fee(), + "EVM base deploy (and init evm instance) cost: {}, deploy cost per EVM gas: {}, deploy cost per byte: {}", + ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.2).unwrap()) - action_receipt_fee(), ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.0).unwrap()), ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.1).unwrap()), ); diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 0c3618ca21f..eb04bb54584 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -698,30 +698,32 @@ fn inverse2x2(m: Matrix2x2) -> Matrix2x2 { Matrix2x2 { a: d / delta, b: -b / delta, c: -c / delta, d: a / delta } } +fn normalize(v: &Vec) -> (Vec, f64) { + let mean = v.iter().sum::() / (v.len() as f64); + // default sklearn LinearRegression only normalize mean to 0, but not normalize stddev to 1, and that gives a very good result. + + let v: Vec<_> = v.iter().map(|x| (*x - mean)).collect(); + (v, mean) +} + fn measurements_to_coef_2d(measurements: Vec, verbose: bool) -> Coef2D { let v1: Vec<_> = measurements.iter().map(|m| m.evm_gas as f64).collect(); + let (v1, _) = normalize(&v1); let v2: Vec<_> = measurements.iter().map(|m| m.size as f64).collect(); + let (v2, _) = normalize(&v2); let a = dot(&v1, &v1); let b = dot(&v1, &v2); let c = dot(&v2, &v1); let d = dot(&v2, &v2); let xt_x_inverse = inverse2x2(Matrix2x2 { a, b, c, d }); - // let xt_x_inverse_xt1: Vec<_> = measurements - // .iter() - // .map(|m| (m.evm_gas as f64) * xt_x_inverse.a + (m.size as f64) * xt_x_inverse.b) - // .collect(); - // let xt_x_inverse_xt2: Vec<_> = measurements - // .iter() - // .map(|m| (m.evm_gas as f64) * xt_x_inverse.c + (m.size as f64) * xt_x_inverse.d) - // .collect(); let y: Vec<_> = measurements.iter().map(|m| m.cost.to_f64().unwrap()).collect(); let xt_y1 = dot(&v1, &y); let xt_y2 = dot(&v2, &y); - let beta1 = xt_x_inverse.a*xt_y1 + xt_x_inverse.b*xt_y2; - let beta2 = xt_x_inverse.c*xt_y1 + xt_x_inverse.d*xt_y2; + let beta1 = (xt_x_inverse.a*xt_y1 + xt_x_inverse.b*xt_y2); + let beta2 = (xt_x_inverse.c*xt_y1 + xt_x_inverse.d*xt_y2); let delta: Vec<_> = measurements .iter() From 681bd9a08692cbf069cebb1dc15daefc813b8d96 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Thu, 15 Oct 2020 21:41:33 -0700 Subject: [PATCH 51/61] fix deploy evm contract to all accounts nonce issue --- .../tests/contracts/SolTests.sol | 16 ++- .../src/vm_estimator.rs | 106 +++++++++++++++--- 2 files changed, 105 insertions(+), 17 deletions(-) diff --git a/runtime/near-evm-runner/tests/contracts/SolTests.sol b/runtime/near-evm-runner/tests/contracts/SolTests.sol index 686aaf2d815..1d885bd20b8 100644 --- a/runtime/near-evm-runner/tests/contracts/SolTests.sol +++ b/runtime/near-evm-runner/tests/contracts/SolTests.sol @@ -83,13 +83,17 @@ contract PrecompiledFunction { constructor() public payable {} function noop() public pure { - + } function testSha256() public pure returns (bytes32) { return sha256(""); } + function testSha256_100bytes() public pure returns (bytes32) { + return sha256("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw"); + } + function testEcrecover() public pure returns (address) { return ecrecover( hex"1111111111111111111111111111111111111111111111111111111111111111", @@ -103,6 +107,10 @@ contract PrecompiledFunction { return ripemd160(""); } + function testRipemd160_100bytes() public pure returns (bytes20) { + return ripemd160("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw"); + } + function identity(bytes memory data) public returns (bytes memory) { bytes memory ret = new bytes(data.length); assembly { @@ -116,7 +124,11 @@ contract PrecompiledFunction { } function test_identity() public returns (bytes memory) { - return identity("0"); + return identity(""); + } + + function test_identity_100bytes() public returns (bytes memory) { + return identity("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw"); } function modexp(uint base, uint e, uint m) public view returns (uint o) { diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index eb04bb54584..8b782f9577d 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -8,6 +8,7 @@ use crate::testbed_runners::GasMetric; use ethabi_contract::use_contract; use ethereum_types::H160; use glob::glob; +use indicatif::{ProgressBar, ProgressStyle}; use lazy_static_include::lazy_static_include_str; use ndarray::prelude::*; use ndarray::Array; @@ -26,6 +27,7 @@ use near_vm_runner::{compile_module, prepare, VMError}; use num_rational::Ratio; use num_traits::cast::ToPrimitive; use rand::Rng; +use rocksdb::Env; use std::collections::hash_map::DefaultHasher; use std::collections::{HashMap, HashSet}; use std::convert::TryFrom; @@ -33,6 +35,7 @@ use std::fs; use std::sync::{Arc, Mutex, RwLock}; use std::{ hash::{Hash, Hasher}, + path::Path, path::PathBuf, }; use testlib::node::{Node, RuntimeNode}; @@ -165,12 +168,60 @@ pub struct EvmCost { pub cost: Ratio, } -fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { +fn testbed_for_evm( + state_dump_path: &str, + accounts: usize, +) -> (Arc>, Arc>>) { + let path = PathBuf::from(state_dump_path); + let testbed = Arc::new(Mutex::new(RuntimeTestbed::from_state_dump(&path))); + let mut nonces: HashMap = HashMap::new(); + let bar = ProgressBar::new(accounts as _); + println!("Prepare a testbed of {} accounts all having a deployed evm contract", accounts); + bar.set_style(ProgressStyle::default_bar().template( + "[elapsed {elapsed_precise} remaining {eta_precise}] Evm contracts {bar} {pos:>7}/{len:7} {msg}", + )); + let mut env = Env::default().unwrap(); + env.set_background_threads(4); + for account_idx in 0..accounts { + let account_id = get_account_id(account_idx); + let signer = InMemorySigner::from_seed(&account_id, KeyType::ED25519, &account_id); + let code = hex::decode(&TEST).unwrap(); + let nonce = *nonces.entry(account_idx).and_modify(|x| *x += 1).or_insert(1); + + let block: Vec<_> = vec![SignedTransaction::from_actions( + nonce as u64, + account_id.clone(), + "evm".to_owned(), + &signer, + vec![Action::FunctionCall(FunctionCallAction { + method_name: "deploy_code".to_string(), + args: code, + gas: 10u64.pow(18), + deposit: 0, + })], + CryptoHash::default(), + )]; + let mut testbed = testbed.lock().unwrap(); + testbed.process_block(&block, false); + testbed.process_blocks_until_no_receipts(false); + bar.inc(1); + } + bar.finish(); + reset_evm_gas_counter(); + env.set_background_threads(0); + (testbed, Arc::new(Mutex::new(nonces))) +} + +fn deploy_evm_contract( + code: &[u8], + config: &Config, + testbed: Arc>, + nonces: Arc>>, +) -> Option { let path = PathBuf::from(config.state_dump_path.as_str()); println!("{:?}. Preparing testbed. Loading state.", config.metric); - let testbed = Mutex::new(RuntimeTestbed::from_state_dump(&path)); let allow_failures = false; - let mut nonces: HashMap = HashMap::new(); + let mut nonces = nonces.lock().unwrap(); let mut accounts_deployed = HashSet::new(); let mut f = || { @@ -233,9 +284,14 @@ fn deploy_evm_contract(code: &[u8], config: &Config) -> Option { Some(EvmCost { evm_gas, size: code.len() as u64, cost: Ratio::new(total_cost, counts) }) } -fn load_and_deploy_evm_contract(path: &PathBuf, config: &Config) -> Option { +fn load_and_deploy_evm_contract( + path: &PathBuf, + config: &Config, + testbed: Arc>, + nonces: Arc>>, +) -> Option { match fs::read(path) { - Ok(code) => deploy_evm_contract(&code, config), + Ok(code) => deploy_evm_contract(&code, config, testbed, nonces), _ => None, } } @@ -268,7 +324,12 @@ pub struct EvmCostCoef { pub precompiled_function_cost: EvmPrecompiledFunctionCost, } -pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef2D { +pub fn measure_evm_deploy( + config: &Config, + verbose: bool, + testbed: Arc>, + nonces: Arc>>, +) -> Coef2D { let globbed_files = glob("./**/*.bin").expect("Failed to read glob pattern for bin files"); let paths = globbed_files .filter_map(|x| match x { @@ -286,7 +347,7 @@ pub fn measure_evm_deploy(config: &Config, verbose: bool) -> Coef2D { }; // Evm counted gas already count on size of the contract, therefore we look for cost = m*evm_gas + b. if let Some(EvmCost { evm_gas, size, cost }) = - load_and_deploy_evm_contract(path, config) + load_and_deploy_evm_contract(path, config, testbed.clone(), nonces.clone()) { if verbose { println!("({}, {}, {}),", evm_gas, size, cost); @@ -340,7 +401,12 @@ pub fn create_evm_context<'a>( ) } -pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { +pub fn measure_evm_funcall( + config: &Config, + verbose: bool, + testbed: Arc>, + nonces: Arc>>, +) -> Coef { let measurements = vec![ measure_evm_function( config, @@ -349,6 +415,8 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { vec![sol_test_addr, soltest::functions::deploy_new_guy::call(8).0].concat() }, "deploy_new_guy(8)", + testbed.clone(), + nonces.clone(), ), measure_evm_function( config, @@ -357,6 +425,8 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { vec![sol_test_addr, soltest::functions::pay_new_guy::call(8).0].concat() }, "pay_new_guy(8)", + testbed.clone(), + nonces.clone(), ), measure_evm_function( config, @@ -365,12 +435,16 @@ pub fn measure_evm_funcall(config: &Config, verbose: bool) -> Coef { vec![sol_test_addr, soltest::functions::return_some_funds::call().0].concat() }, "return_some_funds()", + testbed.clone(), + nonces.clone(), ), measure_evm_function( config, verbose, |sol_test_addr| vec![sol_test_addr, soltest::functions::emit_it::call(8).0].concat(), "emit_it(8)", + testbed.clone(), + nonces.clone(), ), ]; println!("{:?}", measurements); @@ -419,12 +493,13 @@ pub fn measure_evm_function) -> Vec + Copy>( verbose: bool, args_encoder: F, test_name: &str, + testbed: Arc>, + nonces: Arc>>, ) -> EvmCost { let path = PathBuf::from(config.state_dump_path.as_str()); println!("{:?}. Preparing testbed. Loading state.", config.metric); - let testbed = Mutex::new(RuntimeTestbed::from_state_dump(&path)); let allow_failures = false; - let mut nonces: HashMap = HashMap::new(); + let mut nonces = nonces.lock().unwrap(); let mut accounts_deployed = HashSet::new(); let code = hex::decode(&TEST).unwrap(); @@ -609,9 +684,10 @@ pub fn near_cost_to_evm_gas(funcall_cost: Coef, cost: Ratio) -> u64 { /// Cost of all evm related pub fn cost_of_evm(config: &Config, verbose: bool) -> EvmCostCoef { + let (testbed, nonces) = testbed_for_evm(&config.state_dump_path, config.active_accounts); let evm_cost_config = EvmCostCoef { - deploy_cost: measure_evm_deploy(config, verbose), - funcall_cost: measure_evm_funcall(config, verbose), + deploy_cost: measure_evm_deploy(config, verbose, testbed.clone(), nonces.clone()), + funcall_cost: measure_evm_funcall(config, verbose, testbed.clone(), nonces.clone()), precompiled_function_cost: measure_evm_precompiled(config, verbose), }; evm_cost_config @@ -710,7 +786,7 @@ fn measurements_to_coef_2d(measurements: Vec, verbose: bool) -> Coef2D let v1: Vec<_> = measurements.iter().map(|m| m.evm_gas as f64).collect(); let (v1, _) = normalize(&v1); let v2: Vec<_> = measurements.iter().map(|m| m.size as f64).collect(); - let (v2, _) = normalize(&v2); + let (v2, _) = normalize(&v2); let a = dot(&v1, &v1); let b = dot(&v1, &v2); let c = dot(&v2, &v1); @@ -722,8 +798,8 @@ fn measurements_to_coef_2d(measurements: Vec, verbose: bool) -> Coef2D let xt_y1 = dot(&v1, &y); let xt_y2 = dot(&v2, &y); - let beta1 = (xt_x_inverse.a*xt_y1 + xt_x_inverse.b*xt_y2); - let beta2 = (xt_x_inverse.c*xt_y1 + xt_x_inverse.d*xt_y2); + let beta1 = (xt_x_inverse.a * xt_y1 + xt_x_inverse.b * xt_y2); + let beta2 = (xt_x_inverse.c * xt_y1 + xt_x_inverse.d * xt_y2); let delta: Vec<_> = measurements .iter() From 6139e99cea8f766489605369f601ca246164419b Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Thu, 15 Oct 2020 21:41:53 -0700 Subject: [PATCH 52/61] balancer contract binary suite --- .../near-evm-runner/tests/build/BBronze.abi | 17 + .../near-evm-runner/tests/build/BBronze.bin | 1 + .../near-evm-runner/tests/build/BColor.abi | 17 + .../near-evm-runner/tests/build/BConst.abi | 257 +++ .../near-evm-runner/tests/build/BConst.bin | 1 + .../near-evm-runner/tests/build/BFactory.abi | 142 ++ .../near-evm-runner/tests/build/BFactory.bin | 1 + runtime/near-evm-runner/tests/build/BMath.abi | 574 ++++++ runtime/near-evm-runner/tests/build/BMath.bin | 1 + runtime/near-evm-runner/tests/build/BNum.abi | 257 +++ runtime/near-evm-runner/tests/build/BNum.bin | 1 + runtime/near-evm-runner/tests/build/BPool.abi | 1630 +++++++++++++++++ runtime/near-evm-runner/tests/build/BPool.bin | 1 + .../near-evm-runner/tests/build/BToken.abi | 549 ++++++ .../near-evm-runner/tests/build/BToken.bin | 1 + .../tests/build/BTokenBase.abi | 307 ++++ .../tests/build/BTokenBase.bin | 1 + .../near-evm-runner/tests/build/IERC20.abi | 197 ++ .../tests/build/Migrations.abi | 68 + .../tests/build/Migrations.bin | 1 + .../tests/build/TBPoolJoinExit.abi | 302 +++ .../tests/build/TBPoolJoinExit.bin | 1 + .../tests/build/TBPoolJoinExitNoFee.abi | 302 +++ .../tests/build/TBPoolJoinExitNoFee.bin | 1 + .../tests/build/TBPoolJoinPool.abi | 303 +++ .../tests/build/TBPoolJoinPool.bin | 1 + runtime/near-evm-runner/tests/build/TMath.abi | 834 +++++++++ runtime/near-evm-runner/tests/build/TMath.bin | 1 + .../near-evm-runner/tests/build/TToken.abi | 311 ++++ .../tests/build/zombieAttack.bin | 1 + 30 files changed, 6081 insertions(+) create mode 100644 runtime/near-evm-runner/tests/build/BBronze.abi create mode 100644 runtime/near-evm-runner/tests/build/BBronze.bin create mode 100644 runtime/near-evm-runner/tests/build/BColor.abi create mode 100644 runtime/near-evm-runner/tests/build/BConst.abi create mode 100644 runtime/near-evm-runner/tests/build/BConst.bin create mode 100644 runtime/near-evm-runner/tests/build/BFactory.abi create mode 100644 runtime/near-evm-runner/tests/build/BFactory.bin create mode 100644 runtime/near-evm-runner/tests/build/BMath.abi create mode 100644 runtime/near-evm-runner/tests/build/BMath.bin create mode 100644 runtime/near-evm-runner/tests/build/BNum.abi create mode 100644 runtime/near-evm-runner/tests/build/BNum.bin create mode 100644 runtime/near-evm-runner/tests/build/BPool.abi create mode 100644 runtime/near-evm-runner/tests/build/BPool.bin create mode 100644 runtime/near-evm-runner/tests/build/BToken.abi create mode 100644 runtime/near-evm-runner/tests/build/BToken.bin create mode 100644 runtime/near-evm-runner/tests/build/BTokenBase.abi create mode 100644 runtime/near-evm-runner/tests/build/BTokenBase.bin create mode 100644 runtime/near-evm-runner/tests/build/IERC20.abi create mode 100644 runtime/near-evm-runner/tests/build/Migrations.abi create mode 100644 runtime/near-evm-runner/tests/build/Migrations.bin create mode 100644 runtime/near-evm-runner/tests/build/TBPoolJoinExit.abi create mode 100644 runtime/near-evm-runner/tests/build/TBPoolJoinExit.bin create mode 100644 runtime/near-evm-runner/tests/build/TBPoolJoinExitNoFee.abi create mode 100644 runtime/near-evm-runner/tests/build/TBPoolJoinExitNoFee.bin create mode 100644 runtime/near-evm-runner/tests/build/TBPoolJoinPool.abi create mode 100644 runtime/near-evm-runner/tests/build/TBPoolJoinPool.bin create mode 100644 runtime/near-evm-runner/tests/build/TMath.abi create mode 100644 runtime/near-evm-runner/tests/build/TMath.bin create mode 100644 runtime/near-evm-runner/tests/build/TToken.abi create mode 100644 runtime/near-evm-runner/tests/build/zombieAttack.bin diff --git a/runtime/near-evm-runner/tests/build/BBronze.abi b/runtime/near-evm-runner/tests/build/BBronze.abi new file mode 100644 index 00000000000..ff6c870a05c --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BBronze.abi @@ -0,0 +1,17 @@ +[ + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/BBronze.bin b/runtime/near-evm-runner/tests/build/BBronze.bin new file mode 100644 index 00000000000..9bbf2865e61 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BBronze.bin @@ -0,0 +1 @@ +6080604052348015600f57600080fd5b5060ba8061001e6000396000f3fe6080604052348015600f57600080fd5b50600436106044577c010000000000000000000000000000000000000000000000000000000060003504639a86139b81146049575b600080fd5b604f6061565b60408051918252519081900360200190f35b7f42524f4e5a4500000000000000000000000000000000000000000000000000009056fea265627a7a72315820d02b5140da771a0eb87c9231627fadfdca36c5c04f502cc3fe1163438b04bda664736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/BColor.abi b/runtime/near-evm-runner/tests/build/BColor.abi new file mode 100644 index 00000000000..ff6c870a05c --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BColor.abi @@ -0,0 +1,17 @@ +[ + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/BConst.abi b/runtime/near-evm-runner/tests/build/BConst.abi new file mode 100644 index 00000000000..42a7386d836 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BConst.abi @@ -0,0 +1,257 @@ +[ + { + "constant": true, + "inputs": [], + "name": "BONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "BPOW_PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "EXIT_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "INIT_POOL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_IN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_OUT_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_TOTAL_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BALANCE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/BConst.bin b/runtime/near-evm-runner/tests/build/BConst.bin new file mode 100644 index 00000000000..df5ec05428b --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BConst.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b5061029c806100206000396000f3fe608060405234801561001057600080fd5b5060043610610108576000357c010000000000000000000000000000000000000000000000000000000090048063b0e0d136116100af578063b0e0d1361461015f578063b7b800a414610167578063ba019dab1461016f578063bc063e1a14610177578063bc694ea21461017f578063c36596a61461012f578063c6580d1214610187578063e4a28a521461010d578063ec0930211461018f57610108565b806309a3bbe41461010d578063189d00ca14610127578063218b53821461012f57806376c7a3c714610137578063867378c51461013f5780639381cd2b14610147578063992e2a921461014f5780639a86139b14610157575b600080fd5b610115610197565b60408051918252519081900360200190f35b6101156101a4565b6101156101b8565b6101156101c4565b6101156101d6565b6101156101ea565b6101156101f7565b610115610203565b610115610227565b61011561022c565b610115610231565b610115610236565b610115610246565b610115610252565b610115610257565b6802b5e3af16b188000081565b6402540be400670de0b6b3a76400005b0481565b670de0b6b3a764000081565b620f4240670de0b6b3a76400006101b4565b64e8d4a51000670de0b6b3a76400006101b4565b68056bc75e2d6310000081565b6704a03ce68d21555681565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b600881565b600281565b600181565b600a670de0b6b3a76400006101b4565b671bc16d674ec7ffff81565b600081565b6002670de0b6b3a76400006101b456fea265627a7a72315820a3ed3e544d5a2480a4ca8e33cf23ff0c96b482b4cef52e564e7ba36b9ce3855064736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/BFactory.abi b/runtime/near-evm-runner/tests/build/BFactory.abi new file mode 100644 index 00000000000..2946beca8ae --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BFactory.abi @@ -0,0 +1,142 @@ +[ + { + "inputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "blabs", + "type": "address" + } + ], + "name": "LOG_BLABS", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "name": "LOG_NEW_POOL", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "b", + "type": "address" + } + ], + "name": "isBPool", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "newBPool", + "outputs": [ + { + "internalType": "contract BPool", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getBLabs", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "b", + "type": "address" + } + ], + "name": "setBLabs", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "contract BPool", + "name": "pool", + "type": "address" + } + ], + "name": "collect", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/BFactory.bin b/runtime/near-evm-runner/tests/build/BFactory.bin new file mode 100644 index 00000000000..c025ffa35ec --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BFactory.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b5060018054600160a060020a03191633179055615fb1806100326000396000f3fe608060405234801561001057600080fd5b506004361061007e577c0100000000000000000000000000000000000000000000000000000000600035046306ec16f8811461008357806336ffb167146100ab5780639a86139b146100cf578063c2bb6dc2146100e9578063c6ce34fb14610123578063d556c5dc14610149575b600080fd5b6100a96004803603602081101561009957600080fd5b5035600160a060020a0316610151565b005b6100b361033e565b60408051600160a060020a039092168252519081900360200190f35b6100d761034d565b60408051918252519081900360200190f35b61010f600480360360208110156100ff57600080fd5b5035600160a060020a0316610371565b604080519115158252519081900360200190f35b6100a96004803603602081101561013957600080fd5b5035600160a060020a031661038f565b6100b3610456565b600154600160a060020a031633146101b3576040805160e560020a62461bcd02815260206004820152600d60248201527f4552525f4e4f545f424c41425300000000000000000000000000000000000000604482015290519081900360640190fd5b604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600091600160a060020a038416916370a0823191602480820192602092909190829003018186803b15801561021657600080fd5b505afa15801561022a573d6000803e3d6000fd5b505050506040513d602081101561024057600080fd5b5051600154604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a0392831660048201526024810184905290519293506000929185169163a9059cbb9160448082019260209290919082900301818787803b1580156102b657600080fd5b505af11580156102ca573d6000803e3d6000fd5b505050506040513d60208110156102e057600080fd5b5051905080610339576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f45524332305f4641494c454400000000000000000000000000000000604482015290519081900360640190fd5b505050565b600154600160a060020a031690565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b600160a060020a031660009081526020819052604090205460ff1690565b600154600160a060020a031633146103f1576040805160e560020a62461bcd02815260206004820152600d60248201527f4552525f4e4f545f424c41425300000000000000000000000000000000000000604482015290519081900360640190fd5b604051600160a060020a0382169033907ff586fa6ee1fc42f5b727f3b214ccbd0b6d7e698c45d49ba32f224fbb8670155d90600090a36001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b6000806040516104659061054f565b604051809103906000f080158015610481573d6000803e3d6000fd5b50600160a060020a038116600081815260208190526040808220805460ff1916600117905551929350909133917f8ccec77b0cb63ac2cafd0f5de8cdfadab91ce656d262240ba8a6343bccc5f94591a3604080517f92eefe9b0000000000000000000000000000000000000000000000000000000081523360048201529051600160a060020a038316916392eefe9b91602480830192600092919082900301818387803b15801561053157600080fd5b505af1158015610545573d6000803e3d6000fd5b5092935050505090565b615a208061055d8339019056fe60c0604052601360808190527f42616c616e63657220506f6f6c20546f6b656e0000000000000000000000000060a0908152620000409160039190620000f7565b506040805180820190915260038082527f425054000000000000000000000000000000000000000000000000000000000060209092019182526200008791600491620000f7565b506005805460ff19166012179055348015620000a257600080fd5b5060068054600580546201000060b060020a031916336201000081029190911790915564e8d4a51000600755600160a060020a03199091161760a060020a60ff02191690556008805460ff191690556200019c565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200013a57805160ff19168380011785556200016a565b828001600101855582156200016a579182015b828111156200016a5782518255916020019190600101906200014d565b50620001789291506200017c565b5090565b6200019991905b8082111562000178576000815560010162000183565b90565b61587480620001ac6000396000f3fe608060405234801561001057600080fd5b5060043610610378576000357c0100000000000000000000000000000000000000000000000000000000900480638d4e4083116101e7578063bc694ea211610122578063d73dd623116100c5578063d73dd62314610b7f578063dd62ed3e14610bab578063e4a28a521461047e578063e4e1e53814610bd9578063ec09302114610c0b578063f1b8a9b714610c13578063f8b2cb4f14610c39578063f8d6aed414610c5f578063fde924f714610c9a57610378565b8063bc694ea214610ad9578063be3bbd2e14610ae1578063c36596a6146104f2578063c6580d1214610b39578063cc77828d14610b41578063cd2ed8fb14610b49578063cf5e7bd314610b51578063d4cadf6814610b7757610378565b8063a221ee491161018a578063a221ee49146109a6578063a9059cbb146109db578063b02f0b7314610a07578063b0e0d13614610a7e578063b7b800a414610a86578063ba019dab14610a8e578063ba9530a614610a96578063bc063e1a14610ad157610378565b80638d4e40831461092a57806392eefe9b14610932578063936c3477146109585780639381cd2b14610960578063948d8ce61461096857806395d89b411461098e578063992e2a92146109965780639a86139b1461099e57610378565b806349b59552116102b757806376c7a3c71161025a57806376c7a3c7146107aa5780637c5e9ea4146107b25780638201aa3f1461080b57806382f652ad1461084b5780638656b65314610886578063867378c5146108c157806389298012146108c95780638c28cbe81461090457610378565b806349b595521461061b5780634bb278f31461063a5780634f69c0d4146106425780635c1bbaf7146106b95780635db34277146106f457806366188463146107265780636d06dfa01461075257806370a082311461078457610378565b8063218b53821161031f578063218b5382146104f257806323b872dd146104fa5780632f37b624146105305780633018205f14610556578063313ce5671461057a57806334e19907146105985780633fdddaa2146105b757806346ab38f1146105e957610378565b806302c967481461037d57806306fdde03146103c1578063095ea7b31461043e57806309a3bbe41461047e5780631446a7ff1461048657806315e84af9146104b457806318160ddd146104e2578063189d00ca146104ea575b600080fd5b6103af6004803603606081101561039357600080fd5b50600160a060020a038135169060208101359060400135610ca2565b60408051918252519081900360200190f35b6103c9610fef565b6040805160208082528351818301528351919283929083019185019080838360005b838110156104035781810151838201526020016103eb565b50505050905090810190601f1680156104305780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61046a6004803603604081101561045457600080fd5b50600160a060020a038135169060200135611085565b604080519115158252519081900360200190f35b6103af6110da565b6103af6004803603604081101561049c57600080fd5b50600160a060020a03813581169160200135166110e7565b6103af600480360360408110156104ca57600080fd5b50600160a060020a0381358116916020013516611241565b6103af611392565b6103af611398565b6103af6113ac565b61046a6004803603606081101561051057600080fd5b50600160a060020a038135811691602081013590911690604001356113b8565b61046a6004803603602081101561054657600080fd5b5035600160a060020a031661151d565b61055e61153b565b60408051600160a060020a039092168252519081900360200190f35b61058261159c565b6040805160ff9092168252519081900360200190f35b6105b5600480360360208110156105ae57600080fd5b50356115a5565b005b6105b5600480360360608110156105cd57600080fd5b50600160a060020a0381351690602081013590604001356117c9565b6103af600480360360608110156105ff57600080fd5b50600160a060020a038135169060208101359060400135611c15565b6105b56004803603602081101561063157600080fd5b50351515611f01565b6105b5612092565b6105b56004803603604081101561065857600080fd5b8135919081019060408101602082013564010000000081111561067a57600080fd5b82018360208201111561068c57600080fd5b803590602001918460208302840111640100000000831117156106ae57600080fd5b5090925090506122a9565b6103af600480360360c08110156106cf57600080fd5b5080359060208101359060408101359060608101359060808101359060a00135612590565b6103af6004803603606081101561070a57600080fd5b50600160a060020a038135169060208101359060400135612648565b61046a6004803603604081101561073c57600080fd5b50600160a060020a038135169060200135612919565b6103af6004803603606081101561076857600080fd5b50600160a060020a0381351690602081013590604001356129f1565b6103af6004803603602081101561079a57600080fd5b5035600160a060020a0316612cf0565b6103af612d0b565b6107f2600480360360a08110156107c857600080fd5b50600160a060020a0381358116916020810135916040820135169060608101359060800135612d1d565b6040805192835260208301919091528051918290030190f35b6107f2600480360360a081101561082157600080fd5b50600160a060020a038135811691602081013591604082013516906060810135906080013561320d565b6103af600480360360c081101561086157600080fd5b5080359060208101359060408101359060608101359060808101359060a001356136e4565b6103af600480360360c081101561089c57600080fd5b5080359060208101359060408101359060608101359060808101359060a001356137a3565b6103af613844565b6103af600480360360c08110156108df57600080fd5b5080359060208101359060408101359060608101359060808101359060a00135613858565b6105b56004803603602081101561091a57600080fd5b5035600160a060020a0316613908565b61046a613ad9565b6105b56004803603602081101561094857600080fd5b5035600160a060020a0316613ae2565b6103af613c2c565b6103af613c84565b6103af6004803603602081101561097e57600080fd5b5035600160a060020a0316613c91565b6103c9613d5f565b6103af613dc0565b6103af613dcc565b6103af600480360360a08110156109bc57600080fd5b5080359060208101359060408101359060608101359060800135613df0565b61046a600480360360408110156109f157600080fd5b50600160a060020a038135169060200135613e55565b6105b560048036036040811015610a1d57600080fd5b81359190810190604081016020820135640100000000811115610a3f57600080fd5b820183602082011115610a5157600080fd5b80359060200191846020830284011164010000000083111715610a7357600080fd5b509092509050613e6b565b6103af61419f565b6103af6141a4565b6103af6141a9565b6103af600480360360c0811015610aac57600080fd5b5080359060208101359060408101359060608101359060808101359060a001356141ae565b6103af61422f565b6103af61423f565b610ae961424b565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015610b25578181015183820152602001610b0d565b505050509050019250505060405180910390f35b6103af614343565b610ae9614348565b6103af614399565b6105b560048036036020811015610b6757600080fd5b5035600160a060020a031661439f565b6103af61472c565b61046a60048036036040811015610b9557600080fd5b50600160a060020a038135169060200135614784565b6103af60048036036040811015610bc157600080fd5b50600160a060020a0381358116916020013516614805565b6105b560048036036060811015610bef57600080fd5b50600160a060020a038135169060208101359060400135614830565b6103af614ab4565b6103af60048036036020811015610c2957600080fd5b5035600160a060020a0316614ac4565b6103af60048036036020811015610c4f57600080fd5b5035600160a060020a0316614ba4565b6103af600480360360c0811015610c7557600080fd5b5080359060208101359060408101359060608101359060808101359060a00135614c72565b61046a614cf5565b600033600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615610d53576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16610daa576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a602052604090205460ff16610e08576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a60205260409020600390810154610e3d91670de0b6b3a76400005b04600101614d05565b831115610e82576040805160e560020a62461bcd02815260206004820152601160248201526000805160206156e0833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a6020526040902060038101546002808301549054600b54600754610ebc949392919089906136e4565b915081610f01576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b82821115610f47576040805160e560020a62461bcd02815260206004820152600c60248201526000805160206156c0833981519152604482015290519081900360640190fd5b610f55816003015485614dee565b60038201556000610f668382614d05565b604080518781529051919250600160a060020a0388169133916000805160206157a0833981519152919081900360200190a3610fa23384614e5f565b610fb4610faf8483614dee565b614e6d565b600554610fd090620100009004600160a060020a031682614e79565b610fdb863387614e83565b50506005805461ff00191690559392505050565b60038054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561107b5780601f106110505761010080835404028352916020019161107b565b820191906000526020600020905b81548152906001019060200180831161105e57829003601f168201915b5050505050905090565b336000818152600160209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390926000805160206157c0833981519152928290030190a35060015b92915050565b6802b5e3af16b188000081565b600554600090610100900460ff1615611138576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090205460ff16611196576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a602052604090205460ff166111f4576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a038084166000908152600a602052604080822092851682528120600380840154600280860154928401549084015493946112389492939290613df0565b95945050505050565b600554600090610100900460ff1615611292576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090205460ff166112f0576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a602052604090205460ff1661134e576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a038084166000908152600a602052604080822092851682529020600380830154600280850154928401549084015460075461123894929190613df0565b60025490565b6402540be400670de0b6b3a76400005b0481565b670de0b6b3a764000081565b600033600160a060020a03851614806113f45750600160a060020a03841660009081526001602090815260408083203384529091529020548211155b611448576040805160e560020a62461bcd02815260206004820152601560248201527f4552525f42544f4b454e5f4241445f43414c4c45520000000000000000000000604482015290519081900360640190fd5b611453848484614f78565b33600160a060020a038516148015906114915750600160a060020a038416600090815260016020908152604080832033845290915290205460001914155b1561151357600160a060020a03841660009081526001602090815260408083203384529091529020546114c49083614dee565b600160a060020a03858116600090815260016020908152604080832033808552908352928190208590558051948552519287169391926000805160206157c08339815191529281900390910190a35b5060019392505050565b600160a060020a03166000908152600a602052604090205460ff1690565b600554600090610100900460ff161561158c576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b50600654600160a060020a031690565b60055460ff1690565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615611654576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16156116ac576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b600654600160a060020a031633146116fc576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b64e8d4a51000811015611759576040805160e560020a62461bcd02815260206004820152600b60248201527f4552525f4d494e5f464545000000000000000000000000000000000000000000604482015290519081900360640190fd5b67016345785d8a00008111156117b9576040805160e560020a62461bcd02815260206004820152600b60248201527f4552525f4d41585f464545000000000000000000000000000000000000000000604482015290519081900360640190fd5b6007556005805461ff0019169055565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615611878576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560065433600160a060020a03909116146118d9576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090205460ff16611937576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b60085460ff1615611980576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b670de0b6b3a76400008110156119e0576040805160e560020a62461bcd02815260206004820152600e60248201527f4552525f4d494e5f574549474854000000000000000000000000000000000000604482015290519081900360640190fd5b6802b5e3af16b1880000811115611a41576040805160e560020a62461bcd02815260206004820152600e60248201527f4552525f4d41585f574549474854000000000000000000000000000000000000604482015290519081900360640190fd5b620f4240821015611a9c576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f4d494e5f42414c414e43450000000000000000000000000000000000604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090206002015480821115611b3f57611ad5600b54611ad08484614dee565b615082565b600b8190556802b5e3af16b18800001015611b3a576040805160e560020a62461bcd02815260206004820152601460248201527f4552525f4d41585f544f54414c5f574549474854000000000000000000000000604482015290519081900360640190fd5b611b60565b80821015611b6057611b5c600b54611b578385614dee565b614dee565b600b555b600160a060020a0384166000908152600a602052604090206002810183905560030180549084905580841115611ba957611ba48533611b9f8785614dee565b6150df565b611c03565b80841015611c03576000611bbd8286614dee565b90506000611bcc826000614d05565b9050611be28733611bdd8585614dee565b614e83565b600554611c00908890620100009004600160a060020a031683614e83565b50505b50506005805461ff0019169055505050565b600033600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615611cc6576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16611d1d576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a602052604090205460ff16611d7b576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a6020526040902060038101546002808301549054600b54600754611db594939291908990613858565b915082821015611dfd576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615800833981519152604482015290519081900360640190fd5b600160a060020a0385166000908152600a60205260409020600390810154611e2d91670de0b6b3a7640000610e34565b821115611e72576040805160e560020a62461bcd02815260206004820152601160248201526000805160206156e0833981519152604482015290519081900360640190fd5b611e80816003015483614dee565b60038201556000611e918582614d05565b604080518581529051919250600160a060020a0388169133916000805160206157a0833981519152919081900360200190a3611ecd3386614e5f565b611eda610faf8683614dee565b600554611ef690620100009004600160a060020a031682614e79565b610fdb863385614e83565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615611fb0576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff1615612008576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b600654600160a060020a03163314612058576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b6006805491151560a060020a0274ff0000000000000000000000000000000000000000199092169190911790556005805461ff0019169055565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615612141576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560065433600160a060020a03909116146121a2576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b60085460ff16156121eb576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b60095460021115612246576040805160e560020a62461bcd02815260206004820152600e60248201527f4552525f4d494e5f544f4b454e53000000000000000000000000000000000000604482015290519081900360640190fd5b6008805460ff191660011790556006805474ff0000000000000000000000000000000000000000191660a060020a17905561228968056bc75e2d63100000615151565b61229c3368056bc75e2d63100000614e79565b6005805461ff0019169055565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615612358576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff166123af576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b60006123b9611392565b905060006123c7858361515a565b90508061240c576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b60005b60095481101561257c5760006009828154811061242857fe5b6000918252602080832090910154600160a060020a0316808352600a90915260408220600301549092509061245d8583614d05565b9050806124a2576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b8787858181106124ae57fe5b905060200201358111156124fa576040805160e560020a62461bcd02815260206004820152600c60248201526000805160206156c0833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a60205260409020600301546125209082615082565b600160a060020a0384166000818152600a60209081526040918290206003019390935580518481529051919233926000805160206157008339815191529281900390910190a36125718333836150df565b50505060010161240f565b5061258685615151565b611c033386614e79565b60008061259d878661515a565b905060006125ab8786615082565b905060006125b9828961515a565b905060006125cf670de0b6b3a76400008561515a565b905060006125dd8383615296565b905060006125eb828e614d05565b905060006125f9828f614dee565b90506000612618612612670de0b6b3a76400008a614dee565b8b614d05565b905061263582612630670de0b6b3a764000084614dee565b61515a565b9f9e505050505050505050505050505050565b600033600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff16156126f9576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16612750576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a602052604090205460ff166127ae576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a60205260409020600301546127e0906002670de0b6b3a76400005b04614d05565b831115612825576040805160e560020a62461bcd0281526020600482015260106024820152600080516020615740833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a6020526040902060038101546002808301549054600b5460075461285f949392919089906137a3565b9150828210156128a7576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615800833981519152604482015290519081900360640190fd5b6128b5816003015485615082565b6003820155604080518581529051600160a060020a0387169133916000805160206157008339815191529181900360200190a36128f182615151565b6128fb3383614e79565b6129068533866150df565b506005805461ff00191690559392505050565b336000908152600160209081526040808320600160a060020a03861684529091528120548083111561296e57336000908152600160209081526040808320600160a060020a038816845290915281205561299d565b6129788184614dee565b336000908152600160209081526040808320600160a060020a03891684529091529020555b336000818152600160209081526040808320600160a060020a0389168085529083529281902054815190815290519293926000805160206157c0833981519152929181900390910190a35060019392505050565b600033600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615612aa2576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16612af9576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a602052604090205460ff16612b57576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a6020526040902060038101546002808301549054600b54600754612b9194939291908990612590565b915081612bd6576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b82821115612c1c576040805160e560020a62461bcd02815260206004820152600c60248201526000805160206156c0833981519152604482015290519081900360640190fd5b600160a060020a0385166000908152600a6020526040902060030154612c4c906002670de0b6b3a76400006127da565b821115612c91576040805160e560020a62461bcd0281526020600482015260106024820152600080516020615740833981519152604482015290519081900360640190fd5b612c9f816003015483615082565b6003820155604080518381529051600160a060020a0387169133916000805160206157008339815191529181900360200190a3612cdb84615151565b612ce53385614e79565b6129068533846150df565b600160a060020a031660009081526020819052604090205490565b620f4240670de0b6b3a76400006113a8565b6040805160208082523690820181905260009283923392600160e060020a03198535169285929081908101848480828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615612dbd576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff001916610100179055600160a060020a0387166000908152600a602052604090205460ff16612e2a576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0385166000908152600a602052604090205460ff16612e88576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b60065460a060020a900460ff16612ee9576040805160e560020a62461bcd02815260206004820152601360248201527f4552525f535741505f4e4f545f5055424c494300000000000000000000000000604482015290519081900360640190fd5b600160a060020a038088166000908152600a602052604080822092881682529020600380820154612f2291670de0b6b3a7640000610e34565b861115612f67576040805160e560020a62461bcd02815260206004820152601160248201526000805160206156e0833981519152604482015290519081900360640190fd5b6000612f888360030154846002015484600301548560020154600754613df0565b905085811115612fe2576040805160e560020a62461bcd02815260206004820152601360248201527f4552525f4241445f4c494d49545f505249434500000000000000000000000000604482015290519081900360640190fd5b61300283600301548460020154846003015485600201548b600754614c72565b94508885111561304a576040805160e560020a62461bcd02815260206004820152600c60248201526000805160206156c0833981519152604482015290519081900360640190fd5b613058836003015486615082565b836003018190555061306e826003015488614dee565b600380840182905584015460028086015490850154600754613091949190613df0565b9350808410156130d9576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b85841115613131576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f4c494d49545f50524943450000000000000000000000000000000000604482015290519081900360640190fd5b61313b858861515a565b811115613180576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b87600160a060020a03168a600160a060020a031633600160a060020a03167f908fb5ee8f16c6bc9bc3690973819f32a4d4b10188134543c88706e0e1d43378888b604051808381526020018281526020019250505060405180910390a46131e88a33876150df565b6131f3883389614e83565b5050506005805461ff001916905590969095509350505050565b6040805160208082523690820181905260009283923392600160e060020a03198535169285929081908101848480828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff16156132ad576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff001916610100179055600160a060020a0387166000908152600a602052604090205460ff1661331a576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0385166000908152600a602052604090205460ff16613378576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b60065460a060020a900460ff166133d9576040805160e560020a62461bcd02815260206004820152601360248201527f4552525f535741505f4e4f545f5055424c494300000000000000000000000000604482015290519081900360640190fd5b600160a060020a038088166000908152600a6020526040808220928816825290206003820154613413906002670de0b6b3a76400006127da565b881115613458576040805160e560020a62461bcd0281526020600482015260106024820152600080516020615740833981519152604482015290519081900360640190fd5b60006134798360030154846002015484600301548560020154600754613df0565b9050858111156134d3576040805160e560020a62461bcd02815260206004820152601360248201527f4552525f4241445f4c494d49545f505249434500000000000000000000000000604482015290519081900360640190fd5b6134f383600301548460020154846003015485600201548d6007546141ae565b94508685101561353b576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615800833981519152604482015290519081900360640190fd5b61354983600301548a615082565b836003018190555061355f826003015486614dee565b600380840182905584015460028086015490850154600754613582949190613df0565b9350808410156135ca576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b85841115613622576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f4c494d49545f50524943450000000000000000000000000000000000604482015290519081900360640190fd5b61362c898661515a565b811115613671576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b87600160a060020a03168a600160a060020a031633600160a060020a03167f908fb5ee8f16c6bc9bc3690973819f32a4d4b10188134543c88706e0e1d433788c89604051808381526020018281526020019250505060405180910390a46136d98a338b6150df565b6131f3883387614e83565b6000806136f1878661515a565b90506000613707670de0b6b3a764000083614dee565b905060006137158286614d05565b9050600061372f87612630670de0b6b3a764000085614dee565b9050600061373d8c83614dee565b9050600061374b828e61515a565b905060006137598288615296565b90506000613767828e614d05565b905060006137758e83614dee565b905061378e81612630670de0b6b3a76400006000614dee565b99505050505050505050509695505050505050565b6000806137b0878661515a565b905060006137cf6137c9670de0b6b3a764000084614dee565b85614d05565b905060006137ee866137e9670de0b6b3a764000085614dee565b614d05565b905060006137fc8b83615082565b9050600061380a828d61515a565b905060006138188287615296565b90506000613826828d614d05565b9050613832818d614dee565b9e9d5050505050505050505050505050565b64e8d4a51000670de0b6b3a76400006113a8565b600080613865878661515a565b90506000613880856137e9670de0b6b3a76400006000614dee565b9050600061388e8883614dee565b9050600061389c828a61515a565b905060006138bb826138b6670de0b6b3a76400008861515a565b615296565b905060006138c9828e614d05565b905060006138d78e83614dee565b905060006138f0612612670de0b6b3a76400008a614dee565b9050612635826137e9670de0b6b3a764000084614dee565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff16156139b7576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff001916610100179055600160a060020a0381166000908152600a602052604090205460ff16613a24576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600160a060020a038316916370a08231916024808301926020929190829003018186803b158015613a8357600080fd5b505afa158015613a97573d6000803e3d6000fd5b505050506040513d6020811015613aad57600080fd5b5051600160a060020a039091166000908152600a60205260409020600301556005805461ff0019169055565b60085460ff1690565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615613b91576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560065433600160a060020a0390911614613bf2576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b6006805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03929092169190911790556005805461ff0019169055565b600554600090610100900460ff1615613c7d576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b50600b5490565b68056bc75e2d6310000081565b600554600090610100900460ff1615613ce2576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a602052604090205460ff16613d40576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b50600160a060020a03166000908152600a602052604090206002015490565b60048054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561107b5780601f106110505761010080835404028352916020019161107b565b6704a03ce68d21555681565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b600080613dfd878761515a565b90506000613e0b868661515a565b90506000613e19838361515a565b90506000613e3b670de0b6b3a7640000612630670de0b6b3a764000089614dee565b9050613e478282614d05565b9a9950505050505050505050565b6000613e62338484614f78565b50600192915050565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615613f1a576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16613f71576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b6000613f7b611392565b90506000613f8a856000614d05565b90506000613f988683614dee565b90506000613fa6828561515a565b905080613feb576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b613ff53388614e5f565b60055461401190620100009004600160a060020a031684614e79565b61401a82614e6d565b60005b60095481101561418a5760006009828154811061403657fe5b6000918252602080832090910154600160a060020a0316808352600a90915260408220600301549092509061406b8583614d05565b9050806140b0576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b8989858181106140bc57fe5b90506020020135811015614108576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615800833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090206003015461412e9082614dee565b600160a060020a0384166000818152600a60209081526040918290206003019390935580518481529051919233926000805160206157a08339815191529281900390910190a361417f833383614e83565b50505060010161401d565b50506005805461ff0019169055505050505050565b600881565b600281565b600181565b6000806141bb878661515a565b905060006141d1670de0b6b3a764000085614dee565b90506141dd8582614d05565b905060006141ef8a6126308c85615082565b905060006141fd8285615296565b90506000614213670de0b6b3a764000083614dee565b905061421f8a82614d05565b9c9b505050505050505050505050565b600a670de0b6b3a76400006113a8565b671bc16d674ec7ffff81565b600554606090610100900460ff161561429c576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b60085460ff166142e4576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b600980548060200260200160405190810160405280929190818152602001828054801561107b57602002820191906000526020600020905b8154600160a060020a0316815260019091019060200180831161431c575050505050905090565b600081565b600554606090610100900460ff16156142e4576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b60095490565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff161561444e576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560065433600160a060020a03909116146144af576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b600160a060020a0381166000908152600a602052604090205460ff1661450d576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b60085460ff1615614556576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b600160a060020a0381166000908152600a60205260408120600301549061457d8282614d05565b600b54600160a060020a0385166000908152600a60205260409020600201549192506145a891614dee565b600b55600160a060020a0383166000908152600a60205260409020600101546009805460001981019190829081106145dc57fe5b60009182526020909120015460098054600160a060020a03909216918490811061460257fe5b9060005260206000200160006101000a815481600160a060020a030219169083600160a060020a0316021790555081600a60006009858154811061464257fe5b6000918252602080832090910154600160a060020a03168352820192909252604001902060010155600980548061467557fe5b600082815260208082206000199084018101805473ffffffffffffffffffffffffffffffffffffffff191690559092019092556040805160808101825283815280830184815281830185815260608301868152600160a060020a038c168752600a909552929094209051815460ff1916901515178155925160018401555160028301555160039091015561470e8533611bdd8787614dee565b600554611c03908690620100009004600160a060020a031685614e83565b600554600090610100900460ff161561477d576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b5060075490565b336000908152600160209081526040808320600160a060020a03861684529091528120546147b29083615082565b336000818152600160209081526040808320600160a060020a0389168085529083529281902085905580519485525191936000805160206157c0833981519152929081900390910190a350600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600654600160a060020a031633146148e1576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090205460ff1615614952576040805160e560020a62461bcd02815260206004820152600c60248201527f4552525f49535f424f554e440000000000000000000000000000000000000000604482015290519081900360640190fd5b60085460ff161561499b576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b6009546008116149f5576040805160e560020a62461bcd02815260206004820152600e60248201527f4552525f4d41585f544f4b454e53000000000000000000000000000000000000604482015290519081900360640190fd5b604080516080810182526001808252600980546020808501918252600085870181815260608701828152600160a060020a038c16808452600a9094529782209651875460ff1916901515178755925186860155915160028601559451600390940193909355805491820181559091527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af01805473ffffffffffffffffffffffffffffffffffffffff19169091179055614aaf8383836117c9565b505050565b6002670de0b6b3a76400006113a8565b600554600090610100900460ff1615614b15576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a602052604090205460ff16614b73576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a6020526040902060020154600b54614b9d90829061515a565b9392505050565b600554600090610100900460ff1615614bf5576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a602052604090205460ff16614c53576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b50600160a060020a03166000908152600a602052604090206003015490565b600080614c7f858861515a565b90506000614c8d8786614dee565b90506000614c9b888361515a565b90506000614ca98285615296565b9050614cbd81670de0b6b3a7640000614dee565b9050614cd1670de0b6b3a764000087614dee565b9450614ce6614ce08c83614d05565b8661515a565b9b9a5050505050505050505050565b60065460a060020a900460ff1690565b6000828202831580614d1f575082848281614d1c57fe5b04145b614d73576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6706f05b59d3b20000810181811015614dd6576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6000670de0b6b3a7640000825b049695505050505050565b6000806000614dfd85856153b9565b915091508015614e57576040805160e560020a62461bcd02815260206004820152601160248201527f4552525f5355425f554e444552464c4f57000000000000000000000000000000604482015290519081900360640190fd5b509392505050565b614e6982826153de565b5050565b614e76816153e9565b50565b614e6982826154b3565b604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a03848116600483015260248201849052915160009286169163a9059cbb91604480830192602092919082900301818787803b158015614eef57600080fd5b505af1158015614f03573d6000803e3d6000fd5b505050506040513d6020811015614f1957600080fd5b5051905080614f72576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f45524332305f46414c53450000000000000000000000000000000000604482015290519081900360640190fd5b50505050565b600160a060020a038316600090815260208190526040902054811115614fe8576040805160e560020a62461bcd02815260206004820152601460248201527f4552525f494e53554646494349454e545f42414c000000000000000000000000604482015290519081900360640190fd5b600160a060020a03831660009081526020819052604090205461500b9082614dee565b600160a060020a03808516600090815260208190526040808220939093559084168152205461503a9082615082565b600160a060020a0380841660008181526020818152604091829020949094558051858152905191939287169260008051602061576083398151915292918290030190a3505050565b600082820183811015614b9d576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4144445f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b604080517f23b872dd000000000000000000000000000000000000000000000000000000008152600160a060020a0384811660048301523060248301526044820184905291516000928616916323b872dd91606480830192602092919082900301818787803b158015614eef57600080fd5b614e76816154be565b6000816151b1576040805160e560020a62461bcd02815260206004820152600c60248201527f4552525f4449565f5a45524f0000000000000000000000000000000000000000604482015290519081900360640190fd5b670de0b6b3a764000083028315806151d95750670de0b6b3a76400008482816151d657fe5b04145b61522d576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b6002830481018181101561528b576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b6000848281614de357fe5b600060018310156152f1576040805160e560020a62461bcd02815260206004820152601560248201527f4552525f42504f575f424153455f544f4f5f4c4f570000000000000000000000604482015290519081900360640190fd5b671bc16d674ec7ffff831115615351576040805160e560020a62461bcd02815260206004820152601660248201527f4552525f42504f575f424153455f544f4f5f4849474800000000000000000000604482015290519081900360640190fd5b600061535c83615521565b9050600061536a8483614dee565b905060006153808661537b8561553c565b61554a565b9050816153915792506110d4915050565b60006153a287846305f5e1006155a1565b90506153ae8282614d05565b979650505050505050565b6000808284106153cf57505080820360006153d7565b505081810360015b9250929050565b614e69823083614f78565b30600090815260208190526040902054811115615450576040805160e560020a62461bcd02815260206004820152601460248201527f4552525f494e53554646494349454e545f42414c000000000000000000000000604482015290519081900360640190fd5b3060009081526020819052604090205461546a9082614dee565b306000908152602081905260409020556002546154879082614dee565b60025560408051828152905160009130916000805160206157608339815191529181900360200190a350565b614e69308383614f78565b306000908152602081905260409020546154d89082615082565b306000908152602081905260409020556002546154f59082615082565b60025560408051828152905130916000916000805160206157608339815191529181900360200190a350565b6000670de0b6b3a76400006155358361553c565b0292915050565b670de0b6b3a7640000900490565b6000806002830661556357670de0b6b3a7640000615565565b835b90506002830492505b8215614b9d5761557e8485614d05565b93506002830615615596576155938185614d05565b90505b60028304925061556e565b60008281806155b887670de0b6b3a76400006153b9565b9092509050670de0b6b3a764000080600060015b888410615670576000670de0b6b3a7640000820290506000806156008a6155fb85670de0b6b3a7640000614dee565b6153b9565b91509150615612876137e9848c614d05565b965061561e878461515a565b96508661562d57505050615670565b8715615637579315935b8015615641579315935b8415615658576156518688614dee565b9550615665565b6156628688615082565b95505b5050506001016155cc565b5090999850505050505050505056fe4552525f4e4f545f46494e414c495a45440000000000000000000000000000004552525f5245454e5452590000000000000000000000000000000000000000004552525f4c494d49545f494e00000000000000000000000000000000000000004552525f4d41585f4f55545f524154494f00000000000000000000000000000063982df10efd8dfaaaa0fcc7f50b2d93b7cba26ccc48adee2873220d485dc39a4552525f4e4f545f434f4e54524f4c4c455200000000000000000000000000004552525f4d41585f494e5f524154494f00000000000000000000000000000000ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef4552525f4e4f545f424f554e4400000000000000000000000000000000000000e74c91552b64c2e2e7bd255639e004e693bd3e1d01cc33e65610b86afcc1ffed8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9254552525f49535f46494e414c495a4544000000000000000000000000000000004552525f4c494d49545f4f5554000000000000000000000000000000000000004552525f4d4154485f415050524f580000000000000000000000000000000000a265627a7a72315820a6ed20be58469dda7b96f5cd85dbd70406a753a02b645704241ab59bf33344fe64736f6c634300050c0032a265627a7a723158201fb7c2c80fbc145fbafa4fbc21af09d0d3faf8acf13673c5517de0883d91e5f564736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/BMath.abi b/runtime/near-evm-runner/tests/build/BMath.abi new file mode 100644 index 00000000000..6df234eb16b --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BMath.abi @@ -0,0 +1,574 @@ +[ + { + "constant": true, + "inputs": [], + "name": "BONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "BPOW_PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "EXIT_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "INIT_POOL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_IN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_OUT_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_TOTAL_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BALANCE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcSpotPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "spotPrice", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcOutGivenIn", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcInGivenOut", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcPoolOutGivenSingleIn", + "outputs": [ + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcSingleInGivenPoolOut", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcSingleOutGivenPoolIn", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcPoolInGivenSingleOut", + "outputs": [ + { + "internalType": "uint256", + "name": "poolAmountIn", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/BMath.bin b/runtime/near-evm-runner/tests/build/BMath.bin new file mode 100644 index 00000000000..73ade7f2077 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BMath.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b50610e77806100206000396000f3fe608060405234801561001057600080fd5b5060043610610175576000357c010000000000000000000000000000000000000000000000000000000090048063a221ee49116100e0578063bc694ea211610099578063bc694ea214610348578063c36596a61461019c578063c6580d1214610350578063e4a28a521461017a578063ec09302114610358578063f8d6aed41461036057610175565b8063a221ee49146102b8578063b0e0d136146102ed578063b7b800a4146102f5578063ba019dab146102fd578063ba9530a614610305578063bc063e1a1461034057610175565b80638656b653116101325780638656b65314610222578063867378c51461025d57806389298012146102655780639381cd2b146102a0578063992e2a92146102a85780639a86139b146102b057610175565b806309a3bbe41461017a578063189d00ca14610194578063218b53821461019c5780635c1bbaf7146101a457806376c7a3c7146101df57806382f652ad146101e7575b600080fd5b61018261039b565b60408051918252519081900360200190f35b6101826103a8565b6101826103bc565b610182600480360360c08110156101ba57600080fd5b5080359060208101359060408101359060608101359060808101359060a001356103c8565b610182610480565b610182600480360360c08110156101fd57600080fd5b5080359060208101359060408101359060608101359060808101359060a00135610492565b610182600480360360c081101561023857600080fd5b5080359060208101359060408101359060608101359060808101359060a00135610551565b6101826105f2565b610182600480360360c081101561027b57600080fd5b5080359060208101359060408101359060608101359060808101359060a00135610606565b6101826106b6565b6101826106c3565b6101826106cf565b610182600480360360a08110156102ce57600080fd5b50803590602081013590604081013590606081013590608001356106f3565b610182610758565b61018261075d565b610182610762565b610182600480360360c081101561031b57600080fd5b5080359060208101359060408101359060608101359060808101359060a00135610767565b6101826107e8565b6101826107f8565b610182610804565b610182610809565b610182600480360360c081101561037657600080fd5b5080359060208101359060408101359060608101359060808101359060a00135610819565b6802b5e3af16b188000081565b6402540be400670de0b6b3a76400005b0481565b670de0b6b3a764000081565b6000806103d5878661089c565b905060006103e387866109e5565b905060006103f1828961089c565b90506000610407670de0b6b3a76400008561089c565b905060006104158383610a49565b90506000610423828e610b6c565b90506000610431828f610c4e565b9050600061045061044a670de0b6b3a76400008a610c4e565b8b610b6c565b905061046d82610468670de0b6b3a764000084610c4e565b61089c565b9f9e505050505050505050505050505050565b620f4240670de0b6b3a76400006103b8565b60008061049f878661089c565b905060006104b5670de0b6b3a764000083610c4e565b905060006104c38286610b6c565b905060006104dd87610468670de0b6b3a764000085610c4e565b905060006104eb8c83610c4e565b905060006104f9828e61089c565b905060006105078288610a49565b90506000610515828e610b6c565b905060006105238e83610c4e565b905061053c81610468670de0b6b3a76400006000610c4e565b99505050505050505050509695505050505050565b60008061055e878661089c565b9050600061057d610577670de0b6b3a764000084610c4e565b85610b6c565b9050600061059c86610597670de0b6b3a764000085610c4e565b610b6c565b905060006105aa8b836109e5565b905060006105b8828d61089c565b905060006105c68287610a49565b905060006105d4828d610b6c565b90506105e0818d610c4e565b9e9d5050505050505050505050505050565b64e8d4a51000670de0b6b3a76400006103b8565b600080610613878661089c565b9050600061062e85610597670de0b6b3a76400006000610c4e565b9050600061063c8883610c4e565b9050600061064a828a61089c565b9050600061066982610664670de0b6b3a76400008861089c565b610a49565b90506000610677828e610b6c565b905060006106858e83610c4e565b9050600061069e61044a670de0b6b3a76400008a610c4e565b905061046d82610597670de0b6b3a764000084610c4e565b68056bc75e2d6310000081565b6704a03ce68d21555681565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b600080610700878761089c565b9050600061070e868661089c565b9050600061071c838361089c565b9050600061073e670de0b6b3a7640000610468670de0b6b3a764000089610c4e565b905061074a8282610b6c565b9a9950505050505050505050565b600881565b600281565b600181565b600080610774878661089c565b9050600061078a670de0b6b3a764000085610c4e565b90506107968582610b6c565b905060006107a88a6104688c856109e5565b905060006107b68285610a49565b905060006107cc670de0b6b3a764000083610c4e565b90506107d88a82610b6c565b9c9b505050505050505050505050565b600a670de0b6b3a76400006103b8565b671bc16d674ec7ffff81565b600081565b6002670de0b6b3a76400006103b8565b600080610826858861089c565b905060006108348786610c4e565b90506000610842888361089c565b905060006108508285610a49565b905061086481670de0b6b3a7640000610c4e565b9050610878670de0b6b3a764000087610c4e565b945061088d6108878c83610b6c565b8661089c565b9b9a5050505050505050505050565b6000816108f3576040805160e560020a62461bcd02815260206004820152600c60248201527f4552525f4449565f5a45524f0000000000000000000000000000000000000000604482015290519081900360640190fd5b670de0b6b3a7640000830283158061091b5750670de0b6b3a764000084828161091857fe5b04145b61096f576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b600283048101818110156109cd576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b60008482816109d857fe5b0493505050505b92915050565b600082820183811015610a42576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4144445f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b9392505050565b60006001831015610aa4576040805160e560020a62461bcd02815260206004820152601560248201527f4552525f42504f575f424153455f544f4f5f4c4f570000000000000000000000604482015290519081900360640190fd5b671bc16d674ec7ffff831115610b04576040805160e560020a62461bcd02815260206004820152601660248201527f4552525f42504f575f424153455f544f4f5f4849474800000000000000000000604482015290519081900360640190fd5b6000610b0f83610cbf565b90506000610b1d8483610c4e565b90506000610b3386610b2e85610cda565b610ce8565b905081610b445792506109df915050565b6000610b5587846305f5e100610d3f565b9050610b618282610b6c565b979650505050505050565b6000828202831580610b86575082848281610b8357fe5b04145b610bda576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6706f05b59d3b20000810181811015610c3d576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6000670de0b6b3a7640000826109d8565b6000806000610c5d8585610e1d565b915091508015610cb7576040805160e560020a62461bcd02815260206004820152601160248201527f4552525f5355425f554e444552464c4f57000000000000000000000000000000604482015290519081900360640190fd5b509392505050565b6000670de0b6b3a7640000610cd383610cda565b0292915050565b670de0b6b3a7640000900490565b60008060028306610d0157670de0b6b3a7640000610d03565b835b90506002830492505b8215610a4257610d1c8485610b6c565b93506002830615610d3457610d318185610b6c565b90505b600283049250610d0c565b6000828180610d5687670de0b6b3a7640000610e1d565b9092509050670de0b6b3a764000080600060015b888410610e0e576000670de0b6b3a764000082029050600080610d9e8a610d9985670de0b6b3a7640000610c4e565b610e1d565b91509150610db087610597848c610b6c565b9650610dbc878461089c565b965086610dcb57505050610e0e565b8715610dd5579315935b8015610ddf579315935b8415610df657610def8688610c4e565b9550610e03565b610e0086886109e5565b95505b505050600101610d6a565b50909998505050505050505050565b600080828410610e335750508082036000610e3b565b505081810360015b925092905056fea265627a7a723158205ed1b22832c14cf9e2efe6ea235b597639d6738dd598d3ea8203c58103f244c964736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/BNum.abi b/runtime/near-evm-runner/tests/build/BNum.abi new file mode 100644 index 00000000000..42a7386d836 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BNum.abi @@ -0,0 +1,257 @@ +[ + { + "constant": true, + "inputs": [], + "name": "BONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "BPOW_PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "EXIT_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "INIT_POOL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_IN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_OUT_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_TOTAL_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BALANCE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/BNum.bin b/runtime/near-evm-runner/tests/build/BNum.bin new file mode 100644 index 00000000000..aac89837d18 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BNum.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b5061029c806100206000396000f3fe608060405234801561001057600080fd5b5060043610610108576000357c010000000000000000000000000000000000000000000000000000000090048063b0e0d136116100af578063b0e0d1361461015f578063b7b800a414610167578063ba019dab1461016f578063bc063e1a14610177578063bc694ea21461017f578063c36596a61461012f578063c6580d1214610187578063e4a28a521461010d578063ec0930211461018f57610108565b806309a3bbe41461010d578063189d00ca14610127578063218b53821461012f57806376c7a3c714610137578063867378c51461013f5780639381cd2b14610147578063992e2a921461014f5780639a86139b14610157575b600080fd5b610115610197565b60408051918252519081900360200190f35b6101156101a4565b6101156101b8565b6101156101c4565b6101156101d6565b6101156101ea565b6101156101f7565b610115610203565b610115610227565b61011561022c565b610115610231565b610115610236565b610115610246565b610115610252565b610115610257565b6802b5e3af16b188000081565b6402540be400670de0b6b3a76400005b0481565b670de0b6b3a764000081565b620f4240670de0b6b3a76400006101b4565b64e8d4a51000670de0b6b3a76400006101b4565b68056bc75e2d6310000081565b6704a03ce68d21555681565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b600881565b600281565b600181565b600a670de0b6b3a76400006101b4565b671bc16d674ec7ffff81565b600081565b6002670de0b6b3a76400006101b456fea265627a7a7231582089365996d164956921d5302db8b5bd223216993fe8eda62ec774fd5ff6d7c3f164736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/BPool.abi b/runtime/near-evm-runner/tests/build/BPool.abi new file mode 100644 index 00000000000..10600139942 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BPool.abi @@ -0,0 +1,1630 @@ +[ + { + "inputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": true, + "inputs": [ + { + "indexed": true, + "internalType": "bytes4", + "name": "sig", + "type": "bytes4" + }, + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "LOG_CALL", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "tokenOut", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + } + ], + "name": "LOG_EXIT", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "tokenIn", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + } + ], + "name": "LOG_JOIN", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "tokenIn", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "tokenOut", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + } + ], + "name": "LOG_SWAP", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "BONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "BPOW_PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "EXIT_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "INIT_POOL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_IN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_OUT_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_TOTAL_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BALANCE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "whom", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcInGivenOut", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcOutGivenIn", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcPoolInGivenSingleOut", + "outputs": [ + { + "internalType": "uint256", + "name": "poolAmountIn", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcPoolOutGivenSingleIn", + "outputs": [ + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcSingleInGivenPoolOut", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcSingleOutGivenPoolIn", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcSpotPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "spotPrice", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "decreaseApproval", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "increaseApproval", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "isPublicSwap", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "isFinalized", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "t", + "type": "address" + } + ], + "name": "isBound", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getNumTokens", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getCurrentTokens", + "outputs": [ + { + "internalType": "address[]", + "name": "tokens", + "type": "address[]" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getFinalTokens", + "outputs": [ + { + "internalType": "address[]", + "name": "tokens", + "type": "address[]" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + } + ], + "name": "getDenormalizedWeight", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getTotalDenormalizedWeight", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + } + ], + "name": "getNormalizedWeight", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + } + ], + "name": "getBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getSwapFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getController", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "setSwapFee", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "manager", + "type": "address" + } + ], + "name": "setController", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "bool", + "name": "public_", + "type": "bool" + } + ], + "name": "setPublicSwap", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "finalize", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "balance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "denorm", + "type": "uint256" + } + ], + "name": "bind", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "balance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "denorm", + "type": "uint256" + } + ], + "name": "rebind", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + } + ], + "name": "unbind", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + } + ], + "name": "gulp", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "tokenIn", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenOut", + "type": "address" + } + ], + "name": "getSpotPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "spotPrice", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "tokenIn", + "type": "address" + }, + { + "internalType": "address", + "name": "tokenOut", + "type": "address" + } + ], + "name": "getSpotPriceSansFee", + "outputs": [ + { + "internalType": "uint256", + "name": "spotPrice", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "maxAmountsIn", + "type": "uint256[]" + } + ], + "name": "joinPool", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "poolAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "minAmountsOut", + "type": "uint256[]" + } + ], + "name": "exitPool", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "tokenIn", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + }, + { + "internalType": "address", + "name": "tokenOut", + "type": "address" + }, + { + "internalType": "uint256", + "name": "minAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxPrice", + "type": "uint256" + } + ], + "name": "swapExactAmountIn", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "spotPriceAfter", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "tokenIn", + "type": "address" + }, + { + "internalType": "uint256", + "name": "maxAmountIn", + "type": "uint256" + }, + { + "internalType": "address", + "name": "tokenOut", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxPrice", + "type": "uint256" + } + ], + "name": "swapExactAmountOut", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "spotPriceAfter", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "tokenIn", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minPoolAmountOut", + "type": "uint256" + } + ], + "name": "joinswapExternAmountIn", + "outputs": [ + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "tokenIn", + "type": "address" + }, + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxAmountIn", + "type": "uint256" + } + ], + "name": "joinswapPoolAmountOut", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "tokenOut", + "type": "address" + }, + { + "internalType": "uint256", + "name": "poolAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minAmountOut", + "type": "uint256" + } + ], + "name": "exitswapPoolAmountIn", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "tokenOut", + "type": "address" + }, + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxPoolAmountIn", + "type": "uint256" + } + ], + "name": "exitswapExternAmountOut", + "outputs": [ + { + "internalType": "uint256", + "name": "poolAmountIn", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/BPool.bin b/runtime/near-evm-runner/tests/build/BPool.bin new file mode 100644 index 00000000000..ed434055d39 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BPool.bin @@ -0,0 +1 @@ +60c0604052601360808190527f42616c616e63657220506f6f6c20546f6b656e0000000000000000000000000060a0908152620000409160039190620000f7565b506040805180820190915260038082527f425054000000000000000000000000000000000000000000000000000000000060209092019182526200008791600491620000f7565b506005805460ff19166012179055348015620000a257600080fd5b5060068054600580546201000060b060020a031916336201000081029190911790915564e8d4a51000600755600160a060020a03199091161760a060020a60ff02191690556008805460ff191690556200019c565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200013a57805160ff19168380011785556200016a565b828001600101855582156200016a579182015b828111156200016a5782518255916020019190600101906200014d565b50620001789291506200017c565b5090565b6200019991905b8082111562000178576000815560010162000183565b90565b61587480620001ac6000396000f3fe608060405234801561001057600080fd5b5060043610610378576000357c0100000000000000000000000000000000000000000000000000000000900480638d4e4083116101e7578063bc694ea211610122578063d73dd623116100c5578063d73dd62314610b7f578063dd62ed3e14610bab578063e4a28a521461047e578063e4e1e53814610bd9578063ec09302114610c0b578063f1b8a9b714610c13578063f8b2cb4f14610c39578063f8d6aed414610c5f578063fde924f714610c9a57610378565b8063bc694ea214610ad9578063be3bbd2e14610ae1578063c36596a6146104f2578063c6580d1214610b39578063cc77828d14610b41578063cd2ed8fb14610b49578063cf5e7bd314610b51578063d4cadf6814610b7757610378565b8063a221ee491161018a578063a221ee49146109a6578063a9059cbb146109db578063b02f0b7314610a07578063b0e0d13614610a7e578063b7b800a414610a86578063ba019dab14610a8e578063ba9530a614610a96578063bc063e1a14610ad157610378565b80638d4e40831461092a57806392eefe9b14610932578063936c3477146109585780639381cd2b14610960578063948d8ce61461096857806395d89b411461098e578063992e2a92146109965780639a86139b1461099e57610378565b806349b59552116102b757806376c7a3c71161025a57806376c7a3c7146107aa5780637c5e9ea4146107b25780638201aa3f1461080b57806382f652ad1461084b5780638656b65314610886578063867378c5146108c157806389298012146108c95780638c28cbe81461090457610378565b806349b595521461061b5780634bb278f31461063a5780634f69c0d4146106425780635c1bbaf7146106b95780635db34277146106f457806366188463146107265780636d06dfa01461075257806370a082311461078457610378565b8063218b53821161031f578063218b5382146104f257806323b872dd146104fa5780632f37b624146105305780633018205f14610556578063313ce5671461057a57806334e19907146105985780633fdddaa2146105b757806346ab38f1146105e957610378565b806302c967481461037d57806306fdde03146103c1578063095ea7b31461043e57806309a3bbe41461047e5780631446a7ff1461048657806315e84af9146104b457806318160ddd146104e2578063189d00ca146104ea575b600080fd5b6103af6004803603606081101561039357600080fd5b50600160a060020a038135169060208101359060400135610ca2565b60408051918252519081900360200190f35b6103c9610fef565b6040805160208082528351818301528351919283929083019185019080838360005b838110156104035781810151838201526020016103eb565b50505050905090810190601f1680156104305780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61046a6004803603604081101561045457600080fd5b50600160a060020a038135169060200135611085565b604080519115158252519081900360200190f35b6103af6110da565b6103af6004803603604081101561049c57600080fd5b50600160a060020a03813581169160200135166110e7565b6103af600480360360408110156104ca57600080fd5b50600160a060020a0381358116916020013516611241565b6103af611392565b6103af611398565b6103af6113ac565b61046a6004803603606081101561051057600080fd5b50600160a060020a038135811691602081013590911690604001356113b8565b61046a6004803603602081101561054657600080fd5b5035600160a060020a031661151d565b61055e61153b565b60408051600160a060020a039092168252519081900360200190f35b61058261159c565b6040805160ff9092168252519081900360200190f35b6105b5600480360360208110156105ae57600080fd5b50356115a5565b005b6105b5600480360360608110156105cd57600080fd5b50600160a060020a0381351690602081013590604001356117c9565b6103af600480360360608110156105ff57600080fd5b50600160a060020a038135169060208101359060400135611c15565b6105b56004803603602081101561063157600080fd5b50351515611f01565b6105b5612092565b6105b56004803603604081101561065857600080fd5b8135919081019060408101602082013564010000000081111561067a57600080fd5b82018360208201111561068c57600080fd5b803590602001918460208302840111640100000000831117156106ae57600080fd5b5090925090506122a9565b6103af600480360360c08110156106cf57600080fd5b5080359060208101359060408101359060608101359060808101359060a00135612590565b6103af6004803603606081101561070a57600080fd5b50600160a060020a038135169060208101359060400135612648565b61046a6004803603604081101561073c57600080fd5b50600160a060020a038135169060200135612919565b6103af6004803603606081101561076857600080fd5b50600160a060020a0381351690602081013590604001356129f1565b6103af6004803603602081101561079a57600080fd5b5035600160a060020a0316612cf0565b6103af612d0b565b6107f2600480360360a08110156107c857600080fd5b50600160a060020a0381358116916020810135916040820135169060608101359060800135612d1d565b6040805192835260208301919091528051918290030190f35b6107f2600480360360a081101561082157600080fd5b50600160a060020a038135811691602081013591604082013516906060810135906080013561320d565b6103af600480360360c081101561086157600080fd5b5080359060208101359060408101359060608101359060808101359060a001356136e4565b6103af600480360360c081101561089c57600080fd5b5080359060208101359060408101359060608101359060808101359060a001356137a3565b6103af613844565b6103af600480360360c08110156108df57600080fd5b5080359060208101359060408101359060608101359060808101359060a00135613858565b6105b56004803603602081101561091a57600080fd5b5035600160a060020a0316613908565b61046a613ad9565b6105b56004803603602081101561094857600080fd5b5035600160a060020a0316613ae2565b6103af613c2c565b6103af613c84565b6103af6004803603602081101561097e57600080fd5b5035600160a060020a0316613c91565b6103c9613d5f565b6103af613dc0565b6103af613dcc565b6103af600480360360a08110156109bc57600080fd5b5080359060208101359060408101359060608101359060800135613df0565b61046a600480360360408110156109f157600080fd5b50600160a060020a038135169060200135613e55565b6105b560048036036040811015610a1d57600080fd5b81359190810190604081016020820135640100000000811115610a3f57600080fd5b820183602082011115610a5157600080fd5b80359060200191846020830284011164010000000083111715610a7357600080fd5b509092509050613e6b565b6103af61419f565b6103af6141a4565b6103af6141a9565b6103af600480360360c0811015610aac57600080fd5b5080359060208101359060408101359060608101359060808101359060a001356141ae565b6103af61422f565b6103af61423f565b610ae961424b565b60408051602080825283518183015283519192839290830191858101910280838360005b83811015610b25578181015183820152602001610b0d565b505050509050019250505060405180910390f35b6103af614343565b610ae9614348565b6103af614399565b6105b560048036036020811015610b6757600080fd5b5035600160a060020a031661439f565b6103af61472c565b61046a60048036036040811015610b9557600080fd5b50600160a060020a038135169060200135614784565b6103af60048036036040811015610bc157600080fd5b50600160a060020a0381358116916020013516614805565b6105b560048036036060811015610bef57600080fd5b50600160a060020a038135169060208101359060400135614830565b6103af614ab4565b6103af60048036036020811015610c2957600080fd5b5035600160a060020a0316614ac4565b6103af60048036036020811015610c4f57600080fd5b5035600160a060020a0316614ba4565b6103af600480360360c0811015610c7557600080fd5b5080359060208101359060408101359060608101359060808101359060a00135614c72565b61046a614cf5565b600033600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615610d53576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16610daa576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a602052604090205460ff16610e08576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a60205260409020600390810154610e3d91670de0b6b3a76400005b04600101614d05565b831115610e82576040805160e560020a62461bcd02815260206004820152601160248201526000805160206156e0833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a6020526040902060038101546002808301549054600b54600754610ebc949392919089906136e4565b915081610f01576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b82821115610f47576040805160e560020a62461bcd02815260206004820152600c60248201526000805160206156c0833981519152604482015290519081900360640190fd5b610f55816003015485614dee565b60038201556000610f668382614d05565b604080518781529051919250600160a060020a0388169133916000805160206157a0833981519152919081900360200190a3610fa23384614e5f565b610fb4610faf8483614dee565b614e6d565b600554610fd090620100009004600160a060020a031682614e79565b610fdb863387614e83565b50506005805461ff00191690559392505050565b60038054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561107b5780601f106110505761010080835404028352916020019161107b565b820191906000526020600020905b81548152906001019060200180831161105e57829003601f168201915b5050505050905090565b336000818152600160209081526040808320600160a060020a038716808552908352818420869055815186815291519394909390926000805160206157c0833981519152928290030190a35060015b92915050565b6802b5e3af16b188000081565b600554600090610100900460ff1615611138576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090205460ff16611196576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a602052604090205460ff166111f4576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a038084166000908152600a602052604080822092851682528120600380840154600280860154928401549084015493946112389492939290613df0565b95945050505050565b600554600090610100900460ff1615611292576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090205460ff166112f0576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a602052604090205460ff1661134e576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a038084166000908152600a602052604080822092851682529020600380830154600280850154928401549084015460075461123894929190613df0565b60025490565b6402540be400670de0b6b3a76400005b0481565b670de0b6b3a764000081565b600033600160a060020a03851614806113f45750600160a060020a03841660009081526001602090815260408083203384529091529020548211155b611448576040805160e560020a62461bcd02815260206004820152601560248201527f4552525f42544f4b454e5f4241445f43414c4c45520000000000000000000000604482015290519081900360640190fd5b611453848484614f78565b33600160a060020a038516148015906114915750600160a060020a038416600090815260016020908152604080832033845290915290205460001914155b1561151357600160a060020a03841660009081526001602090815260408083203384529091529020546114c49083614dee565b600160a060020a03858116600090815260016020908152604080832033808552908352928190208590558051948552519287169391926000805160206157c08339815191529281900390910190a35b5060019392505050565b600160a060020a03166000908152600a602052604090205460ff1690565b600554600090610100900460ff161561158c576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b50600654600160a060020a031690565b60055460ff1690565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615611654576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16156116ac576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b600654600160a060020a031633146116fc576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b64e8d4a51000811015611759576040805160e560020a62461bcd02815260206004820152600b60248201527f4552525f4d494e5f464545000000000000000000000000000000000000000000604482015290519081900360640190fd5b67016345785d8a00008111156117b9576040805160e560020a62461bcd02815260206004820152600b60248201527f4552525f4d41585f464545000000000000000000000000000000000000000000604482015290519081900360640190fd5b6007556005805461ff0019169055565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615611878576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560065433600160a060020a03909116146118d9576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090205460ff16611937576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b60085460ff1615611980576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b670de0b6b3a76400008110156119e0576040805160e560020a62461bcd02815260206004820152600e60248201527f4552525f4d494e5f574549474854000000000000000000000000000000000000604482015290519081900360640190fd5b6802b5e3af16b1880000811115611a41576040805160e560020a62461bcd02815260206004820152600e60248201527f4552525f4d41585f574549474854000000000000000000000000000000000000604482015290519081900360640190fd5b620f4240821015611a9c576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f4d494e5f42414c414e43450000000000000000000000000000000000604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090206002015480821115611b3f57611ad5600b54611ad08484614dee565b615082565b600b8190556802b5e3af16b18800001015611b3a576040805160e560020a62461bcd02815260206004820152601460248201527f4552525f4d41585f544f54414c5f574549474854000000000000000000000000604482015290519081900360640190fd5b611b60565b80821015611b6057611b5c600b54611b578385614dee565b614dee565b600b555b600160a060020a0384166000908152600a602052604090206002810183905560030180549084905580841115611ba957611ba48533611b9f8785614dee565b6150df565b611c03565b80841015611c03576000611bbd8286614dee565b90506000611bcc826000614d05565b9050611be28733611bdd8585614dee565b614e83565b600554611c00908890620100009004600160a060020a031683614e83565b50505b50506005805461ff0019169055505050565b600033600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615611cc6576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16611d1d576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a602052604090205460ff16611d7b576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a6020526040902060038101546002808301549054600b54600754611db594939291908990613858565b915082821015611dfd576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615800833981519152604482015290519081900360640190fd5b600160a060020a0385166000908152600a60205260409020600390810154611e2d91670de0b6b3a7640000610e34565b821115611e72576040805160e560020a62461bcd02815260206004820152601160248201526000805160206156e0833981519152604482015290519081900360640190fd5b611e80816003015483614dee565b60038201556000611e918582614d05565b604080518581529051919250600160a060020a0388169133916000805160206157a0833981519152919081900360200190a3611ecd3386614e5f565b611eda610faf8683614dee565b600554611ef690620100009004600160a060020a031682614e79565b610fdb863385614e83565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615611fb0576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff1615612008576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b600654600160a060020a03163314612058576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b6006805491151560a060020a0274ff0000000000000000000000000000000000000000199092169190911790556005805461ff0019169055565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615612141576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560065433600160a060020a03909116146121a2576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b60085460ff16156121eb576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b60095460021115612246576040805160e560020a62461bcd02815260206004820152600e60248201527f4552525f4d494e5f544f4b454e53000000000000000000000000000000000000604482015290519081900360640190fd5b6008805460ff191660011790556006805474ff0000000000000000000000000000000000000000191660a060020a17905561228968056bc75e2d63100000615151565b61229c3368056bc75e2d63100000614e79565b6005805461ff0019169055565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615612358576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff166123af576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b60006123b9611392565b905060006123c7858361515a565b90508061240c576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b60005b60095481101561257c5760006009828154811061242857fe5b6000918252602080832090910154600160a060020a0316808352600a90915260408220600301549092509061245d8583614d05565b9050806124a2576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b8787858181106124ae57fe5b905060200201358111156124fa576040805160e560020a62461bcd02815260206004820152600c60248201526000805160206156c0833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a60205260409020600301546125209082615082565b600160a060020a0384166000818152600a60209081526040918290206003019390935580518481529051919233926000805160206157008339815191529281900390910190a36125718333836150df565b50505060010161240f565b5061258685615151565b611c033386614e79565b60008061259d878661515a565b905060006125ab8786615082565b905060006125b9828961515a565b905060006125cf670de0b6b3a76400008561515a565b905060006125dd8383615296565b905060006125eb828e614d05565b905060006125f9828f614dee565b90506000612618612612670de0b6b3a76400008a614dee565b8b614d05565b905061263582612630670de0b6b3a764000084614dee565b61515a565b9f9e505050505050505050505050505050565b600033600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff16156126f9576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16612750576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a602052604090205460ff166127ae576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a60205260409020600301546127e0906002670de0b6b3a76400005b04614d05565b831115612825576040805160e560020a62461bcd0281526020600482015260106024820152600080516020615740833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a6020526040902060038101546002808301549054600b5460075461285f949392919089906137a3565b9150828210156128a7576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615800833981519152604482015290519081900360640190fd5b6128b5816003015485615082565b6003820155604080518581529051600160a060020a0387169133916000805160206157008339815191529181900360200190a36128f182615151565b6128fb3383614e79565b6129068533866150df565b506005805461ff00191690559392505050565b336000908152600160209081526040808320600160a060020a03861684529091528120548083111561296e57336000908152600160209081526040808320600160a060020a038816845290915281205561299d565b6129788184614dee565b336000908152600160209081526040808320600160a060020a03891684529091529020555b336000818152600160209081526040808320600160a060020a0389168085529083529281902054815190815290519293926000805160206157c0833981519152929181900390910190a35060019392505050565b600033600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615612aa2576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16612af9576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a602052604090205460ff16612b57576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0384166000908152600a6020526040902060038101546002808301549054600b54600754612b9194939291908990612590565b915081612bd6576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b82821115612c1c576040805160e560020a62461bcd02815260206004820152600c60248201526000805160206156c0833981519152604482015290519081900360640190fd5b600160a060020a0385166000908152600a6020526040902060030154612c4c906002670de0b6b3a76400006127da565b821115612c91576040805160e560020a62461bcd0281526020600482015260106024820152600080516020615740833981519152604482015290519081900360640190fd5b612c9f816003015483615082565b6003820155604080518381529051600160a060020a0387169133916000805160206157008339815191529181900360200190a3612cdb84615151565b612ce53385614e79565b6129068533846150df565b600160a060020a031660009081526020819052604090205490565b620f4240670de0b6b3a76400006113a8565b6040805160208082523690820181905260009283923392600160e060020a03198535169285929081908101848480828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615612dbd576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff001916610100179055600160a060020a0387166000908152600a602052604090205460ff16612e2a576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0385166000908152600a602052604090205460ff16612e88576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b60065460a060020a900460ff16612ee9576040805160e560020a62461bcd02815260206004820152601360248201527f4552525f535741505f4e4f545f5055424c494300000000000000000000000000604482015290519081900360640190fd5b600160a060020a038088166000908152600a602052604080822092881682529020600380820154612f2291670de0b6b3a7640000610e34565b861115612f67576040805160e560020a62461bcd02815260206004820152601160248201526000805160206156e0833981519152604482015290519081900360640190fd5b6000612f888360030154846002015484600301548560020154600754613df0565b905085811115612fe2576040805160e560020a62461bcd02815260206004820152601360248201527f4552525f4241445f4c494d49545f505249434500000000000000000000000000604482015290519081900360640190fd5b61300283600301548460020154846003015485600201548b600754614c72565b94508885111561304a576040805160e560020a62461bcd02815260206004820152600c60248201526000805160206156c0833981519152604482015290519081900360640190fd5b613058836003015486615082565b836003018190555061306e826003015488614dee565b600380840182905584015460028086015490850154600754613091949190613df0565b9350808410156130d9576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b85841115613131576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f4c494d49545f50524943450000000000000000000000000000000000604482015290519081900360640190fd5b61313b858861515a565b811115613180576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b87600160a060020a03168a600160a060020a031633600160a060020a03167f908fb5ee8f16c6bc9bc3690973819f32a4d4b10188134543c88706e0e1d43378888b604051808381526020018281526020019250505060405180910390a46131e88a33876150df565b6131f3883389614e83565b5050506005805461ff001916905590969095509350505050565b6040805160208082523690820181905260009283923392600160e060020a03198535169285929081908101848480828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff16156132ad576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff001916610100179055600160a060020a0387166000908152600a602052604090205460ff1661331a576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0385166000908152600a602052604090205460ff16613378576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b60065460a060020a900460ff166133d9576040805160e560020a62461bcd02815260206004820152601360248201527f4552525f535741505f4e4f545f5055424c494300000000000000000000000000604482015290519081900360640190fd5b600160a060020a038088166000908152600a6020526040808220928816825290206003820154613413906002670de0b6b3a76400006127da565b881115613458576040805160e560020a62461bcd0281526020600482015260106024820152600080516020615740833981519152604482015290519081900360640190fd5b60006134798360030154846002015484600301548560020154600754613df0565b9050858111156134d3576040805160e560020a62461bcd02815260206004820152601360248201527f4552525f4241445f4c494d49545f505249434500000000000000000000000000604482015290519081900360640190fd5b6134f383600301548460020154846003015485600201548d6007546141ae565b94508685101561353b576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615800833981519152604482015290519081900360640190fd5b61354983600301548a615082565b836003018190555061355f826003015486614dee565b600380840182905584015460028086015490850154600754613582949190613df0565b9350808410156135ca576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b85841115613622576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f4c494d49545f50524943450000000000000000000000000000000000604482015290519081900360640190fd5b61362c898661515a565b811115613671576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b87600160a060020a03168a600160a060020a031633600160a060020a03167f908fb5ee8f16c6bc9bc3690973819f32a4d4b10188134543c88706e0e1d433788c89604051808381526020018281526020019250505060405180910390a46136d98a338b6150df565b6131f3883387614e83565b6000806136f1878661515a565b90506000613707670de0b6b3a764000083614dee565b905060006137158286614d05565b9050600061372f87612630670de0b6b3a764000085614dee565b9050600061373d8c83614dee565b9050600061374b828e61515a565b905060006137598288615296565b90506000613767828e614d05565b905060006137758e83614dee565b905061378e81612630670de0b6b3a76400006000614dee565b99505050505050505050509695505050505050565b6000806137b0878661515a565b905060006137cf6137c9670de0b6b3a764000084614dee565b85614d05565b905060006137ee866137e9670de0b6b3a764000085614dee565b614d05565b905060006137fc8b83615082565b9050600061380a828d61515a565b905060006138188287615296565b90506000613826828d614d05565b9050613832818d614dee565b9e9d5050505050505050505050505050565b64e8d4a51000670de0b6b3a76400006113a8565b600080613865878661515a565b90506000613880856137e9670de0b6b3a76400006000614dee565b9050600061388e8883614dee565b9050600061389c828a61515a565b905060006138bb826138b6670de0b6b3a76400008861515a565b615296565b905060006138c9828e614d05565b905060006138d78e83614dee565b905060006138f0612612670de0b6b3a76400008a614dee565b9050612635826137e9670de0b6b3a764000084614dee565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff16156139b7576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff001916610100179055600160a060020a0381166000908152600a602052604090205460ff16613a24576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051600160a060020a038316916370a08231916024808301926020929190829003018186803b158015613a8357600080fd5b505afa158015613a97573d6000803e3d6000fd5b505050506040513d6020811015613aad57600080fd5b5051600160a060020a039091166000908152600a60205260409020600301556005805461ff0019169055565b60085460ff1690565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615613b91576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560065433600160a060020a0390911614613bf2576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b6006805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03929092169190911790556005805461ff0019169055565b600554600090610100900460ff1615613c7d576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b50600b5490565b68056bc75e2d6310000081565b600554600090610100900460ff1615613ce2576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a602052604090205460ff16613d40576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b50600160a060020a03166000908152600a602052604090206002015490565b60048054604080516020601f600260001961010060018816150201909516949094049384018190048102820181019092528281526060939092909183018282801561107b5780601f106110505761010080835404028352916020019161107b565b6704a03ce68d21555681565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b600080613dfd878761515a565b90506000613e0b868661515a565b90506000613e19838361515a565b90506000613e3b670de0b6b3a7640000612630670de0b6b3a764000089614dee565b9050613e478282614d05565b9a9950505050505050505050565b6000613e62338484614f78565b50600192915050565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff1615613f1a576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560085460ff16613f71576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b6000613f7b611392565b90506000613f8a856000614d05565b90506000613f988683614dee565b90506000613fa6828561515a565b905080613feb576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b613ff53388614e5f565b60055461401190620100009004600160a060020a031684614e79565b61401a82614e6d565b60005b60095481101561418a5760006009828154811061403657fe5b6000918252602080832090910154600160a060020a0316808352600a90915260408220600301549092509061406b8583614d05565b9050806140b0576040805160e560020a62461bcd02815260206004820152600f6024820152600080516020615820833981519152604482015290519081900360640190fd5b8989858181106140bc57fe5b90506020020135811015614108576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615800833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090206003015461412e9082614dee565b600160a060020a0384166000818152600a60209081526040918290206003019390935580518481529051919233926000805160206157a08339815191529281900390910190a361417f833383614e83565b50505060010161401d565b50506005805461ff0019169055505050505050565b600881565b600281565b600181565b6000806141bb878661515a565b905060006141d1670de0b6b3a764000085614dee565b90506141dd8582614d05565b905060006141ef8a6126308c85615082565b905060006141fd8285615296565b90506000614213670de0b6b3a764000083614dee565b905061421f8a82614d05565b9c9b505050505050505050505050565b600a670de0b6b3a76400006113a8565b671bc16d674ec7ffff81565b600554606090610100900460ff161561429c576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b60085460ff166142e4576040805160e560020a62461bcd0281526020600482015260116024820152600080516020615680833981519152604482015290519081900360640190fd5b600980548060200260200160405190810160405280929190818152602001828054801561107b57602002820191906000526020600020905b8154600160a060020a0316815260019091019060200180831161431c575050505050905090565b600081565b600554606090610100900460ff16156142e4576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b60095490565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600554610100900460ff161561444e576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b6005805461ff00191661010017905560065433600160a060020a03909116146144af576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b600160a060020a0381166000908152600a602052604090205460ff1661450d576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b60085460ff1615614556576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b600160a060020a0381166000908152600a60205260408120600301549061457d8282614d05565b600b54600160a060020a0385166000908152600a60205260409020600201549192506145a891614dee565b600b55600160a060020a0383166000908152600a60205260409020600101546009805460001981019190829081106145dc57fe5b60009182526020909120015460098054600160a060020a03909216918490811061460257fe5b9060005260206000200160006101000a815481600160a060020a030219169083600160a060020a0316021790555081600a60006009858154811061464257fe5b6000918252602080832090910154600160a060020a03168352820192909252604001902060010155600980548061467557fe5b600082815260208082206000199084018101805473ffffffffffffffffffffffffffffffffffffffff191690559092019092556040805160808101825283815280830184815281830185815260608301868152600160a060020a038c168752600a909552929094209051815460ff1916901515178155925160018401555160028301555160039091015561470e8533611bdd8787614dee565b600554611c03908690620100009004600160a060020a031685614e83565b600554600090610100900460ff161561477d576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b5060075490565b336000908152600160209081526040808320600160a060020a03861684529091528120546147b29083615082565b336000818152600160209081526040808320600160a060020a0389168085529083529281902085905580519485525191936000805160206157c0833981519152929081900390910190a350600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b33600160a060020a0316600035600160e060020a031916600160e060020a03191660003660405180806020018281038252848482818152602001925080828437600083820152604051601f909101601f19169092018290039550909350505050a2600654600160a060020a031633146148e1576040805160e560020a62461bcd0281526020600482015260126024820152600080516020615720833981519152604482015290519081900360640190fd5b600160a060020a0383166000908152600a602052604090205460ff1615614952576040805160e560020a62461bcd02815260206004820152600c60248201527f4552525f49535f424f554e440000000000000000000000000000000000000000604482015290519081900360640190fd5b60085460ff161561499b576040805160e560020a62461bcd02815260206004820152601060248201526000805160206157e0833981519152604482015290519081900360640190fd5b6009546008116149f5576040805160e560020a62461bcd02815260206004820152600e60248201527f4552525f4d41585f544f4b454e53000000000000000000000000000000000000604482015290519081900360640190fd5b604080516080810182526001808252600980546020808501918252600085870181815260608701828152600160a060020a038c16808452600a9094529782209651875460ff1916901515178755925186860155915160028601559451600390940193909355805491820181559091527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af01805473ffffffffffffffffffffffffffffffffffffffff19169091179055614aaf8383836117c9565b505050565b6002670de0b6b3a76400006113a8565b600554600090610100900460ff1615614b15576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a602052604090205460ff16614b73576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a6020526040902060020154600b54614b9d90829061515a565b9392505050565b600554600090610100900460ff1615614bf5576040805160e560020a62461bcd02815260206004820152600b60248201526000805160206156a0833981519152604482015290519081900360640190fd5b600160a060020a0382166000908152600a602052604090205460ff16614c53576040805160e560020a62461bcd02815260206004820152600d6024820152600080516020615780833981519152604482015290519081900360640190fd5b50600160a060020a03166000908152600a602052604090206003015490565b600080614c7f858861515a565b90506000614c8d8786614dee565b90506000614c9b888361515a565b90506000614ca98285615296565b9050614cbd81670de0b6b3a7640000614dee565b9050614cd1670de0b6b3a764000087614dee565b9450614ce6614ce08c83614d05565b8661515a565b9b9a5050505050505050505050565b60065460a060020a900460ff1690565b6000828202831580614d1f575082848281614d1c57fe5b04145b614d73576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6706f05b59d3b20000810181811015614dd6576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6000670de0b6b3a7640000825b049695505050505050565b6000806000614dfd85856153b9565b915091508015614e57576040805160e560020a62461bcd02815260206004820152601160248201527f4552525f5355425f554e444552464c4f57000000000000000000000000000000604482015290519081900360640190fd5b509392505050565b614e6982826153de565b5050565b614e76816153e9565b50565b614e6982826154b3565b604080517fa9059cbb000000000000000000000000000000000000000000000000000000008152600160a060020a03848116600483015260248201849052915160009286169163a9059cbb91604480830192602092919082900301818787803b158015614eef57600080fd5b505af1158015614f03573d6000803e3d6000fd5b505050506040513d6020811015614f1957600080fd5b5051905080614f72576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f45524332305f46414c53450000000000000000000000000000000000604482015290519081900360640190fd5b50505050565b600160a060020a038316600090815260208190526040902054811115614fe8576040805160e560020a62461bcd02815260206004820152601460248201527f4552525f494e53554646494349454e545f42414c000000000000000000000000604482015290519081900360640190fd5b600160a060020a03831660009081526020819052604090205461500b9082614dee565b600160a060020a03808516600090815260208190526040808220939093559084168152205461503a9082615082565b600160a060020a0380841660008181526020818152604091829020949094558051858152905191939287169260008051602061576083398151915292918290030190a3505050565b600082820183811015614b9d576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4144445f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b604080517f23b872dd000000000000000000000000000000000000000000000000000000008152600160a060020a0384811660048301523060248301526044820184905291516000928616916323b872dd91606480830192602092919082900301818787803b158015614eef57600080fd5b614e76816154be565b6000816151b1576040805160e560020a62461bcd02815260206004820152600c60248201527f4552525f4449565f5a45524f0000000000000000000000000000000000000000604482015290519081900360640190fd5b670de0b6b3a764000083028315806151d95750670de0b6b3a76400008482816151d657fe5b04145b61522d576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b6002830481018181101561528b576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b6000848281614de357fe5b600060018310156152f1576040805160e560020a62461bcd02815260206004820152601560248201527f4552525f42504f575f424153455f544f4f5f4c4f570000000000000000000000604482015290519081900360640190fd5b671bc16d674ec7ffff831115615351576040805160e560020a62461bcd02815260206004820152601660248201527f4552525f42504f575f424153455f544f4f5f4849474800000000000000000000604482015290519081900360640190fd5b600061535c83615521565b9050600061536a8483614dee565b905060006153808661537b8561553c565b61554a565b9050816153915792506110d4915050565b60006153a287846305f5e1006155a1565b90506153ae8282614d05565b979650505050505050565b6000808284106153cf57505080820360006153d7565b505081810360015b9250929050565b614e69823083614f78565b30600090815260208190526040902054811115615450576040805160e560020a62461bcd02815260206004820152601460248201527f4552525f494e53554646494349454e545f42414c000000000000000000000000604482015290519081900360640190fd5b3060009081526020819052604090205461546a9082614dee565b306000908152602081905260409020556002546154879082614dee565b60025560408051828152905160009130916000805160206157608339815191529181900360200190a350565b614e69308383614f78565b306000908152602081905260409020546154d89082615082565b306000908152602081905260409020556002546154f59082615082565b60025560408051828152905130916000916000805160206157608339815191529181900360200190a350565b6000670de0b6b3a76400006155358361553c565b0292915050565b670de0b6b3a7640000900490565b6000806002830661556357670de0b6b3a7640000615565565b835b90506002830492505b8215614b9d5761557e8485614d05565b93506002830615615596576155938185614d05565b90505b60028304925061556e565b60008281806155b887670de0b6b3a76400006153b9565b9092509050670de0b6b3a764000080600060015b888410615670576000670de0b6b3a7640000820290506000806156008a6155fb85670de0b6b3a7640000614dee565b6153b9565b91509150615612876137e9848c614d05565b965061561e878461515a565b96508661562d57505050615670565b8715615637579315935b8015615641579315935b8415615658576156518688614dee565b9550615665565b6156628688615082565b95505b5050506001016155cc565b5090999850505050505050505056fe4552525f4e4f545f46494e414c495a45440000000000000000000000000000004552525f5245454e5452590000000000000000000000000000000000000000004552525f4c494d49545f494e00000000000000000000000000000000000000004552525f4d41585f4f55545f524154494f00000000000000000000000000000063982df10efd8dfaaaa0fcc7f50b2d93b7cba26ccc48adee2873220d485dc39a4552525f4e4f545f434f4e54524f4c4c455200000000000000000000000000004552525f4d41585f494e5f524154494f00000000000000000000000000000000ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef4552525f4e4f545f424f554e4400000000000000000000000000000000000000e74c91552b64c2e2e7bd255639e004e693bd3e1d01cc33e65610b86afcc1ffed8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9254552525f49535f46494e414c495a4544000000000000000000000000000000004552525f4c494d49545f4f5554000000000000000000000000000000000000004552525f4d4154485f415050524f580000000000000000000000000000000000a265627a7a72315820a6ed20be58469dda7b96f5cd85dbd70406a753a02b645704241ab59bf33344fe64736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/BToken.abi b/runtime/near-evm-runner/tests/build/BToken.abi new file mode 100644 index 00000000000..bd685b01c12 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BToken.abi @@ -0,0 +1,549 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "BONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "BPOW_PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "EXIT_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "INIT_POOL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_IN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_OUT_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_TOTAL_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BALANCE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "whom", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "increaseApproval", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "decreaseApproval", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/BToken.bin b/runtime/near-evm-runner/tests/build/BToken.bin new file mode 100644 index 00000000000..3126375860d --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BToken.bin @@ -0,0 +1 @@ +60c0604052601360808190527f42616c616e63657220506f6f6c20546f6b656e0000000000000000000000000060a090815261003e91600391906100a3565b506040805180820190915260038082527f42505400000000000000000000000000000000000000000000000000000000006020909201918252610083916004916100a3565b506005805460ff1916601217905534801561009d57600080fd5b5061013e565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100e457805160ff1916838001178555610111565b82800160010185558215610111579182015b828111156101115782518255916020019190600101906100f6565b5061011d929150610121565b5090565b61013b91905b8082111561011d5760008155600101610127565b90565b610bd88061014d6000396000f3fe608060405234801561001057600080fd5b50600436106101a1576000357c010000000000000000000000000000000000000000000000000000000090048063992e2a92116100f6578063bc694ea2116100a4578063bc694ea2146103b7578063c36596a61461028d578063c6580d12146103bf578063d73dd623146103c7578063dd62ed3e146103f3578063e4a28a5214610263578063ec09302114610421576101a1565b8063992e2a921461035b5780639a86139b14610363578063a9059cbb1461036b578063b0e0d13614610397578063b7b800a41461039f578063ba019dab146103a7578063bc063e1a146103af576101a1565b8063313ce56711610153578063313ce567146102cb57806366188463146102e957806370a082311461031557806376c7a3c71461033b578063867378c5146103435780639381cd2b1461034b57806395d89b4114610353576101a1565b806306fdde03146101a6578063095ea7b31461022357806309a3bbe41461026357806318160ddd1461027d578063189d00ca14610285578063218b53821461028d57806323b872dd14610295575b600080fd5b6101ae610429565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101e85781810151838201526020016101d0565b50505050905090810190601f1680156102155780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61024f6004803603604081101561023957600080fd5b50600160a060020a0381351690602001356104bf565b604080519115158252519081900360200190f35b61026b610513565b60408051918252519081900360200190f35b61026b610520565b61026b610526565b61026b61053a565b61024f600480360360608110156102ab57600080fd5b50600160a060020a03813581169160208101359091169060400135610546565b6102d36106ab565b6040805160ff9092168252519081900360200190f35b61024f600480360360408110156102ff57600080fd5b50600160a060020a0381351690602001356106b4565b61026b6004803603602081101561032b57600080fd5b5035600160a060020a031661078c565b61026b6107a7565b61026b6107b9565b61026b6107cd565b6101ae6107da565b61026b61083b565b61026b610847565b61024f6004803603604081101561038157600080fd5b50600160a060020a03813516906020013561086b565b61026b610881565b61026b610886565b61026b61088b565b61026b610890565b61026b6108a0565b61026b6108ac565b61024f600480360360408110156103dd57600080fd5b50600160a060020a0381351690602001356108b1565b61026b6004803603604081101561040957600080fd5b50600160a060020a0381358116916020013516610932565b61026b61095d565b60038054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104b55780601f1061048a576101008083540402835291602001916104b5565b820191906000526020600020905b81548152906001019060200180831161049857829003601f168201915b5050505050905090565b336000818152600160209081526040808320600160a060020a03871680855290835281842086905581518681529151939490939092600080516020610b84833981519152928290030190a350600192915050565b6802b5e3af16b188000081565b60025490565b6402540be400670de0b6b3a76400005b0481565b670de0b6b3a764000081565b600033600160a060020a03851614806105825750600160a060020a03841660009081526001602090815260408083203384529091529020548211155b6105d6576040805160e560020a62461bcd02815260206004820152601560248201527f4552525f42544f4b454e5f4241445f43414c4c45520000000000000000000000604482015290519081900360640190fd5b6105e184848461096d565b33600160a060020a0385161480159061061f5750600160a060020a038416600090815260016020908152604080832033845290915290205460001914155b156106a157600160a060020a03841660009081526001602090815260408083203384529091529020546106529083610a89565b600160a060020a0385811660009081526001602090815260408083203380855290835292819020859055805194855251928716939192600080516020610b848339815191529281900390910190a35b5060019392505050565b60055460ff1690565b336000908152600160209081526040808320600160a060020a03861684529091528120548083111561070957336000908152600160209081526040808320600160a060020a0388168452909152812055610738565b6107138184610a89565b336000908152600160209081526040808320600160a060020a03891684529091529020555b336000818152600160209081526040808320600160a060020a038916808552908352928190205481519081529051929392600080516020610b84833981519152929181900390910190a35060019392505050565b600160a060020a031660009081526020819052604090205490565b620f4240670de0b6b3a7640000610536565b64e8d4a51000670de0b6b3a7640000610536565b68056bc75e2d6310000081565b60048054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156104b55780601f1061048a576101008083540402835291602001916104b5565b6704a03ce68d21555681565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b600061087833848461096d565b50600192915050565b600881565b600281565b600181565b600a670de0b6b3a7640000610536565b671bc16d674ec7ffff81565b600081565b336000908152600160209081526040808320600160a060020a03861684529091528120546108df9083610afa565b336000818152600160209081526040808320600160a060020a038916808552908352928190208590558051948552519193600080516020610b84833981519152929081900390910190a350600192915050565b600160a060020a03918216600090815260016020908152604080832093909416825291909152205490565b6002670de0b6b3a7640000610536565b600160a060020a0383166000908152602081905260409020548111156109dd576040805160e560020a62461bcd02815260206004820152601460248201527f4552525f494e53554646494349454e545f42414c000000000000000000000000604482015290519081900360640190fd5b600160a060020a038316600090815260208190526040902054610a009082610a89565b600160a060020a038085166000908152602081905260408082209390935590841681522054610a2f9082610afa565b600160a060020a038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000806000610a988585610b5e565b915091508015610af2576040805160e560020a62461bcd02815260206004820152601160248201527f4552525f5355425f554e444552464c4f57000000000000000000000000000000604482015290519081900360640190fd5b509392505050565b600082820183811015610b57576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4144445f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b9392505050565b600080828410610b745750508082036000610b7c565b505081810360015b925092905056fe8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a265627a7a72315820a87af892d69e40e2c034544393d3427651f6eae9f394257394f44f1bd9738fdf64736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/BTokenBase.abi b/runtime/near-evm-runner/tests/build/BTokenBase.abi new file mode 100644 index 00000000000..96908e29e8b --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BTokenBase.abi @@ -0,0 +1,307 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "BONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "BPOW_PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "EXIT_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "INIT_POOL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_IN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_OUT_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_TOTAL_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BALANCE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/BTokenBase.bin b/runtime/near-evm-runner/tests/build/BTokenBase.bin new file mode 100644 index 00000000000..ff5c54e21c4 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/BTokenBase.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b5061029c806100206000396000f3fe608060405234801561001057600080fd5b5060043610610108576000357c010000000000000000000000000000000000000000000000000000000090048063b0e0d136116100af578063b0e0d1361461015f578063b7b800a414610167578063ba019dab1461016f578063bc063e1a14610177578063bc694ea21461017f578063c36596a61461012f578063c6580d1214610187578063e4a28a521461010d578063ec0930211461018f57610108565b806309a3bbe41461010d578063189d00ca14610127578063218b53821461012f57806376c7a3c714610137578063867378c51461013f5780639381cd2b14610147578063992e2a921461014f5780639a86139b14610157575b600080fd5b610115610197565b60408051918252519081900360200190f35b6101156101a4565b6101156101b8565b6101156101c4565b6101156101d6565b6101156101ea565b6101156101f7565b610115610203565b610115610227565b61011561022c565b610115610231565b610115610236565b610115610246565b610115610252565b610115610257565b6802b5e3af16b188000081565b6402540be400670de0b6b3a76400005b0481565b670de0b6b3a764000081565b620f4240670de0b6b3a76400006101b4565b64e8d4a51000670de0b6b3a76400006101b4565b68056bc75e2d6310000081565b6704a03ce68d21555681565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b600881565b600281565b600181565b600a670de0b6b3a76400006101b4565b671bc16d674ec7ffff81565b600081565b6002670de0b6b3a76400006101b456fea265627a7a7231582008760bf61cf90a4adde4f0558f43bdcd8f3e5cdf97aca2d1957bb4fef5289a1764736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/IERC20.abi b/runtime/near-evm-runner/tests/build/IERC20.abi new file mode 100644 index 00000000000..a8a6512c554 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/IERC20.abi @@ -0,0 +1,197 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "whom", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/Migrations.abi b/runtime/near-evm-runner/tests/build/Migrations.abi new file mode 100644 index 00000000000..bc177e8cb7a --- /dev/null +++ b/runtime/near-evm-runner/tests/build/Migrations.abi @@ -0,0 +1,68 @@ +[ + { + "inputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "constant": true, + "inputs": [], + "name": "lastCompletedMigration", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "completed", + "type": "uint256" + } + ], + "name": "setCompleted", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "new_address", + "type": "address" + } + ], + "name": "upgrade", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/Migrations.bin b/runtime/near-evm-runner/tests/build/Migrations.bin new file mode 100644 index 00000000000..30bf5398e99 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/Migrations.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b5060008054600160a060020a031916331790556101b9806100326000396000f3fe608060405234801561001057600080fd5b506004361061004f5760e060020a60003504630900f01081146100545780638da5cb5b1461007c578063fbdbad3c146100a0578063fdacd576146100ba575b600080fd5b61007a6004803603602081101561006a57600080fd5b5035600160a060020a03166100d7565b005b610084610157565b60408051600160a060020a039092168252519081900360200190f35b6100a8610166565b60408051918252519081900360200190f35b61007a600480360360208110156100d057600080fd5b503561016c565b600054600160a060020a031633141561015457600081905080600160a060020a031663fdacd5766001546040518263ffffffff1660e060020a02815260040180828152602001915050600060405180830381600087803b15801561013a57600080fd5b505af115801561014e573d6000803e3d6000fd5b50505050505b50565b600054600160a060020a031681565b60015481565b600054600160a060020a03163314156101545760015556fea265627a7a7231582023ed50b526b6a1b0948c964d1041e7f84e7a132d4284b38755f775875359435d64736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/TBPoolJoinExit.abi b/runtime/near-evm-runner/tests/build/TBPoolJoinExit.abi new file mode 100644 index 00000000000..8a33cf7ccaf --- /dev/null +++ b/runtime/near-evm-runner/tests/build/TBPoolJoinExit.abi @@ -0,0 +1,302 @@ +[ + { + "constant": true, + "inputs": [], + "name": "BONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "BPOW_PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "EXIT_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "INIT_POOL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_IN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_OUT_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_TOTAL_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BALANCE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "echidna_no_bug_found", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolTotal", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_records_t_balance", + "type": "uint256" + } + ], + "name": "joinAndExitPool", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/TBPoolJoinExit.bin b/runtime/near-evm-runner/tests/build/TBPoolJoinExit.bin new file mode 100644 index 00000000000..268dfee4a38 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/TBPoolJoinExit.bin @@ -0,0 +1 @@ +60806040526000805460ff1916600117905534801561001d57600080fd5b506108298061002d6000396000f3fe608060405234801561001057600080fd5b506004361061012e576000357c0100000000000000000000000000000000000000000000000000000000900480639a86139b116100ca578063bc694ea21161008e578063bc694ea2146101f2578063c36596a614610171578063c6580d12146101fa578063e4a28a5214610133578063ec093021146102025761012e565b80639a86139b146101ca578063b0e0d136146101d2578063b7b800a4146101da578063ba019dab146101e2578063bc063e1a146101ea5761012e565b806309a3bbe4146101335780631819aa421461014d578063189d00ca14610169578063218b5382146101715780632370e3a41461017957806376c7a3c7146101aa578063867378c5146101b25780639381cd2b146101ba578063992e2a92146101c2575b600080fd5b61013b61020a565b60408051918252519081900360200190f35b610155610217565b604080519115158252519081900360200190f35b61013b610220565b61013b610234565b6101a86004803603608081101561018f57600080fd5b5080359060208101359060408101359060600135610240565b005b61013b610317565b61013b610329565b61013b61033d565b61013b61034a565b61013b610356565b61013b61037a565b61013b61037f565b61013b610384565b61013b610389565b61013b610399565b61013b6103a5565b61013b6103aa565b6802b5e3af16b188000081565b60005460ff1681565b6402540be400670de0b6b3a76400005b0481565b670de0b6b3a764000081565b600061024d8584846103ba565b905068056bc75e2d6310000083111561026557600080fd5b670de0b6b3a764000083101561027a57600080fd5b678ac7230489e8000082111561028f57600080fd5b620f424082101561029f57600080fd5b6102a98386610436565b92506102b58282610436565b9150600081116102c457600080fd5b838310156102d157600080fd5b60006102de85858561049a565b9050808310156102ed57600080fd5b8486116102f957600080fd5b81811461030557600080fd5b50506000805460ff1916905550505050565b620f4240670de0b6b3a7640000610230565b64e8d4a51000670de0b6b3a7640000610230565b68056bc75e2d6310000081565b6704a03ce68d21555681565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b600881565b600281565b600181565b600a670de0b6b3a7640000610230565b671bc16d674ec7ffff81565b600081565b6002670de0b6b3a7640000610230565b6000806103c78585610535565b90508061041e576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f4d4154485f415050524f580000000000000000000000000000000000604482015290519081900360640190fd5b82600061042b838361067c565b979650505050505050565b600082820183811015610493576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4144445f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b9392505050565b6000806104a885600061067c565b905060006104b6868361075e565b905060006104c48287610535565b90508061051b576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f4d4154485f415050524f580000000000000000000000000000000000604482015290519081900360640190fd5b846000610528838361067c565b9998505050505050505050565b60008161058c576040805160e560020a62461bcd02815260206004820152600c60248201527f4552525f4449565f5a45524f0000000000000000000000000000000000000000604482015290519081900360640190fd5b670de0b6b3a764000083028315806105b45750670de0b6b3a76400008482816105b157fe5b04145b610608576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b60028304810181811015610666576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b600084828161067157fe5b049695505050505050565b600082820283158061069657508284828161069357fe5b04145b6106ea576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6706f05b59d3b2000081018181101561074d576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6000670de0b6b3a764000082610671565b600080600061076d85856107cf565b9150915080156107c7576040805160e560020a62461bcd02815260206004820152601160248201527f4552525f5355425f554e444552464c4f57000000000000000000000000000000604482015290519081900360640190fd5b509392505050565b6000808284106107e557505080820360006107ed565b505081810360015b925092905056fea265627a7a723158201790844e1e2552cec4a67cc6ca52dd783178e8f791461ba35e1a0422e236dca664736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/TBPoolJoinExitNoFee.abi b/runtime/near-evm-runner/tests/build/TBPoolJoinExitNoFee.abi new file mode 100644 index 00000000000..f47c54d1493 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/TBPoolJoinExitNoFee.abi @@ -0,0 +1,302 @@ +[ + { + "constant": true, + "inputs": [], + "name": "BONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "BPOW_PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "EXIT_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "INIT_POOL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_IN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_OUT_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_TOTAL_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BALANCE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "echidna_no_bug_found", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolTotal", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_records_t_balance", + "type": "uint256" + } + ], + "name": "joinAndExitNoFeePool", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/TBPoolJoinExitNoFee.bin b/runtime/near-evm-runner/tests/build/TBPoolJoinExitNoFee.bin new file mode 100644 index 00000000000..a42713dc1ac --- /dev/null +++ b/runtime/near-evm-runner/tests/build/TBPoolJoinExitNoFee.bin @@ -0,0 +1 @@ +60806040526000805460ff1916600117905534801561001d57600080fd5b506106f88061002d6000396000f3fe608060405234801561001057600080fd5b506004361061012e576000357c010000000000000000000000000000000000000000000000000000000090048063b0e0d136116100ca578063c36596a61161008e578063c36596a614610171578063c6580d12146101c9578063e15c7d42146101d1578063e4a28a5214610133578063ec093021146102025761012e565b8063b0e0d136146101a1578063b7b800a4146101a9578063ba019dab146101b1578063bc063e1a146101b9578063bc694ea2146101c15761012e565b806309a3bbe4146101335780631819aa421461014d578063189d00ca14610169578063218b53821461017157806376c7a3c714610179578063867378c5146101815780639381cd2b14610189578063992e2a92146101915780639a86139b14610199575b600080fd5b61013b61020a565b60408051918252519081900360200190f35b610155610217565b604080519115158252519081900360200190f35b61013b610220565b61013b610234565b61013b610240565b61013b610252565b61013b610266565b61013b610273565b61013b61027f565b61013b6102a3565b61013b6102a8565b61013b6102ad565b61013b6102b2565b61013b6102c2565b61013b6102ce565b610200600480360360808110156101e757600080fd5b50803590602081013590604081013590606001356102d3565b005b61013b6103aa565b6802b5e3af16b188000081565b60005460ff1681565b6402540be400670de0b6b3a76400005b0481565b670de0b6b3a764000081565b620f4240670de0b6b3a7640000610230565b64e8d4a51000670de0b6b3a7640000610230565b68056bc75e2d6310000081565b6704a03ce68d21555681565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b600881565b600281565b600181565b600a670de0b6b3a7640000610230565b671bc16d674ec7ffff81565b600081565b60006102e08584846103ba565b905068056bc75e2d631000008311156102f857600080fd5b670de0b6b3a764000083101561030d57600080fd5b678ac7230489e8000082111561032257600080fd5b620f424082101561033257600080fd5b61033c8386610436565b92506103488282610436565b91506000811161035757600080fd5b8383101561036457600080fd5b60006103718585856103ba565b90508083101561038057600080fd5b84861161038c57600080fd5b81811461039857600080fd5b50506000805460ff1916905550505050565b6002670de0b6b3a7640000610230565b6000806103c7858561049a565b90508061041e576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f4d4154485f415050524f580000000000000000000000000000000000604482015290519081900360640190fd5b82600061042b83836105e1565b979650505050505050565b600082820183811015610493576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4144445f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b9392505050565b6000816104f1576040805160e560020a62461bcd02815260206004820152600c60248201527f4552525f4449565f5a45524f0000000000000000000000000000000000000000604482015290519081900360640190fd5b670de0b6b3a764000083028315806105195750670de0b6b3a764000084828161051657fe5b04145b61056d576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b600283048101818110156105cb576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b60008482816105d657fe5b049695505050505050565b60008282028315806105fb5750828482816105f857fe5b04145b61064f576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6706f05b59d3b200008101818110156106b2576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6000670de0b6b3a7640000826105d656fea265627a7a72315820ed2924388694d36bdbe4d7941a0e87d38ab5eeb0b511a244b36f45486e75febf64736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/TBPoolJoinPool.abi b/runtime/near-evm-runner/tests/build/TBPoolJoinPool.abi new file mode 100644 index 00000000000..6f3372807ae --- /dev/null +++ b/runtime/near-evm-runner/tests/build/TBPoolJoinPool.abi @@ -0,0 +1,303 @@ +[ + { + "constant": true, + "inputs": [], + "name": "BONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "BPOW_PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "EXIT_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "INIT_POOL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_IN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_OUT_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_TOTAL_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BALANCE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "echidna_no_bug_found", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolTotal", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_records_t_balance", + "type": "uint256" + } + ], + "name": "joinPool", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/TBPoolJoinPool.bin b/runtime/near-evm-runner/tests/build/TBPoolJoinPool.bin new file mode 100644 index 00000000000..65ea9d6ab16 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/TBPoolJoinPool.bin @@ -0,0 +1 @@ +60806040526000805460ff1916600117905534801561001d57600080fd5b506106298061002d6000396000f3fe608060405234801561001057600080fd5b506004361061012e576000357c0100000000000000000000000000000000000000000000000000000000900480639a86139b116100ca578063bc694ea21161008e578063bc694ea2146101ea578063c36596a614610171578063c6580d12146101f2578063e4a28a5214610133578063ec093021146101fa5761012e565b80639a86139b146101c2578063b0e0d136146101ca578063b7b800a4146101d2578063ba019dab146101da578063bc063e1a146101e25761012e565b806309a3bbe4146101335780631819aa421461014d578063189d00ca14610169578063218b5382146101715780632e6884451461017957806376c7a3c7146101a2578063867378c5146101aa5780639381cd2b146101b2578063992e2a92146101ba575b600080fd5b61013b610202565b60408051918252519081900360200190f35b61015561020f565b604080519115158252519081900360200190f35b61013b610218565b61013b61022c565b61013b6004803603606081101561018f57600080fd5b5080359060208101359060400135610238565b61013b610328565b61013b61033a565b61013b61034e565b61013b61035b565b61013b610367565b61013b61038b565b61013b610390565b61013b610395565b61013b61039a565b61013b6103aa565b61013b6103b6565b61013b6103bb565b6802b5e3af16b188000081565b60005460ff1681565b6402540be400670de0b6b3a76400005b0481565b670de0b6b3a764000081565b600068056bc75e2d6310000083111561025057600080fd5b670de0b6b3a764000083101561026557600080fd5b678ac7230489e8000082111561027a57600080fd5b620f424082101561028a57600080fd5b600061029685856103cb565b9050806102ed576040805160e560020a62461bcd02815260206004820152600f60248201527f4552525f4d4154485f415050524f580000000000000000000000000000000000604482015290519081900360640190fd5b8260006102fa8383610512565b90506000871161030957600080fd5b801561031457600080fd5b50506000805460ff19169055509392505050565b620f4240670de0b6b3a7640000610228565b64e8d4a51000670de0b6b3a7640000610228565b68056bc75e2d6310000081565b6704a03ce68d21555681565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b600881565b600281565b600181565b600a670de0b6b3a7640000610228565b671bc16d674ec7ffff81565b600081565b6002670de0b6b3a7640000610228565b600081610422576040805160e560020a62461bcd02815260206004820152600c60248201527f4552525f4449565f5a45524f0000000000000000000000000000000000000000604482015290519081900360640190fd5b670de0b6b3a7640000830283158061044a5750670de0b6b3a764000084828161044757fe5b04145b61049e576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b600283048101818110156104fc576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b600084828161050757fe5b049695505050505050565b600082820283158061052c57508284828161052957fe5b04145b610580576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6706f05b59d3b200008101818110156105e3576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6000670de0b6b3a76400008261050756fea265627a7a72315820f0f26278e3fc3369c41e852dd72450e07aafa81526408f333ccee8c0e34ee4c364736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/TMath.abi b/runtime/near-evm-runner/tests/build/TMath.abi new file mode 100644 index 00000000000..14a08506688 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/TMath.abi @@ -0,0 +1,834 @@ +[ + { + "constant": true, + "inputs": [], + "name": "BONE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "BPOW_PRECISION", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "EXIT_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "INIT_POOL_SUPPLY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_IN_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_OUT_RATIO", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_TOTAL_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MAX_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BALANCE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BOUND_TOKENS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_BPOW_BASE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_FEE", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MIN_WEIGHT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcInGivenOut", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcOutGivenIn", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcPoolInGivenSingleOut", + "outputs": [ + { + "internalType": "uint256", + "name": "poolAmountIn", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcPoolOutGivenSingleIn", + "outputs": [ + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolAmountOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcSingleInGivenPoolOut", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountIn", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolSupply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalWeight", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "poolAmountIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcSingleOutGivenPoolIn", + "outputs": [ + { + "internalType": "uint256", + "name": "tokenAmountOut", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "tokenBalanceIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenBalanceOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenWeightOut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + } + ], + "name": "calcSpotPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "spotPrice", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getColor", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "a", + "type": "uint256" + } + ], + "name": "calc_btoi", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "a", + "type": "uint256" + } + ], + "name": "calc_bfloor", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "a", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "b", + "type": "uint256" + } + ], + "name": "calc_badd", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "a", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "b", + "type": "uint256" + } + ], + "name": "calc_bsub", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "a", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "b", + "type": "uint256" + } + ], + "name": "calc_bsubSign", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "a", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "b", + "type": "uint256" + } + ], + "name": "calc_bmul", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "a", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "b", + "type": "uint256" + } + ], + "name": "calc_bdiv", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "a", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "n", + "type": "uint256" + } + ], + "name": "calc_bpowi", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "base", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "exp", + "type": "uint256" + } + ], + "name": "calc_bpow", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "uint256", + "name": "base", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "exp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "precision", + "type": "uint256" + } + ], + "name": "calc_bpowApprox", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/TMath.bin b/runtime/near-evm-runner/tests/build/TMath.bin new file mode 100644 index 00000000000..4a14f446467 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/TMath.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b506110df806100206000396000f3fe608060405234801561001057600080fd5b50600436106101e3576000357c010000000000000000000000000000000000000000000000000000000090048063b0e0d13611610117578063c36596a6116100ba578063c36596a614610250578063c6580d12146104a9578063c6b3199d146104b1578063cd094b14146104ce578063e4a28a52146101e8578063ec093021146104f1578063f5f5b148146104f9578063f760324b1461051c578063f8d6aed41461053f576101e3565b8063b0e0d136146103ed578063b58d3e70146103f5578063b65fcf4014610412578063b7b800a41461044e578063ba019dab14610456578063ba9530a61461045e578063bc063e1a14610499578063bc694ea2146104a1576101e3565b806382f652ad1161018a57806382f652ad146102c45780638656b653146102ff578063867378c51461033a578063872289ab1461034257806389298012146103655780639381cd2b146103a0578063992e2a92146103a85780639a86139b146103b0578063a221ee49146103b8576101e3565b806309a3bbe4146101e8578063189d00ca146102025780631bcaf56f1461020a5780631fdee4071461022d578063218b53821461025057806331124372146102585780635c1bbaf71461028157806376c7a3c7146102bc575b600080fd5b6101f061057a565b60408051918252519081900360200190f35b6101f0610587565b6101f06004803603604081101561022057600080fd5b508035906020013561059b565b6101f06004803603604081101561024357600080fd5b50803590602001356105b0565b6101f06105bc565b6101f06004803603606081101561026e57600080fd5b50803590602081013590604001356105c8565b6101f0600480360360c081101561029757600080fd5b5080359060208101359060408101359060608101359060808101359060a001356105dd565b6101f0610695565b6101f0600480360360c08110156102da57600080fd5b5080359060208101359060408101359060608101359060808101359060a001356106a7565b6101f0600480360360c081101561031557600080fd5b5080359060208101359060408101359060608101359060808101359060a00135610766565b6101f0610807565b6101f06004803603604081101561035857600080fd5b508035906020013561081b565b6101f0600480360360c081101561037b57600080fd5b5080359060208101359060408101359060608101359060808101359060a00135610827565b6101f06108d7565b6101f06108e4565b6101f06108f0565b6101f0600480360360a08110156103ce57600080fd5b5080359060208101359060408101359060608101359060800135610914565b6101f0610979565b6101f06004803603602081101561040b57600080fd5b503561097e565b6104356004803603604081101561042857600080fd5b5080359060200135610989565b6040805192835290151560208301528051918290030190f35b6101f06109a2565b6101f06109a7565b6101f0600480360360c081101561047457600080fd5b5080359060208101359060408101359060608101359060808101359060a001356109ac565b6101f0610a2d565b6101f0610a3d565b6101f0610a49565b6101f0600480360360208110156104c757600080fd5b5035610a4e565b6101f0600480360360408110156104e457600080fd5b5080359060200135610a59565b6101f0610a65565b6101f06004803603604081101561050f57600080fd5b5080359060200135610a75565b6101f06004803603604081101561053257600080fd5b5080359060200135610a81565b6101f0600480360360c081101561055557600080fd5b5080359060208101359060408101359060608101359060808101359060a00135610a8d565b6802b5e3af16b188000081565b6402540be400670de0b6b3a76400005b0481565b60006105a78383610b10565b90505b92915050565b60006105a78383610b81565b670de0b6b3a764000081565b60006105d5848484610cc8565b949350505050565b6000806105ea8786610b81565b905060006105f88786610da6565b905060006106068289610b81565b9050600061061c670de0b6b3a764000085610b81565b9050600061062a8383610e03565b90506000610638828e610f26565b90506000610646828f610b10565b9050600061066561065f670de0b6b3a76400008a610b10565b8b610f26565b90506106828261067d670de0b6b3a764000084610b10565b610b81565b9f9e505050505050505050505050505050565b620f4240670de0b6b3a7640000610597565b6000806106b48786610b81565b905060006106ca670de0b6b3a764000083610b10565b905060006106d88286610f26565b905060006106f28761067d670de0b6b3a764000085610b10565b905060006107008c83610b10565b9050600061070e828e610b81565b9050600061071c8288610e03565b9050600061072a828e610f26565b905060006107388e83610b10565b90506107518161067d670de0b6b3a76400006000610b10565b99505050505050505050509695505050505050565b6000806107738786610b81565b9050600061079261078c670de0b6b3a764000084610b10565b85610f26565b905060006107b1866107ac670de0b6b3a764000085610b10565b610f26565b905060006107bf8b83610da6565b905060006107cd828d610b81565b905060006107db8287610e03565b905060006107e9828d610f26565b90506107f5818d610b10565b9e9d5050505050505050505050505050565b64e8d4a51000670de0b6b3a7640000610597565b60006105a78383610da6565b6000806108348786610b81565b9050600061084f856107ac670de0b6b3a76400006000610b10565b9050600061085d8883610b10565b9050600061086b828a610b81565b9050600061088a82610885670de0b6b3a764000088610b81565b610e03565b90506000610898828e610f26565b905060006108a68e83610b10565b905060006108bf61065f670de0b6b3a76400008a610b10565b9050610682826107ac670de0b6b3a764000084610b10565b68056bc75e2d6310000081565b6704a03ce68d21555681565b7f42524f4e5a45000000000000000000000000000000000000000000000000000090565b6000806109218787610b81565b9050600061092f8686610b81565b9050600061093d8383610b81565b9050600061095f670de0b6b3a764000061067d670de0b6b3a764000089610b10565b905061096b8282610f26565b9a9950505050505050505050565b600881565b60006105aa82611008565b6000806109968484611023565b915091505b9250929050565b600281565b600181565b6000806109b98786610b81565b905060006109cf670de0b6b3a764000085610b10565b90506109db8582610f26565b905060006109ed8a61067d8c85610da6565b905060006109fb8285610e03565b90506000610a11670de0b6b3a764000083610b10565b9050610a1d8a82610f26565b9c9b505050505050505050505050565b600a670de0b6b3a7640000610597565b671bc16d674ec7ffff81565b600081565b60006105aa82611045565b60006105a78383610f26565b6002670de0b6b3a7640000610597565b60006105a78383610e03565b60006105a78383611053565b600080610a9a8588610b81565b90506000610aa88786610b10565b90506000610ab68883610b81565b90506000610ac48285610e03565b9050610ad881670de0b6b3a7640000610b10565b9050610aec670de0b6b3a764000087610b10565b9450610b01610afb8c83610f26565b86610b81565b9b9a5050505050505050505050565b6000806000610b1f8585611023565b915091508015610b79576040805160e560020a62461bcd02815260206004820152601160248201527f4552525f5355425f554e444552464c4f57000000000000000000000000000000604482015290519081900360640190fd5b509392505050565b600081610bd8576040805160e560020a62461bcd02815260206004820152600c60248201527f4552525f4449565f5a45524f0000000000000000000000000000000000000000604482015290519081900360640190fd5b670de0b6b3a76400008302831580610c005750670de0b6b3a7640000848281610bfd57fe5b04145b610c54576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b60028304810181811015610cb2576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4449565f494e5445524e414c00000000000000000000000000000000604482015290519081900360640190fd5b6000848281610cbd57fe5b049695505050505050565b6000828180610cdf87670de0b6b3a7640000611023565b9092509050670de0b6b3a764000080600060015b888410610d97576000670de0b6b3a764000082029050600080610d278a610d2285670de0b6b3a7640000610b10565b611023565b91509150610d39876107ac848c610f26565b9650610d458784610b81565b965086610d5457505050610d97565b8715610d5e579315935b8015610d68579315935b8415610d7f57610d788688610b10565b9550610d8c565b610d898688610da6565b95505b505050600101610cf3565b50909998505050505050505050565b6000828201838110156105a7576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4144445f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b60006001831015610e5e576040805160e560020a62461bcd02815260206004820152601560248201527f4552525f42504f575f424153455f544f4f5f4c4f570000000000000000000000604482015290519081900360640190fd5b671bc16d674ec7ffff831115610ebe576040805160e560020a62461bcd02815260206004820152601660248201527f4552525f42504f575f424153455f544f4f5f4849474800000000000000000000604482015290519081900360640190fd5b6000610ec983611008565b90506000610ed78483610b10565b90506000610eed86610ee885611045565b611053565b905081610efe5792506105aa915050565b6000610f0f87846305f5e100610cc8565b9050610f1b8282610f26565b979650505050505050565b6000828202831580610f40575082848281610f3d57fe5b04145b610f94576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6706f05b59d3b20000810181811015610ff7576040805160e560020a62461bcd02815260206004820152601060248201527f4552525f4d554c5f4f564552464c4f5700000000000000000000000000000000604482015290519081900360640190fd5b6000670de0b6b3a764000082610cbd565b6000670de0b6b3a764000061101c83611045565b0292915050565b600080828410611039575050808203600061099b565b5050818103600161099b565b670de0b6b3a7640000900490565b6000806002830661106c57670de0b6b3a764000061106e565b835b90506002830492505b82156105a7576110878485610f26565b9350600283061561109f5761109c8185610f26565b90505b60028304925061107756fea265627a7a72315820ba5c88696fa9a89794667fd441404d301fffcf81987230fc5eda2a8253a37e0a64736f6c634300050c0032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/TToken.abi b/runtime/near-evm-runner/tests/build/TToken.abi new file mode 100644 index 00000000000..12a64cc0432 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/TToken.abi @@ -0,0 +1,311 @@ +[ + { + "inputs": [ + { + "internalType": "string", + "name": "name", + "type": "string" + }, + { + "internalType": "string", + "name": "symbol", + "type": "string" + }, + { + "internalType": "uint8", + "name": "decimals", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "whom", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "burn", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amt", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/runtime/near-evm-runner/tests/build/zombieAttack.bin b/runtime/near-evm-runner/tests/build/zombieAttack.bin new file mode 100644 index 00000000000..dd6826bc417 --- /dev/null +++ b/runtime/near-evm-runner/tests/build/zombieAttack.bin @@ -0,0 +1 @@ +6080604052610a87806100136000396000f3fe6080604052600436106100705760003560e01c8063299fb0431161004e578063299fb043146101af5780632ccb1b30146101c65780639d9f9a6e14610235578063b69ef8a81461028657610070565b80630a84cba514610072578063111e0b12146100e757806314d54f541461015c575b005b61009e6004803603602081101561008857600080fd5b81019080803590602001909291905050506102b1565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b610113600480360360208110156100fd57600080fd5b8101908080359060200190929190505050610390565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b34801561016857600080fd5b506101956004803603602081101561017f57600080fd5b81019080803590602001909291905050506103dc565b604051808215151515815260200191505060405180910390f35b3480156101bb57600080fd5b506101c461041e565b005b3480156101d257600080fd5b5061021f600480360360408110156101e957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610756565b6040518082815260200191505060405180910390f35b61023d6107af565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b34801561029257600080fd5b5061029b610810565b6040518082815260200191505060405180910390f35b6000806000836040516102c390610818565b80828152602001915050604051809103906000f0801580156102e9573d6000803e3d6000fd5b5090508073ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f19350505050158015610332573d6000803e3d6000fd5b508073ffffffffffffffffffffffffffffffffffffffff167fa53ffc4fb91f5ca8287e168fc73db3b0b384a6ca275650f885a1740ef7a0bc1c346040518082815260200191505060405180910390a280348191509250925050915091565b600080600034846040516103a390610818565b808281526020019150506040518091039082f0801580156103c8573d6000803e3d6000fd5b509050905080348191509250925050915091565b60007f379340f64b65a8890c7ea4f6d86d2359beaf41080f36a7ea64b78a2c06eee3f0826040518082815260200191505060405180910390a160019050919050565b7fe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8556002604051806000019050602060405180830381855afa158015610467573d6000803e3d6000fd5b5050506040513d602081101561047c57600080fd5b810190808051906020019092919050505014610500576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f7368613220646967657374206d69736d6174636800000000000000000000000081525060200191505060405180910390fd5b7f9c1185a5c5e9fc54612808977ee8f548b2258d310000000000000000000000006003604051806000019050602060405180830381855afa158015610549573d6000803e3d6000fd5b5050506040515160601b6bffffffffffffffffffffffff1916146105d5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f726d6431363020646967657374206d69736d617463680000000000000000000081525060200191505060405180910390fd5b60006001601b6040516000815260200160405260405180807f11111111111111111111111111111111111111111111111111111111111111118152506020018260ff168152602001807fb9f0bb08640d3c1c00761cdd0121209268f6fd3816bc98b9e6f3cc77bf82b698815250602001807f12ac7a61788a0fdc0e19180f14c945a8e1088a27d92a74dce81c0981fb6447448152506020019150506020604051602081039080840390855afa158015610692573d6000803e3d6000fd5b505050602060405103519050731563915e194d8cfba1943570603f7606a311550873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610753576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f65637265636f766572206d69736d61746368000000000000000000000000000081525060200191505060405180910390fd5b50565b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561079e573d6000803e3d6000fd5b506107a7610810565b905092915050565b6000803373ffffffffffffffffffffffffffffffffffffffff166108fc600234816107d657fe5b049081150290604051600060405180830381858888f19350505050158015610802573d6000803e3d6000fd5b503334819150915091509091565b600047905090565b61022d806108268339019056fe6080604052600660005560405161022d38038061022d8339818101604052602081101561002b57600080fd5b810190808051906020019092919050505080600081905550506101da806100536000396000f3fe60806040526004361061003f5760003560e01c80632ccb1b301461004157806339c117a4146100b0578063b69ef8a8146100df578063e6a899b61461010a575b005b34801561004d57600080fd5b5061009a6004803603604081101561006457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610135565b6040518082815260200191505060405180910390f35b3480156100bc57600080fd5b506100c561018e565b604051808215151515815260200191505060405180910390f35b3480156100eb57600080fd5b506100f4610197565b6040518082815260200191505060405180910390f35b34801561011657600080fd5b5061011f61019f565b6040518082815260200191505060405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561017d573d6000803e3d6000fd5b50610186610197565b905092915050565b60006001905090565b600047905090565b6000548156fea265627a7a72315820f6f44f505670bac22a9333cd975c317fbaa88dc23152a224b1341fc02dd8764264736f6c63430005100032a265627a7a723158205890404b6d6a9f080f4d5156523ec567b299609c5d3e45e4baf5c0ee35c7a68764736f6c63430005100032 \ No newline at end of file From 63d9937eb04ea2ad911c2e4d1d431817b7dd5a27 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Thu, 15 Oct 2020 23:16:00 -0700 Subject: [PATCH 53/61] evm precompile function per byte evm gas, but they are too small --- .../tests/build/PrecompiledFunction.abi | 45 +++++++++++++++++ .../tests/build/PrecompiledFunction.bin | 2 +- .../near-evm-runner/tests/build/SolTests.bin | 2 +- .../tests/contracts/SolTests.sol | 4 +- runtime/runtime-params-estimator/src/cases.rs | 21 ++++++++ .../src/vm_estimator.rs | 49 +++++++++++++++++-- 6 files changed, 114 insertions(+), 9 deletions(-) diff --git a/runtime/near-evm-runner/tests/build/PrecompiledFunction.abi b/runtime/near-evm-runner/tests/build/PrecompiledFunction.abi index 4e03798cbd8..98369784154 100644 --- a/runtime/near-evm-runner/tests/build/PrecompiledFunction.abi +++ b/runtime/near-evm-runner/tests/build/PrecompiledFunction.abi @@ -29,6 +29,21 @@ "stateMutability": "pure", "type": "function" }, + { + "constant": true, + "inputs": [], + "name": "testSha256_100bytes", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, { "constant": true, "inputs": [], @@ -59,6 +74,21 @@ "stateMutability": "pure", "type": "function" }, + { + "constant": true, + "inputs": [], + "name": "testRipemd160_1kb", + "outputs": [ + { + "internalType": "bytes20", + "name": "", + "type": "bytes20" + } + ], + "payable": false, + "stateMutability": "pure", + "type": "function" + }, { "constant": false, "inputs": [ @@ -95,6 +125,21 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "constant": false, + "inputs": [], + "name": "test_identity_100bytes", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, { "constant": true, "inputs": [ diff --git a/runtime/near-evm-runner/tests/build/PrecompiledFunction.bin b/runtime/near-evm-runner/tests/build/PrecompiledFunction.bin index 36be42fb21b..198e45d143f 100644 --- a/runtime/near-evm-runner/tests/build/PrecompiledFunction.bin +++ b/runtime/near-evm-runner/tests/build/PrecompiledFunction.bin @@ -1 +1 @@ -6080604052610627806100136000396000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c80638a6fa9da116100665780638a6fa9da146102a3578063a449e8eb146102c1578063a7d4bbe6146102df578063b7a0961a14610335578063e96cc75c1461037157610093565b80631d82afc714610098578063511636701461011b5780635dfc2e4a14610165578063840f61201461016f575b600080fd5b6100a061038f565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100e05780820151818401526020810190506100c5565b50505050905090810190601f16801561010d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101236103d4565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61016d6104a0565b005b6102286004803603602081101561018557600080fd5b81019080803590602001906401000000008111156101a257600080fd5b8201836020820111156101b457600080fd5b803590602001918460018302840111640100000000831117156101d657600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506104a2565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561026857808201518184015260208101905061024d565b50505050905090810190601f1680156102955780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102ab6104fe565b6040518082815260200191505060405180910390f35b6102c9610503565b6040518082815260200191505060405180910390f35b61031f600480360360608110156102f557600080fd5b81019080803590602001909291908035906020019092919080359060200190929190505050610558565b6040518082815260200191505060405180910390f35b61033d6105a3565b60405180826bffffffffffffffffffffffff19166bffffffffffffffffffffffff1916815260200191505060405180910390f35b6103796105dc565b6040518082815260200191505060405180910390f35b60606103cf6040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152506104a2565b905090565b60006001601b6040516000815260200160405260405180807f11111111111111111111111111111111111111111111111111111111111111118152506020018260ff168152602001807fb9f0bb08640d3c1c00761cdd0121209268f6fd3816bc98b9e6f3cc77bf82b698815250602001807f12ac7a61788a0fdc0e19180f14c945a8e1088a27d92a74dce81c0981fb6447448152506020019150506020604051602081039080840390855afa158015610491573d6000803e3d6000fd5b50505060206040510351905090565b565b60608082516040519080825280601f01601f1916602001820160405280156104d95781602001600182028038833980820191505090505b509050825180602083018260208701600060045af16104f457fe5b5080915050919050565b600090565b60006002604051806000019050602060405180830381855afa15801561052d573d6000803e3d6000fd5b5050506040513d602081101561054257600080fd5b8101908080519060200190929190505050905090565b600060405160208152602080820152602060408201528460608201528360808201528260a082015260208160c08360056107d05a03fa61059757600080fd5b80519150509392505050565b60006003604051806000019050602060405180830381855afa1580156105cd573d6000803e3d6000fd5b5050506040515160601b905090565b60006105ed61303960ad6065610558565b90509056fea265627a7a723158206718ad0764da1eb7d9b1547a52115ca6598c9725f9fc7c88300679d157bbb89c64736f6c63430005100032 \ No newline at end of file +6080604052610c2c806100136000396000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c8063840f612011610071578063840f61201461026d5780638a6fa9da146103a1578063a449e8eb146103bf578063a7d4bbe6146103dd578063b7a0961a14610433578063e96cc75c1461046f576100b4565b806304e87187146100b9578063080e99331461013c5780631d82afc71461015a578063494236eb146101dd57806351163670146102195780635dfc2e4a14610263575b600080fd5b6100c161048d565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101015780820151818401526020810190506100e6565b50505050905090810190601f16801561012e5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101446104b5565b6040518082815260200191505060405180910390f35b610162610512565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101a2578082015181840152602081019050610187565b50505050905090810190601f1680156101cf5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101e5610531565b60405180826bffffffffffffffffffffffff19166bffffffffffffffffffffffff1916815260200191505060405180910390f35b610221610574565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61026b610640565b005b6103266004803603602081101561028357600080fd5b81019080803590602001906401000000008111156102a057600080fd5b8201836020820111156102b257600080fd5b803590602001918460018302840111640100000000831117156102d457600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610642565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561036657808201518184015260208101905061034b565b50505050905090810190601f1680156103935780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103a961069e565b6040518082815260200191505060405180910390f35b6103c76106a3565b6040518082815260200191505060405180910390f35b61041d600480360360608110156103f357600080fd5b810190808035906020019092919080359060200190929190803590602001909291905050506106f8565b6040518082815260200191505060405180910390f35b61043b610743565b60405180826bffffffffffffffffffffffff19166bffffffffffffffffffffffff1916815260200191505060405180910390f35b61047761077c565b6040518082815260200191505060405180910390f35b60606104b06040518060a0016040528060658152602001610b9360659139610642565b905090565b600060026040518080610b93606591396065019050602060405180830381855afa1580156104e7573d6000803e3d6000fd5b5050506040513d60208110156104fc57600080fd5b8101908080519060200190929190505050905090565b606061052c60405180602001604052806000815250610642565b905090565b6000600360405180806107936104009139610400019050602060405180830381855afa158015610565573d6000803e3d6000fd5b5050506040515160601b905090565b60006001601b6040516000815260200160405260405180807f11111111111111111111111111111111111111111111111111111111111111118152506020018260ff168152602001807fb9f0bb08640d3c1c00761cdd0121209268f6fd3816bc98b9e6f3cc77bf82b698815250602001807f12ac7a61788a0fdc0e19180f14c945a8e1088a27d92a74dce81c0981fb6447448152506020019150506020604051602081039080840390855afa158015610631573d6000803e3d6000fd5b50505060206040510351905090565b565b60608082516040519080825280601f01601f1916602001820160405280156106795781602001600182028038833980820191505090505b509050825180602083018260208701600060045af161069457fe5b5080915050919050565b600090565b60006002604051806000019050602060405180830381855afa1580156106cd573d6000803e3d6000fd5b5050506040513d60208110156106e257600080fd5b8101908080519060200190929190505050905090565b600060405160208152602080820152602060408201528460608201528360808201528260a082015260208160c08360056107d05a03fa61073757600080fd5b80519150509392505050565b60006003604051806000019050602060405180830381855afa15801561076d573d6000803e3d6000fd5b5050506040515160601b905090565b600061078d61303960ad60656106f8565b90509056fe6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f707172737475767778797a6162636465666768696a6b6c6d6e6f7071727374757677a265627a7a723158205d2c2b792d903870209e310c124cea57de9949e98fa1104d789ef0f5fea175cd64736f6c63430005100032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/build/SolTests.bin b/runtime/near-evm-runner/tests/build/SolTests.bin index dd6826bc417..b7bacad4583 100644 --- a/runtime/near-evm-runner/tests/build/SolTests.bin +++ b/runtime/near-evm-runner/tests/build/SolTests.bin @@ -1 +1 @@ -6080604052610a87806100136000396000f3fe6080604052600436106100705760003560e01c8063299fb0431161004e578063299fb043146101af5780632ccb1b30146101c65780639d9f9a6e14610235578063b69ef8a81461028657610070565b80630a84cba514610072578063111e0b12146100e757806314d54f541461015c575b005b61009e6004803603602081101561008857600080fd5b81019080803590602001909291905050506102b1565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b610113600480360360208110156100fd57600080fd5b8101908080359060200190929190505050610390565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b34801561016857600080fd5b506101956004803603602081101561017f57600080fd5b81019080803590602001909291905050506103dc565b604051808215151515815260200191505060405180910390f35b3480156101bb57600080fd5b506101c461041e565b005b3480156101d257600080fd5b5061021f600480360360408110156101e957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610756565b6040518082815260200191505060405180910390f35b61023d6107af565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b34801561029257600080fd5b5061029b610810565b6040518082815260200191505060405180910390f35b6000806000836040516102c390610818565b80828152602001915050604051809103906000f0801580156102e9573d6000803e3d6000fd5b5090508073ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f19350505050158015610332573d6000803e3d6000fd5b508073ffffffffffffffffffffffffffffffffffffffff167fa53ffc4fb91f5ca8287e168fc73db3b0b384a6ca275650f885a1740ef7a0bc1c346040518082815260200191505060405180910390a280348191509250925050915091565b600080600034846040516103a390610818565b808281526020019150506040518091039082f0801580156103c8573d6000803e3d6000fd5b509050905080348191509250925050915091565b60007f379340f64b65a8890c7ea4f6d86d2359beaf41080f36a7ea64b78a2c06eee3f0826040518082815260200191505060405180910390a160019050919050565b7fe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8556002604051806000019050602060405180830381855afa158015610467573d6000803e3d6000fd5b5050506040513d602081101561047c57600080fd5b810190808051906020019092919050505014610500576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f7368613220646967657374206d69736d6174636800000000000000000000000081525060200191505060405180910390fd5b7f9c1185a5c5e9fc54612808977ee8f548b2258d310000000000000000000000006003604051806000019050602060405180830381855afa158015610549573d6000803e3d6000fd5b5050506040515160601b6bffffffffffffffffffffffff1916146105d5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f726d6431363020646967657374206d69736d617463680000000000000000000081525060200191505060405180910390fd5b60006001601b6040516000815260200160405260405180807f11111111111111111111111111111111111111111111111111111111111111118152506020018260ff168152602001807fb9f0bb08640d3c1c00761cdd0121209268f6fd3816bc98b9e6f3cc77bf82b698815250602001807f12ac7a61788a0fdc0e19180f14c945a8e1088a27d92a74dce81c0981fb6447448152506020019150506020604051602081039080840390855afa158015610692573d6000803e3d6000fd5b505050602060405103519050731563915e194d8cfba1943570603f7606a311550873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610753576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f65637265636f766572206d69736d61746368000000000000000000000000000081525060200191505060405180910390fd5b50565b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561079e573d6000803e3d6000fd5b506107a7610810565b905092915050565b6000803373ffffffffffffffffffffffffffffffffffffffff166108fc600234816107d657fe5b049081150290604051600060405180830381858888f19350505050158015610802573d6000803e3d6000fd5b503334819150915091509091565b600047905090565b61022d806108268339019056fe6080604052600660005560405161022d38038061022d8339818101604052602081101561002b57600080fd5b810190808051906020019092919050505080600081905550506101da806100536000396000f3fe60806040526004361061003f5760003560e01c80632ccb1b301461004157806339c117a4146100b0578063b69ef8a8146100df578063e6a899b61461010a575b005b34801561004d57600080fd5b5061009a6004803603604081101561006457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610135565b6040518082815260200191505060405180910390f35b3480156100bc57600080fd5b506100c561018e565b604051808215151515815260200191505060405180910390f35b3480156100eb57600080fd5b506100f4610197565b6040518082815260200191505060405180910390f35b34801561011657600080fd5b5061011f61019f565b6040518082815260200191505060405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561017d573d6000803e3d6000fd5b50610186610197565b905092915050565b60006001905090565b600047905090565b6000548156fea265627a7a72315820f6f44f505670bac22a9333cd975c317fbaa88dc23152a224b1341fc02dd8764264736f6c63430005100032a265627a7a723158205890404b6d6a9f080f4d5156523ec567b299609c5d3e45e4baf5c0ee35c7a68764736f6c63430005100032 \ No newline at end of file +6080604052610a87806100136000396000f3fe6080604052600436106100705760003560e01c8063299fb0431161004e578063299fb043146101af5780632ccb1b30146101c65780639d9f9a6e14610235578063b69ef8a81461028657610070565b80630a84cba514610072578063111e0b12146100e757806314d54f541461015c575b005b61009e6004803603602081101561008857600080fd5b81019080803590602001909291905050506102b1565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b610113600480360360208110156100fd57600080fd5b8101908080359060200190929190505050610390565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b34801561016857600080fd5b506101956004803603602081101561017f57600080fd5b81019080803590602001909291905050506103dc565b604051808215151515815260200191505060405180910390f35b3480156101bb57600080fd5b506101c461041e565b005b3480156101d257600080fd5b5061021f600480360360408110156101e957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610756565b6040518082815260200191505060405180910390f35b61023d6107af565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b34801561029257600080fd5b5061029b610810565b6040518082815260200191505060405180910390f35b6000806000836040516102c390610818565b80828152602001915050604051809103906000f0801580156102e9573d6000803e3d6000fd5b5090508073ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f19350505050158015610332573d6000803e3d6000fd5b508073ffffffffffffffffffffffffffffffffffffffff167fa53ffc4fb91f5ca8287e168fc73db3b0b384a6ca275650f885a1740ef7a0bc1c346040518082815260200191505060405180910390a280348191509250925050915091565b600080600034846040516103a390610818565b808281526020019150506040518091039082f0801580156103c8573d6000803e3d6000fd5b509050905080348191509250925050915091565b60007f379340f64b65a8890c7ea4f6d86d2359beaf41080f36a7ea64b78a2c06eee3f0826040518082815260200191505060405180910390a160019050919050565b7fe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8556002604051806000019050602060405180830381855afa158015610467573d6000803e3d6000fd5b5050506040513d602081101561047c57600080fd5b810190808051906020019092919050505014610500576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f7368613220646967657374206d69736d6174636800000000000000000000000081525060200191505060405180910390fd5b7f9c1185a5c5e9fc54612808977ee8f548b2258d310000000000000000000000006003604051806000019050602060405180830381855afa158015610549573d6000803e3d6000fd5b5050506040515160601b6bffffffffffffffffffffffff1916146105d5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f726d6431363020646967657374206d69736d617463680000000000000000000081525060200191505060405180910390fd5b60006001601b6040516000815260200160405260405180807f11111111111111111111111111111111111111111111111111111111111111118152506020018260ff168152602001807fb9f0bb08640d3c1c00761cdd0121209268f6fd3816bc98b9e6f3cc77bf82b698815250602001807f12ac7a61788a0fdc0e19180f14c945a8e1088a27d92a74dce81c0981fb6447448152506020019150506020604051602081039080840390855afa158015610692573d6000803e3d6000fd5b505050602060405103519050731563915e194d8cfba1943570603f7606a311550873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614610753576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260128152602001807f65637265636f766572206d69736d61746368000000000000000000000000000081525060200191505060405180910390fd5b50565b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561079e573d6000803e3d6000fd5b506107a7610810565b905092915050565b6000803373ffffffffffffffffffffffffffffffffffffffff166108fc600234816107d657fe5b049081150290604051600060405180830381858888f19350505050158015610802573d6000803e3d6000fd5b503334819150915091509091565b600047905090565b61022d806108268339019056fe6080604052600660005560405161022d38038061022d8339818101604052602081101561002b57600080fd5b810190808051906020019092919050505080600081905550506101da806100536000396000f3fe60806040526004361061003f5760003560e01c80632ccb1b301461004157806339c117a4146100b0578063b69ef8a8146100df578063e6a899b61461010a575b005b34801561004d57600080fd5b5061009a6004803603604081101561006457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610135565b6040518082815260200191505060405180910390f35b3480156100bc57600080fd5b506100c561018e565b604051808215151515815260200191505060405180910390f35b3480156100eb57600080fd5b506100f4610197565b6040518082815260200191505060405180910390f35b34801561011657600080fd5b5061011f61019f565b6040518082815260200191505060405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f1935050505015801561017d573d6000803e3d6000fd5b50610186610197565b905092915050565b60006001905090565b600047905090565b6000548156fea265627a7a72315820e36da559b208b35510871048d70a0d6e8f4b25035fff6508b43b8eb718e4959e64736f6c63430005100032a265627a7a72315820d93d617e67411c892e102bf050987a9d89de3c461d600c727f04c59dc88f078864736f6c63430005100032 \ No newline at end of file diff --git a/runtime/near-evm-runner/tests/contracts/SolTests.sol b/runtime/near-evm-runner/tests/contracts/SolTests.sol index 1d885bd20b8..cda1f28a318 100644 --- a/runtime/near-evm-runner/tests/contracts/SolTests.sol +++ b/runtime/near-evm-runner/tests/contracts/SolTests.sol @@ -107,8 +107,8 @@ contract PrecompiledFunction { return ripemd160(""); } - function testRipemd160_100bytes() public pure returns (bytes20) { - return ripemd160("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvw"); + function testRipemd160_1kb() public pure returns (bytes20) { + return ripemd160("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij"); } function identity(bytes memory data) public returns (bytes memory) { diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index 5ff64d366c4..a461be22dd8 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -189,14 +189,35 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon "sha256: {}", near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.sha256_cost) ); + println!( + "sha256 per byte: {}", + near_cost_to_evm_gas( + cost.funcall_cost, + cost.precompiled_function_cost.sha256_cost_per_byte + ) + ); println!( "ripemd160: {}", near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.ripemd160_cost) ); + println!( + "ripemd160 per byte: {}", + near_cost_to_evm_gas( + cost.funcall_cost, + cost.precompiled_function_cost.ripemd160_cost_per_byte + ) + ); println!( "identity: {}", near_cost_to_evm_gas(cost.funcall_cost, cost.precompiled_function_cost.identity_cost) ); + println!( + "identity per byte: {}", + near_cost_to_evm_gas( + cost.funcall_cost, + cost.precompiled_function_cost.identity_cost_per_byte + ) + ); println!( "modexp: {}", near_cost_to_evm_gas( diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index 8b782f9577d..c40ed0aa36d 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -308,8 +308,11 @@ type Coef2D = (f64, f64, f64); pub struct EvmPrecompiledFunctionCost { pub ec_recover_cost: Ratio, pub sha256_cost: Ratio, + pub sha256_cost_per_byte: Ratio, pub ripemd160_cost: Ratio, + pub ripemd160_cost_per_byte: Ratio, pub identity_cost: Ratio, + pub identity_cost_per_byte: Ratio, pub modexp_impl_cost: Ratio, // pub bn128AddImplCost: Ratio, // pub bn128MulImplCost: Ratio, @@ -637,6 +640,16 @@ pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiled ), "test_sha256()", ), + measure_evm_precompile_function( + config, + verbose, + &mut context, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_sha256_100bytes::call().0, + ), + "test_sha256_100bytes()", + ), measure_evm_precompile_function( config, verbose, @@ -647,6 +660,16 @@ pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiled ), "test_ripemd160()", ), + measure_evm_precompile_function( + config, + verbose, + &mut context, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_ripemd160_1kb::call().0, + ), + "test_ripemd160_1kb()", + ), measure_evm_precompile_function( config, verbose, @@ -657,6 +680,16 @@ pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiled ), "test_identity()", ), + measure_evm_precompile_function( + config, + verbose, + &mut context, + encode_call_function_args( + precompiled_function_addr, + precompiled_function::functions::test_identity_100bytes::call().0, + ), + "test_identity_100bytes()", + ), measure_evm_precompile_function( config, verbose, @@ -669,13 +702,19 @@ pub fn measure_evm_precompiled(config: &Config, verbose: bool) -> EvmPrecompiled ), ]; - EvmPrecompiledFunctionCost { + println!("measurements: {:?}", measurements); + let r = EvmPrecompiledFunctionCost { ec_recover_cost: measurements[1].cost - measurements[0].cost, sha256_cost: measurements[2].cost - measurements[0].cost, - ripemd160_cost: measurements[3].cost - measurements[0].cost, - identity_cost: measurements[4].cost - measurements[0].cost, - modexp_impl_cost: measurements[5].cost - measurements[0].cost, - } + sha256_cost_per_byte: (measurements[3].cost - measurements[2].cost) / 100, + ripemd160_cost: measurements[4].cost - measurements[0].cost, + ripemd160_cost_per_byte: (measurements[5].cost - measurements[4].cost) / 1024, + identity_cost: measurements[6].cost - measurements[0].cost, + identity_cost_per_byte: (measurements[7].cost - measurements[6].cost) / 100, + modexp_impl_cost: measurements[8].cost - measurements[0].cost, + }; + println!("sha256_cost_per_byte {}", r.sha256_cost_per_byte); + r } pub fn near_cost_to_evm_gas(funcall_cost: Coef, cost: Ratio) -> u64 { From 4cc2940abc827e7c9ee3efa7504d9180e6e58e9f Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 16 Oct 2020 15:18:01 -0700 Subject: [PATCH 54/61] wire in evm gas per byte and update numbers --- runtime/near-evm-runner/src/lib.rs | 58 ++++++++++++------- runtime/near-runtime-fees/src/lib.rs | 26 +++++---- .../src/vm_estimator.rs | 2 - runtime/runtime/src/actions.rs | 1 - .../runtime_group_tools/random_config.rs | 1 + 5 files changed, 53 insertions(+), 35 deletions(-) diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 85d823ea660..9dc175f3b95 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -43,7 +43,8 @@ pub struct EvmContext<'a> { // Different kind of evm operations that result in different gas calculation pub enum EvmOpForGas { - Deploy, + // size of deployed evm contract after it's decoded from hex (0.5x) + Deploy(usize), Funcall, Other, } @@ -486,8 +487,11 @@ impl<'a> EvmContext<'a> { let evm_gas = self.evm_gas_counter.used_gas.as_u64(); self.gas_counter.inc_evm_gas_counter(evm_gas); let gas = match op { - EvmOpForGas::Deploy => { - evm_gas * fee_cfg.deploy_cost_per_evm_gas + fee_cfg.bootstrap_cost + EvmOpForGas::Deploy(decoded_len) => { + // gas per byte is counting hex encoded contract size (solc output, 2x of decoded len) + (decoded_len as u64 * 2) * fee_cfg.deploy_cost_per_byte + + evm_gas * fee_cfg.deploy_cost_per_evm_gas + + fee_cfg.bootstrap_cost } EvmOpForGas::Funcall => { evm_gas * fee_cfg.funcall_cost_per_evm_gas @@ -504,6 +508,7 @@ fn max_evm_gas_from_near_gas( near_gas: Gas, evm_gas_config: &EvmCostConfig, method_name: &str, + decoded_code_size: Option, ) -> Option { match method_name { "deploy_code" => { @@ -511,7 +516,10 @@ fn max_evm_gas_from_near_gas( return None; } Some( - ((near_gas - evm_gas_config.bootstrap_cost) + ((near_gas + - evm_gas_config.bootstrap_cost + - evm_gas_config.deploy_cost_per_byte + * (2 * decoded_code_size.unwrap() as u64)) / evm_gas_config.deploy_cost_per_evm_gas) .into(), ) @@ -551,8 +559,12 @@ pub fn run_evm( prepaid_gas: Gas, is_view: bool, ) -> (Option, Option) { - let evm_gas_result = - max_evm_gas_from_near_gas(prepaid_gas, &fees_config.evm_config, &method_name); + let evm_gas_result = max_evm_gas_from_near_gas( + prepaid_gas, + &fees_config.evm_config, + &method_name, + if &method_name == "deploy_code" { Some(args.len()) } else { None }, + ); if evm_gas_result.is_none() { return ( @@ -583,7 +595,7 @@ pub fn run_evm( let result = match method_name.as_str() { // Change the state methods. - "deploy_code" => context.deploy_code(args).map(|address| { + "deploy_code" => context.deploy_code(args.clone()).map(|address| { #[cfg(feature = "costs_counting")] EVM_LAST_DEPLOYED.with(|addr| { *addr.borrow_mut() = address.clone(); @@ -591,28 +603,32 @@ pub fn run_evm( utils::address_to_vec(&address) }), // TODO: remove this function name if no one is using it. - "call_function" => context.call_function(args), - "call" => context.call_function(args), - "meta_call" => context.meta_call_function(args), - "deposit" => context.deposit(args).map(|balance| utils::u256_to_arr(&balance).to_vec()), - "withdraw" => context.withdraw(args).map(|_| vec![]), - "transfer" => context.transfer(args).map(|_| vec![]), - "create" => context.create_evm(args).map(|_| vec![]), + "call_function" => context.call_function(args.clone()), + "call" => context.call_function(args.clone()), + "meta_call" => context.meta_call_function(args.clone()), + "deposit" => { + context.deposit(args.clone()).map(|balance| utils::u256_to_arr(&balance).to_vec()) + } + "withdraw" => context.withdraw(args.clone()).map(|_| vec![]), + "transfer" => context.transfer(args.clone()).map(|_| vec![]), + "create" => context.create_evm(args.clone()).map(|_| vec![]), // View methods. // TODO: remove this function name if no one is using it. - "view_function_call" => context.view_call_function(args), - "view" => context.view_call_function(args), - "get_code" => context.get_code(args), - "get_storage_at" => context.get_storage_at(args), - "get_nonce" => context.get_nonce(args).map(|nonce| utils::u256_to_arr(&nonce).to_vec()), + "view_function_call" => context.view_call_function(args.clone()), + "view" => context.view_call_function(args.clone()), + "get_code" => context.get_code(args.clone()), + "get_storage_at" => context.get_storage_at(args.clone()), + "get_nonce" => { + context.get_nonce(args.clone()).map(|nonce| utils::u256_to_arr(&nonce).to_vec()) + } "get_balance" => { - context.get_balance(args).map(|balance| utils::u256_to_arr(&balance).to_vec()) + context.get_balance(args.clone()).map(|balance| utils::u256_to_arr(&balance).to_vec()) } _ => Err(VMLogicError::EvmError(EvmError::MethodNotFound)), }; context .pay_gas_from_evm_gas(match method_name.as_str() { - "deploy_code" => EvmOpForGas::Deploy, + "deploy_code" => EvmOpForGas::Deploy(args.len()), "call_function" => EvmOpForGas::Funcall, _ => EvmOpForGas::Other, }) diff --git a/runtime/near-runtime-fees/src/lib.rs b/runtime/near-runtime-fees/src/lib.rs index 66ce0b62c1a..1dc6216f782 100644 --- a/runtime/near-runtime-fees/src/lib.rs +++ b/runtime/near-runtime-fees/src/lib.rs @@ -158,6 +158,8 @@ pub struct EvmCostConfig { pub bootstrap_cost: Gas, /// For every unit of gas used by evm in deploy evm contract, equivalent near gas cost pub deploy_cost_per_evm_gas: Gas, + /// For every byte of evm contract, result near gas cost + pub deploy_cost_per_byte: Gas, /// For bootstrapped evm, base cost to invoke a contract function pub funcall_cost_base: Gas, /// For every unit of gas used by evm in funcall, equivalent near gas cost @@ -264,18 +266,19 @@ impl Default for RuntimeFeesConfig { burnt_gas_reward: Rational::new(3, 10), pessimistic_gas_price_inflation_ratio: Rational::new(103, 100), evm_config: EvmCostConfig { - // Got inside emu-cost docker, numbers very slightly in different runs: + // Got inside emu-cost docker, numbers differ slightly in different runs: // cd /host/nearcore/runtime/near-evm-runner/tests - // ../../runtime-params-estimator/emu-cost/counter_plugin/qemu-x86_64 -cpu Westmere-v1 -plugin file=../../runtime-params-estimator/emu-cost/counter_plugin/libcounter.so ../../../target/release/runtime-params-estimator --home /tmp/data --accounts-num 2000 --iters 1 --warmup-iters 1 --evm-only - bootstrap_cost: 29513857500, - deploy_cost_per_evm_gas: 29008902, - funcall_cost_base: 108890282500, - funcall_cost_per_evm_gas: 35070059, - ecrecover_cost: 8005, - sha256_cost: 215, - ripemd160_cost: 200, - identity_cost: 591, - modexp_cost: 330, + // ../../runtime-params-estimator/emu-cost/counter_plugin/qemu-x86_64 -cpu Westmere-v1 -plugin file=../../runtime-params-estimator/emu-cost/counter_plugin/libcounter.so ../../../target/release/runtime-params-estimator --home /tmp/data --accounts-num 200000 --iters 1 --warmup-iters 1 --evm-only + bootstrap_cost: 701340443790, + deploy_cost_per_evm_gas: 2428031, + deploy_cost_per_byte: 1328305, + funcall_cost_base: 675044695000, + funcall_cost_per_evm_gas: 73398498, + ecrecover_cost: 3825, + sha256_cost: 89, + ripemd160_cost: 82, + identity_cost: 182, + modexp_cost: 144, }, evm_deposit: EVM_DEPOSIT, } @@ -316,6 +319,7 @@ impl RuntimeFeesConfig { evm_config: EvmCostConfig { bootstrap_cost: 0, deploy_cost_per_evm_gas: 0, + deploy_cost_per_byte: 0, funcall_cost_base: 0, funcall_cost_per_evm_gas: 0, ecrecover_cost: 0, diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index c40ed0aa36d..bfa311f5849 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -279,8 +279,6 @@ fn deploy_evm_contract( let counts = total_transactions(config) as u64; evm_gas /= counts; - // evm_gas is times gas spent, so does cost - // Some(EvmCost { evm_gas, cost: Ratio::new(total_cost, counts) }) Some(EvmCost { evm_gas, size: code.len() as u64, cost: Ratio::new(total_cost, counts) }) } diff --git a/runtime/runtime/src/actions.rs b/runtime/runtime/src/actions.rs index 720d755554a..4490f5e8061 100644 --- a/runtime/runtime/src/actions.rs +++ b/runtime/runtime/src/actions.rs @@ -67,7 +67,6 @@ pub(crate) fn execute_function_call( is_view, ) } else { - println!("wasm!!!!"); let code = match runtime_ext.get_code(account.code_hash) { Ok(Some(code)) => code, Ok(None) => { diff --git a/runtime/runtime/tests/runtime_group_tools/random_config.rs b/runtime/runtime/tests/runtime_group_tools/random_config.rs index 1aeeccfb0ec..e0ba6b09af3 100644 --- a/runtime/runtime/tests/runtime_group_tools/random_config.rs +++ b/runtime/runtime/tests/runtime_group_tools/random_config.rs @@ -49,6 +49,7 @@ pub fn random_config() -> RuntimeConfig { evm_config: EvmCostConfig { bootstrap_cost: rng.next_u64() % 1000, deploy_cost_per_evm_gas: rng.next_u64() % 1000, + deploy_cost_per_byte: rng.next_u64() % 1000, funcall_cost_base: rng.next_u64() % 1000, funcall_cost_per_evm_gas: rng.next_u64() % 1000, ecrecover_cost: rng.next_u64() % 1000, From d03d30a359e73ef2c9357ae3a4e68945b5f60199 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 19 Oct 2020 16:02:54 -0700 Subject: [PATCH 55/61] avoid pay evm bootstrap fee when evm is not started --- runtime/near-evm-runner/src/lib.rs | 39 ++++++++++++------------------ 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 0dbe3a7b028..01dee49af9c 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -64,11 +64,6 @@ fn address_to_key(prefix: KeyPrefix, address: &H160) -> Vec { result } -#[cfg(feature = "costs_counting")] -thread_local! { - static EVM_LAST_DEPLOYED: std::cell::RefCell = Default::default(); -} - impl<'a> EvmState for EvmContext<'a> { fn code_at(&self, address: &H160) -> Result>> { self.ext @@ -626,16 +621,20 @@ pub fn run_evm( let result = match method_name.as_str() { // Change the state methods. "deploy_code" => context.deploy_code(args.clone()).map(|address| { - #[cfg(feature = "costs_counting")] - EVM_LAST_DEPLOYED.with(|addr| { - *addr.borrow_mut() = address.clone(); - }); + context.pay_gas_from_evm_gas(EvmOpForGas::Deploy(args.len())).unwrap(); utils::address_to_vec(&address) }), // TODO: remove this function name if no one is using it. - "call_function" => context.call_function(args.clone()), - "call" => context.call_function(args.clone()), - "meta_call" => context.meta_call_function(args.clone()), + "call_function" | "call" => { + let r = context.call_function(args.clone()); + context.pay_gas_from_evm_gas(EvmOpForGas::Funcall).unwrap(); + r + } + "meta_call" => { + let r = context.meta_call_function(args.clone()); + context.pay_gas_from_evm_gas(EvmOpForGas::Other).unwrap(); + r + } "deposit" => { context.deposit(args.clone()).map(|balance| utils::u256_to_arr(&balance).to_vec()) } @@ -644,8 +643,11 @@ pub fn run_evm( "create" => context.create_evm(args.clone()).map(|_| vec![]), // View methods. // TODO: remove this function name if no one is using it. - "view_function_call" => context.view_call_function(args.clone()), - "view" => context.view_call_function(args.clone()), + "view_function_call" | "view" => { + let r = context.view_call_function(args.clone()); + context.pay_gas_from_evm_gas(EvmOpForGas::Other).unwrap(); + r + } "get_code" => context.get_code(args.clone()), "get_storage_at" => context.get_storage_at(args.clone()), "get_nonce" => { @@ -656,15 +658,6 @@ pub fn run_evm( } _ => Err(VMLogicError::EvmError(EvmError::MethodNotFound)), }; - context - .pay_gas_from_evm_gas(match method_name.as_str() { - "deploy_code" => EvmOpForGas::Deploy(args.len()), - "call_function" => EvmOpForGas::Funcall, - _ => EvmOpForGas::Other, - }) - // It's not possible deduct near gas underflow, because even use full evm gas it's less than prepaid near gas - // If full evm gas isn't enough for evm operation, evm will revert result and all near gas is used to pay for evm gas - .unwrap(); match result { Ok(value) => { From bcb235856ac8a9a4c8bd9db377e6770bb2cdcf58 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Tue, 20 Oct 2020 21:22:29 -0700 Subject: [PATCH 56/61] do not measure action receipt fee for evm as they are deduct separately --- runtime/runtime-params-estimator/src/cases.rs | 7 +++---- .../runtime-params-estimator/src/vm_estimator.rs | 16 +++++----------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/runtime/runtime-params-estimator/src/cases.rs b/runtime/runtime-params-estimator/src/cases.rs index a461be22dd8..b8670b5d2d3 100644 --- a/runtime/runtime-params-estimator/src/cases.rs +++ b/runtime/runtime-params-estimator/src/cases.rs @@ -22,8 +22,7 @@ use crate::testbed::RuntimeTestbed; use crate::testbed_runners::GasMetric; use crate::testbed_runners::{get_account_id, measure_actions, measure_transactions, Config}; use crate::vm_estimator::{ - action_receipt_fee, cost_of_evm, cost_per_op, cost_to_compile, load_and_compile, - near_cost_to_evm_gas, + cost_of_evm, cost_per_op, cost_to_compile, load_and_compile, near_cost_to_evm_gas, }; use near_runtime_fees::{ AccessKeyCreationConfig, ActionCreationConfig, DataReceiptCreationConfig, Fee, @@ -171,13 +170,13 @@ pub fn run(mut config: Config, only_compile: bool, only_evm: bool) -> RuntimeCon let cost = cost_of_evm(&config, true); println!( "EVM base deploy (and init evm instance) cost: {}, deploy cost per EVM gas: {}, deploy cost per byte: {}", - ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.2).unwrap()) - action_receipt_fee(), + ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.2).unwrap()), ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.0).unwrap()), ratio_to_gas(config.metric, Ratio::::from_f64(cost.deploy_cost.1).unwrap()), ); println!( "EVM base function call cost: {}, function call cost per EVM gas: {}", - ratio_to_gas(config.metric, cost.funcall_cost.1) - action_receipt_fee(), + ratio_to_gas(config.metric, cost.funcall_cost.1), ratio_to_gas(config.metric, cost.funcall_cost.0), ); println!("EVM precompiled function evm gas:"); diff --git a/runtime/runtime-params-estimator/src/vm_estimator.rs b/runtime/runtime-params-estimator/src/vm_estimator.rs index bfa311f5849..451015d866b 100644 --- a/runtime/runtime-params-estimator/src/vm_estimator.rs +++ b/runtime/runtime-params-estimator/src/vm_estimator.rs @@ -267,8 +267,11 @@ fn deploy_evm_contract( for block_size in config.block_sizes.clone() { let block: Vec<_> = (0..block_size).map(|_| f()).collect(); let mut testbed = testbed.lock().unwrap(); - let start = start_count(config.metric); testbed.process_block(&block, allow_failures); + // process_block create action receipt for FunctionCall Action, not count as gas used in evm. + // In real node, action receipt cost is deducted in validate_tx -> tx_cost so should only count + // and deduct evm execution cost + let start = start_count(config.metric); testbed.process_blocks_until_no_receipts(allow_failures); let cost = end_count(config.metric, &start); total_cost += cost; @@ -452,15 +455,6 @@ pub fn measure_evm_funcall( measurements_to_coef(measurements, true) } -pub fn action_receipt_fee() -> u64 { - // Because run --only-evm, don't have aggreggated metrics of Metric::noop and Metric::Receipt, so just deduct - // ReceiptFees::ActionFunctionCallBase from last run without --only-evm, which is this function returns - // TODO: it should be updated to only function_call_cost, after #3279 is merged into upstream branch: evm-precompile - let fees = RuntimeFeesConfig::default(); - - fees.action_receipt_creation_config.execution + fees.action_receipt_creation_config.send_not_sir -} - pub fn measure_evm_precompile_function( config: &Config, verbose: bool, @@ -578,8 +572,8 @@ pub fn measure_evm_function) -> Vec + Copy>( for block_size in config.block_sizes.clone() { let block: Vec<_> = (0..block_size).map(|_| f()).collect(); let mut testbed = testbed.lock().unwrap(); - let start = start_count(config.metric); testbed.process_block(&block, allow_failures); + let start = start_count(config.metric); testbed.process_blocks_until_no_receipts(allow_failures); let cost = end_count(config.metric, &start); total_cost += cost; From af979448dc9221447cf1fb13d22bac30ae4c8c2c Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Wed, 21 Oct 2020 08:57:57 -0700 Subject: [PATCH 57/61] new numbers --- runtime/near-runtime-fees/src/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/runtime/near-runtime-fees/src/lib.rs b/runtime/near-runtime-fees/src/lib.rs index 41149db3333..8d004a87c05 100644 --- a/runtime/near-runtime-fees/src/lib.rs +++ b/runtime/near-runtime-fees/src/lib.rs @@ -270,16 +270,16 @@ impl Default for RuntimeFeesConfig { // Got inside emu-cost docker, numbers differ slightly in different runs: // cd /host/nearcore/runtime/near-evm-runner/tests // ../../runtime-params-estimator/emu-cost/counter_plugin/qemu-x86_64 -cpu Westmere-v1 -plugin file=../../runtime-params-estimator/emu-cost/counter_plugin/libcounter.so ../../../target/release/runtime-params-estimator --home /tmp/data --accounts-num 200000 --iters 1 --warmup-iters 1 --evm-only - bootstrap_cost: 701340443790, - deploy_cost_per_evm_gas: 2428031, - deploy_cost_per_byte: 1328305, - funcall_cost_base: 675044695000, - funcall_cost_per_evm_gas: 73398498, - ecrecover_cost: 3825, - sha256_cost: 89, - ripemd160_cost: 82, - identity_cost: 182, - modexp_cost: 144, + bootstrap_cost: 373945633846, + deploy_cost_per_evm_gas: 3004467, + deploy_cost_per_byte: 2732257, + funcall_cost_base: 300126401250, + funcall_cost_per_evm_gas: 116076934, + ecrecover_cost: 2418, + sha256_cost: 56, + ripemd160_cost: 52, + identity_cost: 115, + modexp_cost: 90, }, evm_deposit: EVM_DEPOSIT, } From 702b6d162faa12005fa6d9578b96518465a34353 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Fri, 30 Oct 2020 15:04:42 -0700 Subject: [PATCH 58/61] features for runtime-params-estimator --- runtime/runtime-params-estimator/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/runtime-params-estimator/Cargo.toml b/runtime/runtime-params-estimator/Cargo.toml index daee599678c..58d61fe6876 100644 --- a/runtime/runtime-params-estimator/Cargo.toml +++ b/runtime/runtime-params-estimator/Cargo.toml @@ -24,7 +24,7 @@ near-vm-logic = {path = "../../runtime/near-vm-logic" , features = ["costs_count near-vm-runner = {path = "../../runtime/near-vm-runner" , features = ["costs_counting", "no_cache", "no_cpu_compatibility_checks", "wasmtime_vm" ]} node-runtime = { path = "../../runtime/runtime" , features = ["costs_counting", "no_cache"]} near-store = { path = "../../core/store", features = ["no_cache", "single_thread_rocksdb"]} -near-primitives = { path = "../../core/primitives" } +near-primitives = { path = "../../core/primitives", features = ["protocol_feature_evm"] } testlib = { path = "../../test-utils/testlib" } state-viewer = { path = "../../test-utils/state-viewer" } neard = { path = "../../neard" } From 29fa4df2248b9790572f7434069eb63ad76f6764 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 2 Nov 2020 13:59:03 -0800 Subject: [PATCH 59/61] evm features works in runtime-param-estimator --- core/primitives/src/version.rs | 4 +++- neard/Cargo.toml | 2 +- runtime/runtime-params-estimator/Cargo.toml | 4 ++-- runtime/runtime/Cargo.toml | 1 + runtime/runtime/src/actions.rs | 5 +++++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/primitives/src/version.rs b/core/primitives/src/version.rs index c0f2aef157a..922fdee71ff 100644 --- a/core/primitives/src/version.rs +++ b/core/primitives/src/version.rs @@ -108,7 +108,9 @@ lazy_static! { let nightly_protocol_features_to_version_mapping: HashMap< ProtocolFeature, ProtocolVersion, - > = vec![(ProtocolFeature::ForwardChunkParts, 41)].into_iter().collect(); + > = vec![(ProtocolFeature::ForwardChunkParts, 41), (ProtocolFeature::EVM, 41)] + .into_iter() + .collect(); for (stable_protocol_feature, stable_protocol_version) in STABLE_PROTOCOL_FEATURES_TO_VERSION_MAPPING.iter() { diff --git a/neard/Cargo.toml b/neard/Cargo.toml index 427908647d8..aa2e65080f9 100644 --- a/neard/Cargo.toml +++ b/neard/Cargo.toml @@ -59,7 +59,7 @@ no_cache = ["node-runtime/no_cache", "near-store/no_cache", "near-chain/no_cache delay_detector = ["near-client/delay_detector"] rosetta_rpc = ["near-rosetta-rpc"] protocol_feature_forward_chunk_parts = ["near-client/protocol_feature_forward_chunk_parts"] -protocol_feature_evm = ["near-primitives/protocol_feature_evm"] +protocol_feature_evm = ["node-runtime/protocol_feature_evm", "near-primitives/protocol_feature_evm"] nightly_protocol_features = ["nightly_protocol", "protocol_feature_forward_chunk_parts", "near-client/nightly_protocol_features", "protocol_feature_evm"] nightly_protocol = ["near-primitives/nightly_protocol"] diff --git a/runtime/runtime-params-estimator/Cargo.toml b/runtime/runtime-params-estimator/Cargo.toml index 58d61fe6876..88cf5b86a17 100644 --- a/runtime/runtime-params-estimator/Cargo.toml +++ b/runtime/runtime-params-estimator/Cargo.toml @@ -22,9 +22,9 @@ near-runtime-fees = { path = "../../runtime/near-runtime-fees" } near-crypto = { path = "../../core/crypto" } near-vm-logic = {path = "../../runtime/near-vm-logic" , features = ["costs_counting"]} near-vm-runner = {path = "../../runtime/near-vm-runner" , features = ["costs_counting", "no_cache", "no_cpu_compatibility_checks", "wasmtime_vm" ]} -node-runtime = { path = "../../runtime/runtime" , features = ["costs_counting", "no_cache"]} +node-runtime = { path = "../../runtime/runtime" , features = ["costs_counting", "no_cache", "protocol_feature_evm"]} near-store = { path = "../../core/store", features = ["no_cache", "single_thread_rocksdb"]} -near-primitives = { path = "../../core/primitives", features = ["protocol_feature_evm"] } +near-primitives = { path = "../../core/primitives", features = ["protocol_feature_evm", "protocol_feature_forward_chunk_parts", "nightly_protocol"] } testlib = { path = "../../test-utils/testlib" } state-viewer = { path = "../../test-utils/state-viewer" } neard = { path = "../../neard" } diff --git a/runtime/runtime/Cargo.toml b/runtime/runtime/Cargo.toml index fa5d1e22564..8b0e57cd6e2 100644 --- a/runtime/runtime/Cargo.toml +++ b/runtime/runtime/Cargo.toml @@ -36,6 +36,7 @@ near-vm-errors = { path = "../../runtime/near-vm-errors" } [features] default = [] dump_errors_schema = ["near-vm-errors/dump_errors_schema"] +protocol_feature_evm = ["near-primitives/protocol_feature_evm"] # Use this feature to enable counting of fees and costs applied. costs_counting = ["near-vm-logic/costs_counting", "near-vm-runner/costs_counting"] diff --git a/runtime/runtime/src/actions.rs b/runtime/runtime/src/actions.rs index a4786236cee..ecc9f827a1f 100644 --- a/runtime/runtime/src/actions.rs +++ b/runtime/runtime/src/actions.rs @@ -50,6 +50,11 @@ pub(crate) fn execute_function_call( is_view: bool, ) -> (Option, Option) { let account_id = runtime_ext.account_id(); + if checked_feature!("protocol_feature_evm", EVM, runtime_ext.protocol_version()) { + println!("has protocol_feature_evm"); + } else { + println!("does not have protocol_feature_evm"); + } if checked_feature!("protocol_feature_evm", EVM, runtime_ext.protocol_version()) && is_account_evm(&account_id) { From b52d37a88f0ba3fb34d409931428b422157fa57b Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 2 Nov 2020 13:59:34 -0800 Subject: [PATCH 60/61] undo debug print --- runtime/runtime/src/actions.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/runtime/runtime/src/actions.rs b/runtime/runtime/src/actions.rs index ecc9f827a1f..a4786236cee 100644 --- a/runtime/runtime/src/actions.rs +++ b/runtime/runtime/src/actions.rs @@ -50,11 +50,6 @@ pub(crate) fn execute_function_call( is_view: bool, ) -> (Option, Option) { let account_id = runtime_ext.account_id(); - if checked_feature!("protocol_feature_evm", EVM, runtime_ext.protocol_version()) { - println!("has protocol_feature_evm"); - } else { - println!("does not have protocol_feature_evm"); - } if checked_feature!("protocol_feature_evm", EVM, runtime_ext.protocol_version()) && is_account_evm(&account_id) { From 838acfd0a4f5db9f57ed5351ecfc1f3fedff86fe Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Mon, 2 Nov 2020 14:00:22 -0800 Subject: [PATCH 61/61] undo disable lto --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 48b5b147da5..5c37117cfd0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,8 +77,8 @@ neard = { path = "./neard"} testlib = { path = "./test-utils/testlib" } [profile.release] -# lto = true # Enable full link-time optimization. -# codegen-units = 1 # Use only 1 codegen-unit to enable full optimizations. +lto = true # Enable full link-time optimization. +codegen-units = 1 # Use only 1 codegen-unit to enable full optimizations. overflow-checks = true [profile.bench]