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

EIP-1702: Generalized Account Versioning Scheme #10771

Merged
merged 11 commits into from
Jul 8, 2019
Merged

EIP-1702: Generalized Account Versioning Scheme #10771

merged 11 commits into from
Jul 8, 2019

Conversation

sorpaas
Copy link
Collaborator

@sorpaas sorpaas commented Jun 21, 2019

rel #10770

This is a draft implementation of EIP-1702.

  • Snapshots and light clients should be backward compatible. Older clients stops working once the network has its first non-legacy version account.
  • The actual versioning is defined by vm::Schedule::versions, where we supports PWasm (which uses the pWasm execution engine) only (because it's the only useful target right now).
  • For future EVM real usage, we'll define feature flags in VersionedSchedule (for example, VersionedSchedule::EVM::eip1283) that states a particular feature should be enabled in the current version.
  • For frontend config, one can specify wasm_version together with wasm_activation_transition, so that pWasm is activated using an account version, instead of code prefix.

@sorpaas sorpaas added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Jun 21, 2019
@dvdplm
Copy link
Collaborator

dvdplm commented Jun 23, 2019

* `pWasm` currently always create new contracts of version zero. This is a known issue.

Can you elaborate on this for my education?

@sorpaas
Copy link
Collaborator Author

sorpaas commented Jun 23, 2019

@dvdplm This is fixed in 4e448f1. Let me know if you still need more info.

And for spec-related questions, maybe consider putting it under sorpaas/EIPs#2!

@@ -84,10 +85,14 @@ pub fn to_fat_rlps(
let mut leftover: Option<Vec<u8>> = None;
loop {
account_stream.append(account_hash);
account_stream.begin_list(5);
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 to make one general begin_unbounded_list for all added rlp parameters? It looks weird, when it's first limited 5-6 elements list and unlimited after it.

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'm trying to maintain backward compatibility here. If we change the snapshotting format when use_short_version is true, then old clients will break. Or do you have better ideas?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The only idea, that I've got, that doesn't break compatibility and doesn't increment the whole packet's length, is to pass the list instead of one of the parameters (for example, push (nonce, code_version) instead of nonce). And to define during decoding, is it list on this place in the packet or not. It will allow to get rid off the most of boolean flags in these two methods but it will be still "hacky" (not obvious). I mean something like this:
Encoding:
....
account_stream.begin_list(5);
account_stream.begin_list(2);
account_stream.append(&acc.nonce);
account_stream.append(&acc.code_version);
account_stream.append(&acc.balance);
...
Decoding:
let account_descr = rlp.val_at(0)?;
let mut nonce = 0;
let mut code_version = U256::zero();
if account_descr.is_list() {
nonce = account_descr.val_at(0)?;
code_version = account_descr.val_at(1)?;
} else {
nonce = account_descr.as_val()?;
}
What do you think?

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 still don't see what's the advantage of this over just checking the RLP list length. That should be reliable and we're already using it in places like transaction decoding: https://github.com/paritytech/parity-ethereum/blob/825c7990f29514d699e22c6e78f73710e53e983d/ethcore/types/src/transaction/transaction.rs#L121-L134

if !use_short_version {
account_stream.append(&acc.code_version);
}

account_stream.begin_unbounded_list();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unbounded list starts here

@@ -170,6 +179,12 @@ pub fn from_fat_rlp(
return Ok((ACC_EMPTY, None));
}

let use_short_version = match rlp.item_count()? {
5 => true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think, that it's a risky logic, to rely on item count in rlp packet. May be to pass this parameter explicitly?

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 don't get what you mean here. Which parameter do you think we can pass explicitly?

fn rlp_append(&self, stream: &mut rlp::RlpStream) {
let use_short_version = self.code_version == U256::zero();

match use_short_version {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also use begin_unbounded_list here.


impl rlp::Decodable for BasicAccount {
fn decode(rlp: &rlp::Rlp) -> Result<Self, rlp::DecoderError> {
let use_short_version = match rlp.item_count()? {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same comment about fragile logic based on item count

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using rlp.item_count() is the only method to know whether we're at version 0 or above version 0. I don't agree it's fragile -- BasicAccount is guaranteed to be either have 4 items (version 0 case) or 5 items (version non-0 case). And we handle all errors explicitly.

ethcore/src/snapshot/account.rs Outdated Show resolved Hide resolved
ethcore/src/factory.rs Outdated Show resolved Hide resolved
Err(err) => Err(err),
}
},
None => Ok(Err(vm::Error::OutOfGas)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this is the correct error, is it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the correct error -- None means the validation phrase fails. In that case, according to the spec we should return out of gas.

sorpaas and others added 2 commits July 4, 2019 20:14
Co-Authored-By: Andronik Ordian <write@reusable.software>
Co-Authored-By: Andronik Ordian <write@reusable.software>
@@ -246,6 +268,7 @@ mod tests {
balance: 123456789.into(),
storage_root: KECCAK_NULL_RLP,
code_hash: KECCAK_EMPTY,
code_version: 0.into(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please add one more test for encoding accounts with not zero code-version?

@ordian ordian added this to the 2.7 milestone Jul 5, 2019
@sorpaas
Copy link
Collaborator Author

sorpaas commented Jul 8, 2019

I have added a frontend config wasmVersion (used together with wasmActivationTransition it enables pwasm via account versioning, rather than code prefix). I think the PR should be ready for review.

For testing, it's still not yet done and I think we may want to have a separate PR to do it comprehensively. (And collaborate with aleth, if possible.)

Copy link
Collaborator

@grbIzl grbIzl left a comment

Choose a reason for hiding this comment

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

Looks good!

@ordian ordian added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jul 8, 2019
@dvdplm dvdplm merged commit 141f6a0 into master Jul 8, 2019
@dvdplm dvdplm deleted the sp-eip1702 branch July 8, 2019 10:03
dvdplm added a commit that referenced this pull request Jul 8, 2019
* master:
  EIP-1702: Generalized Account Versioning Scheme (#10771)
dvdplm added a commit that referenced this pull request Jul 8, 2019
…-state-db

* dp/chore/extricate-state-backend:
  Sort out the merge
  EIP-1702: Generalized Account Versioning Scheme (#10771)
dvdplm added a commit that referenced this pull request Jul 8, 2019
…cation

* dp/chore/extract-state-db:
  Sort out the merge
  EIP-1702: Generalized Account Versioning Scheme (#10771)
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