Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit ff16ee4

Browse files
author
adria0
committed
EIP161 precompile balances precondition
1 parent 620c354 commit ff16ee4

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

ethcore/machine/src/executive.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ const STACK_SIZE_ENTRY_OVERHEAD: usize = 100 * 1024;
6363
const STACK_SIZE_ENTRY_OVERHEAD: usize = 20 * 1024;
6464

6565
#[cfg(any(test, feature = "test-helpers"))]
66-
/// RIPEMD160 was removed in mainnet block #2686351. See security Security alert [11/24/2016].
67-
/// This is only applies in tests, since all precompile accounts are now non-empty in mainnet.
66+
/// Precompile that can never be prunned from state trie (0x3, only in tests)
6867
const UNPRUNABLE_PRECOMPILE_ADDRESS: Option<Address> = Some(ethereum_types::H160([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3]));
6968

7069
#[cfg(not(any(test, feature = "test-helpers")))]
71-
/// EIP161 - By default all empty accounts can be prunned.
70+
/// Precompile that can never be prunned from state trie (none)
7271
const UNPRUNABLE_PRECOMPILE_ADDRESS: Option<Address> = None;
7372

7473
/// Returns new address created from address, nonce, and code hash
@@ -422,7 +421,6 @@ impl<'a> CallCreateExecutive<'a> {
422421
Self::check_static_flag(&params, self.static_flag, self.is_create)?;
423422
state.checkpoint();
424423

425-
let initial_builtin_balance = state.balance(&params.code_address)?;
426424
Self::transfer_exec_balance(&params, self.schedule, state, substate)?;
427425

428426
let default = [];
@@ -451,13 +449,14 @@ impl<'a> CallCreateExecutive<'a> {
451449
})
452450
}
453451
} else {
454-
// EIP161 - reverted calls cancels state trie cleaning
455-
if initial_builtin_balance.is_zero() {
456-
let prune = UNPRUNABLE_PRECOMPILE_ADDRESS
457-
.map_or(true, |addr| addr != params.code_address);
458-
if prune {
452+
// Openethereum needs balance > 0 in precompiles to be EIP161 compliant, see PR#11597.
453+
// Since RIPEMD160 was removed in mainnet block #2686351,
454+
// this is activated only in tests to check this specific irregular estate transition.
455+
if let Some(unprunable_addr) = UNPRUNABLE_PRECOMPILE_ADDRESS {
456+
if unprunable_addr != params.code_address
457+
&& state.balance(&params.code_address)?.is_zero() {
459458
substate.touched.remove(&params.code_address);
460-
}
459+
}
461460
}
462461
// just drain the whole gas
463462
state.revert_to_checkpoint();

0 commit comments

Comments
 (0)