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

Handle the case for contract creation on an empty but exist account with storage items #10065

Merged
merged 5 commits into from
Jan 15, 2019

Conversation

sorpaas
Copy link
Collaborator

@sorpaas sorpaas commented Dec 14, 2018

In spec it's technically possible to create empty account with existing storage items, thus break the net metering model. This PR creates is_base_storage_root_unchanged function in state. However, any sane person wouldn't do that so practically is_base_storage_root_unchanged should always be true with the only exception of tests.

For any items in the checkpoint, once we set original_storage_cache, we carry it on for any further items in the checkpoint. So we can check the newest items in the checkpoint list to determine whether there's any changes of the base_storage_root value. It works for current model because the value of base_storage_root can only ever be changed once.

@sorpaas sorpaas added A0-pleasereview 🤓 Pull request needs code review. B1-patch-beta 🕷🕷 B0-patch-stable 🕷 Pull request should also be back-ported to the stable branch. A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels Dec 14, 2018
@5chdn 5chdn added this to the 2.3 milestone Dec 14, 2018
@sorpaas sorpaas added A4-gotissues 💥 Pull request is reviewed and has significant issues which must be addressed. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Dec 14, 2018
@@ -116,6 +116,10 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
where T: Tracer, V: VMTracer, B: StateBackend
{
fn initial_storage_at(&self, key: &H256) -> vm::Result<H256> {
if self.substate.new_contract_with_previously_non_empty_storage.contains(&self.origin_info.address) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that the contract was empty initially, but then it is somehow initialized via CREATE within the same scope?
I.e. asking if returning zero() here wouldn't break something else

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to use is_base_storage_root_unchanged. If base storage root is changed from an original storage root value, then the changed base storage root can only be KECCAK_NULL_RLP (because we only change it in contract creation). From any point after that, we discard the actual original storage value, but use H256::zero().

I think it's safe and can't think of any way this will break things, but would love to have more eyes for review.

@sorpaas sorpaas added A0-pleasereview 🤓 Pull request needs code review. and removed A4-gotissues 💥 Pull request is reviewed and has significant issues which must be addressed. labels Dec 14, 2018
@sorpaas sorpaas removed the B0-patch-stable 🕷 Pull request should also be back-ported to the stable branch. label Dec 28, 2018
@5chdn 5chdn mentioned this pull request Dec 28, 2018
15 tasks
@5chdn 5chdn added the M4-core ⛓ Core client code / Rust. label Jan 3, 2019
@5chdn 5chdn modified the milestones: 2.3, 2.4 Jan 10, 2019
This was referenced Jan 10, 2019
@@ -539,6 +539,13 @@ impl<B: Backend> State<B> {
|a| a.as_ref().map_or(self.account_start_nonce, |account| *account.nonce()))
}

/// Whether the base storage root of an account remains unchanged.
pub fn is_base_storage_root_unchanged(&self, a: &Address) -> TrieResult<bool> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just return bool here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below State::ensure_cached can fail, and in that case I think it's better to bail because it's a DB failure.

@niklasad1 niklasad1 added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 14, 2019
Co-Authored-By: sorpaas <accounts@that.world>
@niklasad1 niklasad1 added A8-looksgood 🦄 Pull request is reviewed well. and removed A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. labels Jan 14, 2019
Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@niklasad1 niklasad1 merged commit 64704c4 into master Jan 15, 2019
@niklasad1 niklasad1 deleted the sp-empty-exist branch January 15, 2019 09:21
niklasad1 pushed a commit that referenced this pull request Jan 15, 2019
…ith 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>
niklasad1 pushed a commit that referenced this pull request Jan 15, 2019
…ith 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>
5chdn added a commit that referenced this pull request Jan 15, 2019
* version: bump stable to 2.2.7

* version: mark 2.2 track stable

* version: mark update critical on all networks

* version: commit cargo lock

* Ping nodes from discovery (#10167)

* snap: fix path in script (#10157)

* snap: fix path in script

* debug, revert me

* fix

* necromancer awk magic

* awk necromancy and path fixing

* working track selection

* Fix _cannot recursively call into `Core`_ issue (#10144)

* Change igd to github:maufl/rust-igd

* Run `igd::search_gateway_from_timeout` from own thread

* 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>

* version: bump fork blocks for kovan and foundation (#10186)

* pull constantinople on ethereum network (#10189)

* ethcore: pull constantinople on ethereum network

* version: mark update as critical

* ethcore: remove constantinople alltogether from chain spec

* version: revert fork block for ethereum
5chdn added a commit that referenced this pull request Jan 15, 2019
* version: mark 2.3 track beta

* version: mark update critical on all networks

* Ping nodes from discovery (#10167)

* Fix _cannot recursively call into `Core`_ issue (#10144)

* Change igd to github:maufl/rust-igd

* Run `igd::search_gateway_from_timeout` from own thread

* 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>

* version: bump fork blocks for kovan and foundation (#10186)

* pull constantinople on ethereum network (#10189)

* ethcore: pull constantinople on ethereum network

* version: mark update as critical

* ethcore: remove constantinople alltogether from chain spec

* version: revert fork block for ethereum
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants