Skip to content

Commit

Permalink
Specify patches for supported networks
Browse files Browse the repository at this point in the history
Summary:
This moves Classic patches to a separate crate, and add additional patches for
Foundation, Ellaism, Musicoin, Expanse, Ubiq.

Reviewers: sorpaas

Reviewed By: sorpaas

Subscribers: jenkins

Differential Revision: https://source.that.world/D46
  • Loading branch information
sorpaas committed Jan 29, 2018
1 parent d4673b8 commit 3bc5d74
Show file tree
Hide file tree
Showing 25 changed files with 840 additions and 133 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ members = [
"./cli",
"./precompiled/modexp",
"./precompiled/bn128",
"./network/foundation",
"./network/classic",
"./network/ellaism",
"./network/musicoin",
"./network/expanse",
"./network/ubiq",
]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ experience of the community and learn from other proposed RFCs.
* FFI, Protobuf and JSON interface
* written in Rust, can be used as a binary, cargo crate or shared library

## Supported Networks

* [Foundation](./network/foundation)
* [Classic](./network/classic)
* [Ellaism](./network/ellaism)
* [Expanse](./network/expanse)
* [Musicoin](./network/musicoin)
* [Ubiq](./network/ubiq)

## Related projects

* [SputnikVM Dev](https://github.com/ethereumproject/sputnikvm-dev) - SputnikVM instance for Smart Contract development,
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ name = "sputnikvm-cli"
etcommon-bigint = "0.2"
etcommon-hexutil = "0.2"
sputnikvm = { version = "0.9", path = ".." }
sputnikvm-network-classic = { path = "../network/classic" }
gethrpc = { path = '../gethrpc' }
clap = "2.22"
serde_json = "0.9"
Expand Down
3 changes: 2 additions & 1 deletion cli/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extern crate clap;
extern crate bigint;
extern crate hexutil;
extern crate sputnikvm;
extern crate sputnikvm_network_classic;
extern crate serde_json;
extern crate gethrpc;
extern crate flame;
Expand All @@ -16,8 +17,8 @@ use bigint::{Gas, Address, U256, M256, H256};
use hexutil::read_hex;
use sputnikvm::{HeaderParams, Context, SeqTransactionVM, ValidTransaction, VM, Log, Patch,
AccountCommitment, AccountChange, RequireError, TransactionAction, VMStatus,
MainnetFrontierPatch, MainnetHomesteadPatch, MainnetEIP150Patch, MainnetEIP160Patch,
SeqContextVM};
use sputnikvm_network_classic::{MainnetFrontierPatch, MainnetHomesteadPatch, MainnetEIP150Patch, MainnetEIP160Patch};
use gethrpc::{GethRPCClient, NormalGethRPCClient, RPCBlock};
use std::str::FromStr;
use std::ops::DerefMut;
Expand Down
10 changes: 10 additions & 0 deletions network/classic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "sputnikvm-network-classic"
version = "0.0.1"
license = "Apache-2.0"
authors = ["Wei Tang <[email protected]>"]
repository = "https://github.com/ethereumproject/sputnikvm"

[dependencies]
sputnikvm = { version = "0.9", path = "../.." }
etcommon-bigint = { version = "0.2", default-features = false }
153 changes: 153 additions & 0 deletions network/classic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
extern crate bigint;
extern crate sputnikvm;

use std::marker::PhantomData;
use bigint::{Gas, U256, H160, Address};
use sputnikvm::{Precompiled, AccountPatch, Patch,
ID_PRECOMPILED, ECREC_PRECOMPILED, SHA256_PRECOMPILED, RIP160_PRECOMPILED};

/// Mainnet account patch
pub struct MainnetAccountPatch;
impl AccountPatch for MainnetAccountPatch {
fn initial_nonce() -> U256 { U256::zero() }
fn initial_create_nonce() -> U256 { Self::initial_nonce() }
fn empty_considered_exists() -> bool { true }
}

pub struct MordenAccountPatch;
impl AccountPatch for MordenAccountPatch {
fn initial_nonce() -> U256 { U256::from(1048576) }
fn initial_create_nonce() -> U256 { Self::initial_nonce() }
fn empty_considered_exists() -> bool { true }
}

pub static ETC_PRECOMPILEDS: [(Address, Option<&'static [u8]>, &'static Precompiled); 4] = [
(H160([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x01]),
None,
&ECREC_PRECOMPILED),
(H160([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x02]),
None,
&SHA256_PRECOMPILED),
(H160([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x03]),
None,
&RIP160_PRECOMPILED),
(H160([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x04]),
None,
&ID_PRECOMPILED),
];

/// Frontier patch.
pub struct FrontierPatch<A: AccountPatch>(PhantomData<A>);
pub type MainnetFrontierPatch = FrontierPatch<MainnetAccountPatch>;
pub type MordenFrontierPatch = FrontierPatch<MordenAccountPatch>;
impl<A: AccountPatch> Patch for FrontierPatch<A> {
type Account = A;

fn code_deposit_limit() -> Option<usize> { None }
fn callstack_limit() -> usize { 1024 }
fn gas_extcode() -> Gas { Gas::from(20usize) }
fn gas_balance() -> Gas { Gas::from(20usize) }
fn gas_sload() -> Gas { Gas::from(50usize) }
fn gas_suicide() -> Gas { Gas::from(0usize) }
fn gas_suicide_new_account() -> Gas { Gas::from(0usize) }
fn gas_call() -> Gas { Gas::from(40usize) }
fn gas_expbyte() -> Gas { Gas::from(10usize) }
fn gas_transaction_create() -> Gas { Gas::from(0usize) }
fn force_code_deposit() -> bool { true }
fn has_delegate_call() -> bool { false }
fn has_static_call() -> bool { false }
fn has_revert() -> bool { false }
fn has_return_data() -> bool { false }
fn err_on_call_with_more_gas() -> bool { true }
fn call_create_l64_after_gas() -> bool { false }
fn memory_limit() -> usize { usize::max_value() }
fn precompileds() -> &'static [(Address, Option<&'static [u8]>, &'static Precompiled)] {
&ETC_PRECOMPILEDS }
}

