Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
call gas on new_account fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Oct 7, 2021
1 parent d72296e commit e62119a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 294 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

target
.vscode


bin/revm-ethereum-tests/temp_folder
4 changes: 2 additions & 2 deletions bin/revm-ethereum-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::{path::PathBuf};
use serde::de::Error;

pub fn main() {
//let folder_path = "./tests/GeneralStateTests";
let folder_path = "./temp_folder";
let folder_path = "./tests/GeneralStateTests";
//let folder_path = "./temp_folder";
let mut test_files = runner::find_all_json_tests(PathBuf::from(folder_path));

//test_files.truncate(300); //for test only
Expand Down
260 changes: 0 additions & 260 deletions bin/revm-ethereum-tests/temp_folder/callcodeNonConst.json

This file was deleted.

34 changes: 17 additions & 17 deletions src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ pub trait Handler {
/// Get global const context of evm execution
fn global_env(&self) -> &GlobalEnv;

/// load account. None it does not exist. Some value true is_cold.
/// load account. Returns (is_cold,is_new_account)
fn load_account(&mut self, address: H160) -> (bool, bool);
/// Get environmental block hash.
fn block_hash(&mut self, number: U256) -> H256;
Expand Down Expand Up @@ -545,18 +545,18 @@ pub trait Handler {

pub trait Tracing {
fn trace_opcode(&mut self, opcode: OpCode, machine: &Machine) {
println!(
"OPCODE: {:?}({:?}) PC:{}, gas:{:#x}({}), refund:{:#x}({}) Stack:{:?}, Data:",
opcode,
opcode as u8,
machine.program_counter(),
machine.gas.remaining(),
machine.gas.remaining(),
machine.gas.refunded(),
machine.gas.refunded(),
machine.stack.data(),
// hex::encode(machine.memory.data()),
);
// println!(
// "OPCODE: {:?}({:?}) PC:{}, gas:{:#x}({}), refund:{:#x}({}) Stack:{:?}, Data:",
// opcode,
// opcode as u8,
// machine.program_counter(),
// machine.gas.remaining(),
// machine.gas.remaining(),
// machine.gas.refunded(),
// machine.gas.refunded(),
// machine.stack.data(),
// // hex::encode(machine.memory.data()),
// );
}
fn trace_call(
&mut self,
Expand All @@ -566,10 +566,10 @@ pub trait Tracing {
input: &Bytes,
is_static: bool,
) {
println!(
"SM CALL: {:?},context:{:?}, is_static:{:?}, transfer:{:?}, input:{:?}",
call, context, is_static, transfer, input,
);
// println!(
// "SM CALL: {:?},context:{:?}, is_static:{:?}, transfer:{:?}, input:{:?}",
// call, context, is_static, transfer, input,
// );
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/opcode/gas/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,17 @@ pub fn selfdestruct_cost<SPEC: Spec>(res: SelfDestructResult) -> u64 {

pub fn call_cost<SPEC: Spec>(
value: U256,
// None-> not exists. Some -> true. Value is_cold or not.
exist: bool,
new_account: bool,
is_cold: bool,
is_call_or_callcode: bool,
is_call_or_staticcall: bool,
//new_account: bool,
) -> u64 {
let transfers_value = value != U256::default();
account_access_cost::<SPEC>(is_cold, SPEC::GAS_CALL)
+ xfer_cost(is_call_or_callcode, transfers_value)
+ new_cost::<SPEC>(
is_call_or_staticcall,
exist,
new_account,
transfers_value,
)
}
Expand Down
8 changes: 2 additions & 6 deletions src/opcode/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,12 @@ pub fn call<H: ExtHandler, SPEC: Spec>(

let to = to.into();
// load account and calculate gas cost.
let (is_cold,exists) = handler.load_account(to);
let (is_cold,new_account) = handler.load_account(to);
gas!(
machine,
gas::call_cost::<SPEC>(
value,
exists,
new_account,
is_cold,
matches!(scheme, CallScheme::Call | CallScheme::CallCode),
matches!(scheme, CallScheme::Call | CallScheme::StaticCall),
Expand Down Expand Up @@ -517,7 +517,6 @@ pub fn call<H: ExtHandler, SPEC: Spec>(
machine.gas.erase_cost(gas.remaining());
// add refunded gas from subcall
machine.gas.record_refund(gas.refunded());
println!("Succedd");
match machine.memory.copy_large(
out_offset,
U256::zero(),
Expand All @@ -535,7 +534,6 @@ pub fn call<H: ExtHandler, SPEC: Spec>(
}
}
ExitReason::Revert(_) => {
println!("revert");
// return remaining gas not used in subcall
machine.gas.erase_cost(gas.remaining());

Expand All @@ -551,13 +549,11 @@ pub fn call<H: ExtHandler, SPEC: Spec>(
Control::Continue
}
ExitReason::Error(e) => {
println!("error: {:?}",e);
push_u256!(machine, U256::zero());

Control::Continue
}
ExitReason::Fatal(e) => {
println!("fatal");
push_u256!(machine, U256::zero());

Control::Exit(e.into())
Expand Down
10 changes: 5 additions & 5 deletions src/subroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ impl SubRoutine {
target: H160,
db: &mut DB,
) -> SelfDestructResult {
let (is_cold, exists) = self.load_account_exist(target, db);
let (is_cold, new_account) = self.load_account_exist(target, db);
let exists = !new_account;
// transfer all the balance
let acc = self.state.get_mut(&address).unwrap();
let value = acc.info.balance;
Expand Down Expand Up @@ -459,7 +460,7 @@ impl SubRoutine {
&& info.nonce == 0
&& info.code.unwrap_or_default() == Bytes::default();
//&& info.code_hash.unwrap_or_default() == H256::default();
(is_cold, !exists)
(is_cold, exists)
}

pub fn load_code<DB: Database>(&mut self, address: H160, db: &mut DB) -> (&mut Account, bool) {
Expand Down Expand Up @@ -518,7 +519,7 @@ impl SubRoutine {
(value, true)
}
};
println!("sload:acc{:?}:{:?}=>{:?}",address,index,load);
//println!("sload:acc{:?}:{:?}=>{:?}",address,index,load);
load
}

Expand All @@ -533,7 +534,7 @@ impl SubRoutine {
) -> (H256, H256, H256, bool) {
// assume that acc exists and load the slot.
let (present, is_cold) = self.sload(address, index, db);
println!("sstore:{:?}:{:?}({:?})=>{:?}::{:?}",address,index,present,new,is_cold);
//println!("sstore:{:?}:{:?}({:?})=>{:?}::{:?}",address,index,present,new,is_cold);
let acc = self.state.get_mut(&address).unwrap();
// if there is no original value in dirty return present valuem that is our original.
let original = if let Some(original) = acc.filth.original_slot(index) {
Expand All @@ -543,7 +544,6 @@ impl SubRoutine {
};
// new value is same as present, we dont need to do anything
if present == new {
println!("present and new are same");
return (original, present, new, is_cold);
}

Expand Down

0 comments on commit e62119a

Please sign in to comment.