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

Commit b76e5ab

Browse files
sorpaasniklasad1
authored andcommitted
Handle the case for contract creation on an empty but exist account with storage items (#10065)
* Add is_base_storage_root_unchanged * Fix compile, use a shortcut for check, and remove ignored tests * Add a warn! * Update ethereum/tests to v6.0.0-beta.2 * grumble: use {:#x} instead of 0x{:x} Co-Authored-By: sorpaas <accounts@that.world>
1 parent c3b31e5 commit b76e5ab

File tree

5 files changed

+22
-43
lines changed

5 files changed

+22
-43
lines changed

ethcore/res/ethereum/tests

Submodule tests updated 110 files
Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,4 @@
1-
{ "block":
2-
[
3-
{
4-
"reference": "None",
5-
"comment": "This failing test is deemed skippable. Could not happen on a mainnet.",
6-
"failing": "GeneralStateTest_stCreate2",
7-
"subtests": ["RevertInCreateInInitCreate2_d0g0v0_Constantinople"]
8-
},
9-
{
10-
"reference": "None",
11-
"comment": "This failing test is deemed skippable. Could not happen on a mainnet.",
12-
"failing": "GeneralStateTest_stRevertTest",
13-
"subtests": ["RevertInCreateInInit_d0g0v0_Constantinople"]
14-
}
15-
],
16-
"state":
17-
[
18-
{
19-
"reference": "None",
20-
"comment": "This failing test is deemed skippable. Could not happen on a mainnet.",
21-
"failing": "stCreate2Test",
22-
"subtests": {
23-
"RevertInCreateInInitCreate2": {
24-
"subnumbers": ["1"],
25-
"chain": "Constantinople (test)"
26-
}
27-
}
28-
},
29-
{
30-
"reference": "None",
31-
"comment": "This failing test is deemed skippable. Could not happen on a mainnet.",
32-
"failing": "stRevertTest",
33-
"subtests": {
34-
"RevertInCreateInInit": {
35-
"subnumbers": ["1"],
36-
"chain": "Constantinople (test)"
37-
}
38-
}
39-
}
40-
41-
]
1+
{
2+
"block": [],
3+
"state": []
424
}

ethcore/src/externalities.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
116116
where T: Tracer, V: VMTracer, B: StateBackend
117117
{
118118
fn initial_storage_at(&self, key: &H256) -> vm::Result<H256> {
119-
self.state.checkpoint_storage_at(0, &self.origin_info.address, key).map(|v| v.unwrap_or(H256::zero())).map_err(Into::into)
119+
if self.state.is_base_storage_root_unchanged(&self.origin_info.address)? {
120+
self.state.checkpoint_storage_at(0, &self.origin_info.address, key).map(|v| v.unwrap_or(H256::zero())).map_err(Into::into)
121+
} else {
122+
warn!(target: "externalities", "Detected existing account {:#x} where a forced contract creation happened.", self.origin_info.address);
123+
Ok(H256::zero())
124+
}
120125
}
121126

122127
fn storage_at(&self, key: &H256) -> vm::Result<H256> {

ethcore/src/state/account.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ impl Account {
451451
}
452452
}
453453

454+
/// Whether the base storage root of this account is unchanged.
455+
pub fn is_base_storage_root_unchanged(&self) -> bool {
456+
self.original_storage_cache.is_none()
457+
}
458+
454459
/// Storage root where the account changes are based upon.
455460
pub fn base_storage_root(&self) -> H256 {
456461
self.storage_root

ethcore/src/state/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,13 @@ impl<B: Backend> State<B> {
539539
|a| a.as_ref().map_or(self.account_start_nonce, |account| *account.nonce()))
540540
}
541541

542+
/// Whether the base storage root of an account remains unchanged.
543+
pub fn is_base_storage_root_unchanged(&self, a: &Address) -> TrieResult<bool> {
544+
Ok(self.ensure_cached(a, RequireCache::None, true,
545+
|a| a.as_ref().map(|account| account.is_base_storage_root_unchanged()))?
546+
.unwrap_or(true))
547+
}
548+
542549
/// Get the storage root of account `a`.
543550
pub fn storage_root(&self, a: &Address) -> TrieResult<Option<H256>> {
544551
self.ensure_cached(a, RequireCache::None, true,

0 commit comments

Comments
 (0)