/// Homestead patch.
pub struct HomesteadPatch<A: AccountPatch>(PhantomData<A>);
pub type MainnetHomesteadPatch = HomesteadPatch<MainnetAccountPatch>;
pub type MordenHomesteadPatch = HomesteadPatch<MordenAccountPatch>;
impl<A: AccountPatch> Patch for HomesteadPatch<A> {
type Account = A;

fn code_deposit_limit() -> Option<usize> { None }
fn callstack_limit() -> usize { 1024 }
fn gas_extcode() -> Gas { Gas::from(20usize) }
fn gas_balance() -> Gas { Gas::from(20usize) }
fn gas_sload() -> Gas { Gas::from(50usize) }
fn gas_suicide() -> Gas { Gas::from(0usize) }
fn gas_suicide_new_account() -> Gas { Gas::from(0usize) }
fn gas_call() -> Gas { Gas::from(40usize) }
fn gas_expbyte() -> Gas { Gas::from(10usize) }
fn gas_transaction_create() -> Gas { Gas::from(32000usize) }
fn force_code_deposit() -> bool { false }
fn has_delegate_call() -> bool { true }
fn has_static_call() -> bool { false }
fn has_revert() -> bool { false }
fn has_return_data() -> bool { false }
fn err_on_call_with_more_gas() -> bool { true }
fn call_create_l64_after_gas() -> bool { false }
fn memory_limit() -> usize { usize::max_value() }
fn precompileds() -> &'static [(Address, Option<&'static [u8]>, &'static Precompiled)] {
&ETC_PRECOMPILEDS }
}

/// EIP150 patch.
pub struct EIP150Patch<A: AccountPatch>(PhantomData<A>);
pub type MainnetEIP150Patch = EIP150Patch<MainnetAccountPatch>;
pub type MordenEIP150Patch = EIP150Patch<MordenAccountPatch>;
impl<A: AccountPatch> Patch for EIP150Patch<A> {
type Account = A;

fn code_deposit_limit() -> Option<usize> { None }
fn callstack_limit() -> usize { 1024 }
fn gas_extcode() -> Gas { Gas::from(700usize) }
fn gas_balance() -> Gas { Gas::from(400usize) }
fn gas_sload() -> Gas { Gas::from(200usize) }
fn gas_suicide() -> Gas { Gas::from(5000usize) }
fn gas_suicide_new_account() -> Gas { Gas::from(25000usize) }
fn gas_call() -> Gas { Gas::from(700usize) }
fn gas_expbyte() -> Gas { Gas::from(10usize) }
fn gas_transaction_create() -> Gas { Gas::from(32000usize) }
fn force_code_deposit() -> bool { false }
fn has_delegate_call() -> bool { true }
fn has_static_call() -> bool { false }
fn has_revert() -> bool { false }
fn has_return_data() -> bool { false }
fn err_on_call_with_more_gas() -> bool { false }
fn call_create_l64_after_gas() -> bool { true }
fn memory_limit() -> usize { usize::max_value() }
fn precompileds() -> &'static [(Address, Option<&'static [u8]>, &'static Precompiled)] {
&ETC_PRECOMPILEDS }
}

