Skip to content

Commit

Permalink
Problem: account_state might be mutated multiple times
Browse files Browse the repository at this point in the history
In `into_context`, MessageCall needs both `require(caller)` and
`require_code(address)`, but it might have already returned before
requiring the later.
  • Loading branch information
sorpaas committed Jun 13, 2017
1 parent c4bf2e1 commit c181fdf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sputnikvm/src/vm/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,27 @@ impl Transaction {
Transaction::MessageCall {
address, caller, gas_price, gas_limit, value, data
} => {
account_state.require(caller)?;
account_state.require_code(address)?;

if !is_code {
let nonce = account_state.nonce(caller)?;
let nonce = account_state.nonce(caller).unwrap();
account_state.set_nonce(caller, nonce + M256::from(1u64)).unwrap();
}

Ok(Context {
address, caller, data, gas_price, value,
gas_limit: gas_limit - upfront,
code: account_state.code(address)?.into(),
code: account_state.code(address).unwrap().into(),
origin: origin.unwrap_or(caller),
})
},
Transaction::ContractCreation {
caller, gas_price, gas_limit, value, init,
} => {
let nonce = account_state.nonce(caller)?;
account_state.require(caller)?;

let nonce = account_state.nonce(caller).unwrap();
account_state.set_nonce(caller, nonce + M256::from(1u64)).unwrap();

let mut rlp = RlpStream::new_list(2);
Expand Down

0 comments on commit c181fdf

Please sign in to comment.