Skip to content

Commit 18f156a

Browse files
authored
Pass all Frontier tests (#374)
* Fix EIP-161 and empty create issue in Frontier * Init code behavior for Frontier * Run cargo fmt * Pass all Frontier tests * Run cargo fmt * Add non_exhaustive to Error types and Config types to prepare for release * Set eip7610 to true
1 parent fa39f93 commit 18f156a

File tree

8 files changed

+72
-46
lines changed

8 files changed

+72
-46
lines changed

interpreter/src/error/exit.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl fmt::Display for ExitError {
4949
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
5050
)]
5151
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
52+
#[non_exhaustive]
5253
pub enum ExitSucceed {
5354
/// Machine encountered an explicit stop.
5455
Stopped,
@@ -71,6 +72,7 @@ impl From<ExitSucceed> for ExitResult {
7172
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
7273
)]
7374
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
75+
#[non_exhaustive]
7476
pub enum ExitException {
7577
/// Trying to pop from an empty stack.
7678
#[cfg_attr(feature = "scale", codec(index = 0))]
@@ -154,6 +156,7 @@ impl From<ExitException> for ExitError {
154156
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
155157
)]
156158
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
159+
#[non_exhaustive]
157160
pub enum ExitFatal {
158161
/// The operation is not supported.
159162
NotSupported,

interpreter/src/runtime.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct RuntimeState {
2626

2727
/// Runtime config.
2828
#[derive(Clone, Debug)]
29+
#[non_exhaustive]
2930
pub struct RuntimeConfig {
3031
/// EIP-161: new rules about empty accounts.
3132
pub eip161_empty_check: bool,
@@ -35,6 +36,32 @@ pub struct RuntimeConfig {
3536
pub eip6780_suicide_only_in_same_tx: bool,
3637
}
3738

39+
impl RuntimeConfig {
40+
/// Create a new Runtime config with default settings.
41+
pub const fn new() -> Self {
42+
Self {
43+
eip161_empty_check: true,
44+
eip7610_create_check_storage: true,
45+
eip6780_suicide_only_in_same_tx: false,
46+
}
47+
}
48+
49+
/// Create a new Runtime config with Frontier settings (everything disabled).
50+
pub const fn frontier() -> Self {
51+
Self {
52+
eip161_empty_check: false,
53+
eip6780_suicide_only_in_same_tx: false,
54+
eip7610_create_check_storage: true,
55+
}
56+
}
57+
}
58+
59+
impl Default for RuntimeConfig {
60+
fn default() -> Self {
61+
Self::new()
62+
}
63+
}
64+
3865
/// Runtime state and config.
3966
#[derive(Clone, Debug)]
4067
pub struct RuntimeStateAndConfig<'config> {
@@ -44,11 +71,7 @@ pub struct RuntimeStateAndConfig<'config> {
4471
pub config: &'config RuntimeConfig,
4572
}
4673

47-
static DEFAULT_RUNTIME_CONFIG: RuntimeConfig = RuntimeConfig {
48-
eip161_empty_check: true,
49-
eip7610_create_check_storage: false,
50-
eip6780_suicide_only_in_same_tx: false,
51-
};
74+
static DEFAULT_RUNTIME_CONFIG: RuntimeConfig = RuntimeConfig::new();
5275

5376
impl RuntimeStateAndConfig<'static> {
5477
/// Used for testing.

jsontests/src/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub fn run_test(
180180
) -> Result<(), Error> {
181181
let mut config = match test.fork {
182182
Fork::Istanbul => Config::istanbul(),
183-
// Fork::Frontier => Config::frontier(),
183+
Fork::Frontier => Config::frontier(),
184184
_ => return Err(Error::UnsupportedFork),
185185
};
186186
config_change(&mut config);

src/backend/in_memory.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ impl InMemoryBackend {
100100
}
101101
}
102102

103-
for address in changeset.deletes.clone() {
104-
self.state.remove(&address);
105-
}
106-
107103
if changeset.config.eip161_empty_check {
108104
for address in changeset.touched.clone() {
109105
if self.is_empty(address) {
@@ -114,6 +110,14 @@ impl InMemoryBackend {
114110
for address in changeset.touched.clone() {
115111
self.state.entry(address).or_default();
116112
}
113+
114+
self.state
115+
.entry(self.environment.block_coinbase)
116+
.or_default();
117+
}
118+
119+
for address in changeset.deletes.clone() {
120+
self.state.remove(&address);
117121
}
118122
}
119123
}

src/backend/overlayed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'config, B> OverlayedBackend<'config, B> {
7272

7373
/// Deconstruct the current overlayed backend. The change set can then be applied into the actual backend.
7474
pub fn deconstruct(mut self) -> (B, OverlayedChangeSet<'config>) {
75-
if self.touched_ripemd {
75+
if self.config.eip161_empty_check && self.touched_ripemd {
7676
self.substate.touched.insert(RIPEMD);
7777
}
7878

src/standard/config.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use evm_interpreter::runtime::RuntimeConfig;
22

33
/// Runtime configuration.
44
#[derive(Clone, Debug)]
5+
#[non_exhaustive]
56
pub struct Config {
67
/// Runtime config.
78
pub runtime: RuntimeConfig,
@@ -87,11 +88,7 @@ impl Config {
8788
/// Frontier hard fork configuration.
8889
pub const fn frontier() -> Config {
8990
Config {
90-
runtime: RuntimeConfig {
91-
eip161_empty_check: false,
92-
eip6780_suicide_only_in_same_tx: false,
93-
eip7610_create_check_storage: true,
94-
},
91+
runtime: RuntimeConfig::frontier(),
9592
eip2_no_empty_contract: false,
9693
eip2_create_transaction_increase: false,
9794
eip2200_sstore_gas_metering: false,
@@ -100,7 +97,7 @@ impl Config {
10097
eip3529_decrease_clears_refund: false,
10198
eip3541_disallow_executable_format: false,
10299
eip3651_warm_coinbase_address: false,
103-
eip150_no_err_on_call_with_more_gas: true,
100+
eip150_no_err_on_call_with_more_gas: false,
104101
eip161_create_increase_nonce: false,
105102
eip150_call_l64_after_gas: false,
106103
eip170_create_contract_limit: false,

src/standard/gasometer/mod.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@ pub struct GasometerState {
2525
}
2626

2727
impl GasometerState {
28-
/// Perform any operation on the gasometer. Set the gasometer to `OutOfGas`
29-
/// if the operation fails.
30-
#[inline]
31-
pub fn perform<R, F: FnOnce(&mut Self) -> Result<R, ExitError>>(
32-
&mut self,
33-
f: F,
34-
) -> Result<R, ExitError> {
35-
match f(self) {
36-
Ok(r) => Ok(r),
37-
Err(e) => {
38-
self.oog();
39-
Err(e)
40-
}
41-
}
42-
}
43-
4428
/// Set the current gasometer to `OutOfGas`.
4529
pub fn oog(&mut self) {
4630
self.memory_gas = 0;
@@ -89,11 +73,9 @@ impl GasometerState {
8973

9074
/// Record code deposit gas.
9175
pub fn record_codedeposit(&mut self, len: usize) -> Result<(), ExitError> {
92-
self.perform(|gasometer| {
93-
let cost = len as u64 * consts::G_CODEDEPOSIT;
94-
gasometer.record_gas64(cost)?;
95-
Ok(())
96-
})
76+
let cost = len as u64 * consts::G_CODEDEPOSIT;
77+
self.record_gas64(cost)?;
78+
Ok(())
9779
}
9880

9981
/// Set memory gas usage.

src/standard/invoker/mod.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,28 @@ where
361361
let retbuf = exit.retval;
362362

363363
if let Some(substate) = substate {
364-
routines::deploy_create_code(
364+
match routines::deploy_create_code(
365365
address,
366366
retbuf,
367367
substate,
368368
handler,
369369
SetCodeOrigin::Transaction,
370-
)?;
371-
372-
Ok(TransactValueCallCreate::Create {
373-
succeed: result,
374-
address,
375-
})
370+
) {
371+
Ok(()) => Ok(TransactValueCallCreate::Create {
372+
succeed: result,
373+
address,
374+
}),
375+
Err(e)
376+
if AsRef::<Config>::as_ref(&substate)
377+
.eip2_no_empty_contract =>
378+
{
379+
Err(e)
380+
}
381+
Err(_) => Ok(TransactValueCallCreate::Create {
382+
succeed: result,
383+
address,
384+
}),
385+
}
376386
} else {
377387
Err(ExitFatal::Unfinished.into())
378388
}
@@ -684,11 +694,18 @@ where
684694
retbuf = Vec::new();
685695
Ok(address)
686696
}
687-
Err(err) => {
697+
Err(err)
698+
if AsRef::<Config>::as_ref(&substate)
699+
.eip2_no_empty_contract =>
700+
{
688701
retbuf = Vec::new();
689702
strategy = MergeStrategy::Discard;
690703
Err(err)
691704
}
705+
Err(_) => {
706+
retbuf = Vec::new();
707+
Ok(address)
708+
}
692709
}
693710
}
694711
Err(err) => Err(err),

0 commit comments

Comments
 (0)