/// EIP160 patch.
pub struct EIP160Patch<A: AccountPatch>(PhantomData<A>);
pub type MainnetEIP160Patch = EIP160Patch<MainnetAccountPatch>;
pub type MordenEIP160Patch = EIP160Patch<MordenAccountPatch>;
impl<A: AccountPatch> Patch for EIP160Patch<A> {
type Account = A;

fn code_deposit_limit() -> Option<usize> { None }
fn callstack_limit() -> usize { 1024 }
fn gas_extcode() -> Gas { Gas::from(700usize) }
fn gas_balance() -> Gas { Gas::from(400usize) }
fn gas_sload() -> Gas { Gas::from(200usize) }
fn gas_suicide() -> Gas { Gas::from(5000usize) }
fn gas_suicide_new_account() -> Gas { Gas::from(25000usize) }
fn gas_call() -> Gas { Gas::from(700usize) }
fn gas_expbyte() -> Gas { Gas::from(50usize) }
fn gas_transaction_create() -> Gas { Gas::from(32000usize) }
fn force_code_deposit() -> bool { false }
fn has_delegate_call() -> bool { true }
fn has_static_call() -> bool { false }
fn has_revert() -> bool { false }
fn has_return_data() -> bool { false }
fn err_on_call_with_more_gas() -> bool { false }
fn call_create_l64_after_gas() -> bool { true }
fn memory_limit() -> usize { usize::max_value() }
fn precompileds() -> &'static [(Address, Option<&'static [u8]>, &'static Precompiled)] {
&ETC_PRECOMPILEDS }
}
10 changes: 10 additions & 0 deletions network/ellaism/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "sputnikvm-network-ellaism"
version = "0.0.1"
license = "Apache-2.0"
authors = ["Wei Tang <[email protected]>"]
repository = "https://github.com/ethereumproject/sputnikvm"

[dependencies]
sputnikvm = { version = "0.9", path = "../.." }
etcommon-bigint = { version = "0.2", default-features = false }
58 changes: 58 additions & 0 deletions network/ellaism/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
extern crate bigint;
extern crate sputnikvm;

use std::marker::PhantomData;
use bigint::{Gas, U256, H160, Address};
use sputnikvm::{Precompiled, AccountPatch, Patch,
ID_PRECOMPILED, ECREC_PRECOMPILED, SHA256_PRECOMPILED, RIP160_PRECOMPILED};

pub static ELLA_PRECOMPILEDS: [(Address, Option<&'static [u8]>, &'static Precompiled); 4] = [
(H160([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x01]),
None,
&ECREC_PRECOMPILED),
(H160([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x02]),
None,
&SHA256_PRECOMPILED),
(H160([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x03]),
None,
&RIP160_PRECOMPILED),
(H160([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x04]),
None,
&ID_PRECOMPILED),
];

/// Mainnet account patch
pub struct MainnetAccountPatch;
impl AccountPatch for MainnetAccountPatch {
fn initial_nonce() -> U256 { U256::zero() }
fn initial_create_nonce() -> U256 { Self::initial_nonce() }
fn empty_considered_exists() -> bool { true }
}

/// EIP160 patch.
pub struct EIP160Patch<A: AccountPatch>(PhantomData<A>);
pub type MainnetEIP160Patch = EIP160Patch<MainnetAccountPatch>;
impl<A: AccountPatch> Patch for EIP160Patch<A> {
type Account = A;

fn code_deposit_limit() -> Option<usize> { None }
fn callstack_limit() -> usize { 1024 }
fn gas_extcode() -> Gas { Gas::from(700usize) }
fn gas_balance() -> Gas { Gas::from(400usize) }
fn gas_sload() -> Gas { Gas::from(200usize) }
fn gas_suicide() -> Gas { Gas::from(5000usize) }
fn gas_suicide_new_account() -> Gas { Gas::from(25000usize) }
fn gas_call() -> Gas { Gas::from(700usize) }
fn gas_expbyte() -> Gas { Gas::from(50usize) }
fn gas_transaction_create() -> Gas { Gas::from(32000usize) }
fn force_code_deposit() -> bool { false }
fn has_delegate_call() -> bool { true }
fn has_static_call() -> bool { false }
fn has_revert() -> bool { false }
fn has_return_data() -> bool { false }
fn err_on_call_with_more_gas() -> bool { false }
fn call_create_l64_after_gas() -> bool { true }
fn memory_limit() -> usize { usize::max_value() }
fn precompileds() -> &'static [(Address, Option<&'static [u8]>, &'static Precompiled)] {
&ELLA_PRECOMPILEDS }
}
12 changes: 12 additions & 0 deletions network/expanse/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "sputnikvm-network-expanse"
version = "0.0.1"
license = "Apache-2.0"
authors = ["Wei Tang <[email protected]>"]
repository = "https://github.com/ethereumproject/sputnikvm"

[dependencies]
sputnikvm = { version = "0.9", path = "../.." }
sputnikvm-precompiled-bn128 = { path = "../../precompiled/bn128" }
sputnikvm-precompiled-modexp = { path = "../../precompiled/modexp" }
etcommon-bigint = { version = "0.2", default-features = false }
Loading

0 comments on commit 3bc5d74

Please sign in to comment.