Fix executive for out of gas builtins.

This commit is contained in:
Gav Wood 2016-01-15 13:08:37 +01:00
parent bf4669eaff
commit 0c39a83365
3 changed files with 24 additions and 43 deletions

View File

@ -21,8 +21,6 @@ pub struct Substate {
logs: Vec<LogEntry>,
/// Refund counter of SSTORE nonzero->zero.
refunds_count: U256,
/// True if transaction, or one of its subcalls runs out of gas.
excepted: bool,
/// Created contracts.
contracts_created: Vec<Address>
}
@ -34,7 +32,6 @@ impl Substate {
suicides: HashSet::new(),
logs: vec![],
refunds_count: U256::zero(),
excepted: false,
contracts_created: vec![]
}
}
@ -43,11 +40,8 @@ impl Substate {
self.suicides.extend(s.suicides.into_iter());
self.logs.extend(s.logs.into_iter());
self.refunds_count = self.refunds_count + s.refunds_count;
self.excepted |= s.excepted;
self.contracts_created.extend(s.contracts_created.into_iter());
}
pub fn excepted(&self) -> bool { self.excepted }
}
/// Transaction execution receipt.
@ -68,8 +62,6 @@ pub struct Executed {
pub cumulative_gas_used: U256,
/// Vector of logs generated by transaction.
pub logs: Vec<LogEntry>,
/// Execution ended running out of gas.
pub excepted: bool,
/// Addresses of contracts created during execution of transaction.
/// Ordered from earliest creation.
///
@ -208,8 +200,8 @@ impl<'a> Executive<'a> {
},
// just drain the whole gas
false => {
substate.excepted = true;
Ok(U256::zero())
self.state.revert(backup);
Err(evm::Error::OutOfGas)
}
}
} else if params.code.len() > 0 {
@ -296,7 +288,6 @@ impl<'a> Executive<'a> {
refunded: refund,
cumulative_gas_used: self.info.gas_used + gas_used,
logs: substate.logs,
excepted: substate.excepted,
contracts_created: substate.contracts_created
})
},
@ -307,7 +298,6 @@ impl<'a> Executive<'a> {
refunded: U256::zero(),
cumulative_gas_used: self.info.gas_used + t.gas,
logs: vec![],
excepted: true,
contracts_created: vec![]
})
}
@ -318,7 +308,6 @@ impl<'a> Executive<'a> {
// TODO: handle other evm::Errors same as OutOfGas once they are implemented
match result {
&Err(evm::Error::OutOfGas) => {
substate.excepted = true;
self.state.revert(backup);
},
&Ok(_) | &Err(evm::Error::Internal) => substate.accrue(un_substate)
@ -464,7 +453,7 @@ impl<'a> Ext for Externalities<'a> {
let gas = *gas - gas_cost;
// if balance is insufficient or we are to deep, return
// if balance is insufficient or we are too deep, return
if self.state.balance(&self.params.address) < *value || self.depth >= self.schedule.max_depth {
return Ok((gas + call_gas, true));
}
@ -902,7 +891,6 @@ mod tests {
assert_eq!(executed.refunded, U256::from(58_699));
assert_eq!(executed.cumulative_gas_used, U256::from(41_301));
assert_eq!(executed.logs.len(), 0);
assert_eq!(executed.excepted, false);
assert_eq!(executed.contracts_created.len(), 0);
assert_eq!(state.balance(&sender), U256::from(1));
assert_eq!(state.balance(&contract), U256::from(17));

View File

@ -31,8 +31,7 @@ impl PodAccount {
let mut stream = RlpStream::new_list(4);
stream.append(&self.nonce);
stream.append(&self.balance);
// TODO.
stream.append(&SHA3_NULL_RLP);
stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k.to_vec(), encode(&U256::from(v.as_slice())))).collect()));
stream.append(&self.code.sha3());
stream.out()
}

View File

@ -4,11 +4,6 @@ use pod_state::*;
use state_diff::*;
use ethereum;
fn flush(s: String) {
::std::io::stdout().write(s.as_bytes()).unwrap();
::std::io::stdout().flush().unwrap();
}
fn do_json_test(json_data: &[u8]) -> Vec<String> {
let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid");
let mut failed = Vec::new();
@ -39,14 +34,12 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
//println!("Transaction: {:?}", t);
//println!("Env: {:?}", env);
let calc_post = sec_trie_root(post.get().iter().map(|(k, v)| (k.to_vec(), v.rlp())).collect());
{
let mut s = State::new_temp();
s.populate_from(post.clone());
s.commit();
assert_eq!(&post_state_root, s.root());
}
if fail_unless(post_state_root == calc_post) {
println!("!!! {}: Trie root mismatch (got: {}, expect: {}):", name, calc_post, post_state_root);
println!("!!! Post:\n{}", post);
} else {
let mut s = State::new_temp();
s.populate_from(pre);
s.commit();
@ -68,6 +61,7 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
}
}
}
}
if !fail {
flush(format!("ok\n"));
}