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

EIP 1884 Re-pricing of trie-size dependent operations #10992

Merged
merged 120 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
ddeef45
Add client-traits crate
dvdplm Aug 6, 2019
0d49c45
New crate `machine`
dvdplm Aug 6, 2019
0465e6b
Use new machine and client-traits crates in ethcore
dvdplm Aug 6, 2019
50ca45a
Use new crates machine and client-traits instead of ethcore where app…
dvdplm Aug 6, 2019
29d4095
Fix tests
dvdplm Aug 6, 2019
cd6e0e2
Don't re-export so many types from ethcore::client
dvdplm Aug 6, 2019
2477cbd
Fixing more fallout from removing re-export
dvdplm Aug 6, 2019
51ba2f4
Merge branch 'master' into dp/chore/move-machine-to-own-crate
dvdplm Aug 6, 2019
c84a01f
fix test
dvdplm Aug 7, 2019
f2497f4
More fallout from not re-exporting types
dvdplm Aug 7, 2019
1e43534
Add some docs
dvdplm Aug 7, 2019
6d83cf2
cleanup
dvdplm Aug 7, 2019
e04d188
import the macro edition style
dvdplm Aug 7, 2019
b6e91de
Merge branch 'master' into dp/chore/move-machine-to-own-crate
dvdplm Aug 7, 2019
bac7268
Tweak docs
dvdplm Aug 7, 2019
978eb88
Add missing import
dvdplm Aug 7, 2019
d6273a7
Merge branch 'master' into dp/chore/move-machine-to-own-crate
dvdplm Aug 8, 2019
18d6a94
remove unused ethabi_derive imports
dvdplm Aug 8, 2019
d5700d9
Use latest ethabi-contract
dvdplm Aug 8, 2019
83bb140
Move many traits from ethcore/client/traits to client-traits crate
dvdplm Aug 9, 2019
d96fff3
Move snapshot related traits to the engine crate (eew)
dvdplm Aug 9, 2019
33aa152
Move a few snapshot related types to common_types
dvdplm Aug 9, 2019
9b70856
fix warning
dvdplm Aug 9, 2019
f76e5ed
Gradually introduce new engine crate: snapshot
dvdplm Aug 9, 2019
5b3a8ca
ethcore typechecks with new engine crate
dvdplm Aug 9, 2019
cecd69c
Sort out types outside ethcore
dvdplm Aug 10, 2019
c5ab534
Add an EpochVerifier to ethash and use that in Engine.epoch_verifier()
dvdplm Aug 10, 2019
45c0497
Document pub members
dvdplm Aug 10, 2019
b11a21f
Sort out tests
dvdplm Aug 10, 2019
af485cc
Add test-helpers feature and move EngineSigner impl to the right place
dvdplm Aug 10, 2019
f617bcb
Sort out tests
dvdplm Aug 10, 2019
64b5c60
Sort out tests and refactor verification types
dvdplm Aug 10, 2019
b1b6b46
Fix missing traits
dvdplm Aug 10, 2019
881b71f
More missing traits
dvdplm Aug 10, 2019
ddca9ee
Fix tests and cleanup
dvdplm Aug 10, 2019
d7d3f4b
cleanup
dvdplm Aug 10, 2019
b2f8be6
Put back needed logger import
dvdplm Aug 10, 2019
8ab2a02
Don't rexport common_types from ethcore/src/client
dvdplm Aug 10, 2019
4aef5f2
Remove files no longer used
dvdplm Aug 10, 2019
951f63e
Get rid of itertools
dvdplm Aug 10, 2019
1c42cc1
Move a few more traits from ethcore to client-traits: BlockChainReset…
dvdplm Aug 10, 2019
07b1c2d
Move ProvingBlockChainClient to client-traits
dvdplm Aug 10, 2019
7e5e4bc
Don't re-export ForkChoice and Transition from ethcore
dvdplm Aug 10, 2019
b244bfb
Address grumbles: sort imports, remove commented out code
dvdplm Aug 13, 2019
37be7b2
Merge branch 'master' into dp/chore/extract-engine-trait
dvdplm Aug 13, 2019
88cfa7f
Fix merge resolution error
dvdplm Aug 13, 2019
f4c9b9c
Extract the Clique engine to own crate
dvdplm Aug 13, 2019
5e307ab
Extract NullEngine and the block_reward module from ethcore
dvdplm Aug 13, 2019
db12d1b
Extract InstantSeal engine to own crate
dvdplm Aug 13, 2019
e9e9d62
Extract remaining engines
dvdplm Aug 14, 2019
0f5e970
Extract executive_state to own crate so it can be used by engine crates
dvdplm Aug 14, 2019
e7ba4a5
Remove snapshot stuff from the engine crate
dvdplm Aug 14, 2019
c9dca59
Put snapshot traits back in ethcore
dvdplm Aug 14, 2019
6e3b365
cleanup
dvdplm Aug 14, 2019
c92751a
Remove stuff from ethcore
dvdplm Aug 14, 2019
61b0dd6
Don't use itertools
dvdplm Aug 14, 2019
c79b7e2
itertools in aura is legit-ish
dvdplm Aug 15, 2019
42e1d57
Merge branch 'master' into dp/chore/extract-clique
dvdplm Aug 15, 2019
663f13e
More post-merge fixes
dvdplm Aug 15, 2019
0bd9176
Re-export less types in client
dvdplm Aug 16, 2019
0bd3713
cleanup
dvdplm Aug 16, 2019
7adcba0
Extract spec to own crate
dvdplm Aug 16, 2019
43206dd
Put back the test-helpers from basic-authority
dvdplm Aug 16, 2019
4f76b1e
Fix ethcore benchmarks
dvdplm Aug 16, 2019
9a53c45
Reduce the public api of ethcore/verification
dvdplm Aug 16, 2019
5acd488
WIP
dvdplm Aug 19, 2019
77e03ae
Add Cargo.toml
dvdplm Aug 19, 2019
d17ab43
Fix compilation outside ethcore
dvdplm Aug 19, 2019
208a3eb
Audit uses of import_verified_blocks() and remove unneeded calls
dvdplm Aug 19, 2019
2ba0a5d
cleanup
dvdplm Aug 19, 2019
acc461f
Remove unused imports from ethcore
dvdplm Aug 19, 2019
b164c4b
Cleanup
dvdplm Aug 19, 2019
b38ae1c
remove double semi-colons
dvdplm Aug 20, 2019
79e6000
Merge branch 'master' into dp/chore/extract-spec-from-ethcore
dvdplm Aug 20, 2019
6cd8b0d
Merge branch 'master' into dp/chore/sort-out-ClientIoMessage
dvdplm Aug 20, 2019
451f540
Add missing generic param
dvdplm Aug 20, 2019
0c4991a
More missing generics
dvdplm Aug 21, 2019
fbe0365
Update ethcore/block-reward/Cargo.toml
dvdplm Aug 21, 2019
fdd35c7
Update ethcore/engines/basic-authority/Cargo.toml
dvdplm Aug 21, 2019
0be9f98
Update ethcore/engines/ethash/Cargo.toml
dvdplm Aug 21, 2019
8fc5929
Update ethcore/engines/clique/src/lib.rs
dvdplm Aug 21, 2019
8077b51
signers is already a ref
dvdplm Aug 21, 2019
7f5c4d3
Add an EngineType enum to tighten up Engine.name()
dvdplm Aug 21, 2019
56b21cf
Add CHAINID opcode
dvdplm Aug 21, 2019
a22870d
Introduce Snapshotting enum to distinguish the type of snapshots a ch…
dvdplm Aug 21, 2019
791e99a
Rename supports_warp to snapshot_mode
dvdplm Aug 21, 2019
77e76f1
Missing import
dvdplm Aug 21, 2019
bcd43d6
Add chain_id wherever we instantiate EnvInfo
dvdplm Aug 21, 2019
08efe7f
more missing chain_id
dvdplm Aug 21, 2019
ea03b69
Tell serde to ignore the chain_id field on Env
dvdplm Aug 21, 2019
ad35cb1
Update ethcore/src/snapshot/consensus/mod.rs
dvdplm Aug 21, 2019
081e40e
Merge branch 'master' into dp/chore/extract-clique
dvdplm Aug 21, 2019
eb14ba5
Use the chain_id from the machine by adding chain_id() to the Ext trait
dvdplm Aug 22, 2019
792e84e
Merge branch 'master' into dp/chore/extract-clique
dvdplm Aug 22, 2019
d438b6a
cleanup
dvdplm Aug 22, 2019
a39199b
add missing impl
dvdplm Aug 22, 2019
70a5f87
Merge branch 'dp/chore/extract-clique' into dp/chore/extract-spec-fro…
dvdplm Aug 22, 2019
94c0a67
missing import
dvdplm Aug 22, 2019
567d96c
Fix import
dvdplm Aug 22, 2019
e20af45
Add transition marker for EIP 1344
dvdplm Aug 22, 2019
c49895c
Merge branch 'master' into dp/chore/extract-spec-from-ethcore
dvdplm Aug 22, 2019
b34cfc4
double semi
dvdplm Aug 23, 2019
8a8e90a
Merge branch 'dp/chore/extract-spec-from-ethcore' into dp/chore/sort-…
dvdplm Aug 23, 2019
3f8aecd
Fix merge problem
dvdplm Aug 23, 2019
3ca11c0
Merge branch 'master' into dp/chore/sort-out-ClientIoMessage
dvdplm Aug 25, 2019
55e74fe
Merge branch 'dp/chore/sort-out-ClientIoMessage' into dp/feature/eip-…
dvdplm Aug 25, 2019
1fc96cc
cleanup
dvdplm Aug 26, 2019
73afcba
reprice SLOAD to 800 gas
dvdplm Aug 27, 2019
8389662
Reprice BALANCE and EXTCODEHASH
dvdplm Aug 27, 2019
988c6f0
Add SELFBALANCE opcode
dvdplm Aug 27, 2019
2fde5a2
Add test for SELFBALANCE
dvdplm Aug 27, 2019
e0eca17
Use easier to read values in test
dvdplm Aug 27, 2019
e28fce7
Merge branch 'master' into dp/feature/eip-1344-add-ChainID-opcode
dvdplm Aug 28, 2019
21980e8
merge conflict error
dvdplm Aug 28, 2019
d61a8fd
Fix a few warnings
dvdplm Aug 28, 2019
b37cfff
Update ethcore/vm/src/schedule.rs
dvdplm Aug 28, 2019
fb67175
more merge fallout
dvdplm Aug 28, 2019
df61eb6
Merge branch 'dp/feature/eip-1344-add-ChainID-opcode' of github.com:p…
dvdplm Aug 28, 2019
9903dd1
Merge branch 'dp/feature/eip-1344-add-ChainID-opcode' into dp/feature…
dvdplm Aug 28, 2019
0e4762c
Merge branch 'master' into dp/feature/eip-1884-reprice-trie-size-depe…
dvdplm Aug 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions ethcore/evm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ pub trait Finalize {
impl Finalize for Result<GasLeft> {
fn finalize<E: Ext>(self, ext: E) -> Result<FinalizationResult> {
match self {
Ok(GasLeft::Known(gas_left)) => Ok(FinalizationResult { gas_left: gas_left, apply_state: true, return_data: ReturnData::empty() }),
Ok(GasLeft::NeedsReturn { gas_left, data, apply_state }) => ext.ret(&gas_left, &data, apply_state).map(|gas_left| FinalizationResult {
gas_left: gas_left,
apply_state: apply_state,
return_data: data,
}),
Ok(GasLeft::Known(gas_left)) => {
Ok(FinalizationResult {
gas_left,
apply_state: true,
return_data: ReturnData::empty()
})
},
Ok(GasLeft::NeedsReturn { gas_left, data, apply_state }) => {
ext.ret(&gas_left, &data, apply_state).map(|gas_left|
FinalizationResult { gas_left, apply_state, return_data: data }
)
},
Err(err) => Err(err),
}
}
Expand Down
3 changes: 3 additions & 0 deletions ethcore/evm/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ enum_with_from_u8! {
GASLIMIT = 0x45,
#[doc = "get chain ID"]
CHAINID = 0x46,
#[doc = "get balance of own account"]
SELFBALANCE = 0x47,

#[doc = "remove item from stack"]
POP = 0x50,
Expand Down Expand Up @@ -502,6 +504,7 @@ lazy_static! {
arr[DIFFICULTY as usize] = Some(InstructionInfo::new("DIFFICULTY", 0, 1, GasPriceTier::Base));
arr[GASLIMIT as usize] = Some(InstructionInfo::new("GASLIMIT", 0, 1, GasPriceTier::Base));
arr[CHAINID as usize] = Some(InstructionInfo::new("CHAINID", 0, 1, GasPriceTier::Base));
arr[SELFBALANCE as usize] = Some(InstructionInfo::new("SELFBALANCE", 0, 1, GasPriceTier::Low));
arr[POP as usize] = Some(InstructionInfo::new("POP", 1, 0, GasPriceTier::Base));
arr[MLOAD as usize] = Some(InstructionInfo::new("MLOAD", 1, 1, GasPriceTier::VeryLow));
arr[MSTORE as usize] = Some(InstructionInfo::new("MSTORE", 2, 0, GasPriceTier::VeryLow));
Expand Down
15 changes: 12 additions & 3 deletions ethcore/evm/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,12 @@ impl<Cost: CostType> Interpreter<Cost> {
let result = if self.gasometer.is_none() {
InterpreterResult::Done(Err(vm::Error::OutOfGas))
} else if self.reader.len() == 0 {
InterpreterResult::Done(Ok(GasLeft::Known(self.gasometer.as_ref().expect("Gasometer None case is checked above; qed").current_gas.as_u256())))
let current_gas = self.gasometer
.as_ref()
.expect("Gasometer None case is checked above; qed")
.current_gas
.as_u256();
InterpreterResult::Done(Ok(GasLeft::Known(current_gas)))
} else {
self.step_inner(ext)
};
Expand All @@ -308,7 +313,7 @@ impl<Cost: CostType> Interpreter<Cost> {
self.done = true;
self.informant.done();
}
return result;
result
}

/// Inner helper function for step.
Expand Down Expand Up @@ -429,7 +434,8 @@ impl<Cost: CostType> Interpreter<Cost> {
(instruction == instructions::REVERT && !schedule.have_revert) ||
((instruction == instructions::SHL || instruction == instructions::SHR || instruction == instructions::SAR) && !schedule.have_bitwise_shifting) ||
(instruction == instructions::EXTCODEHASH && !schedule.have_extcodehash) ||
(instruction == instructions::CHAINID && !schedule.have_chain_id)
(instruction == instructions::CHAINID && !schedule.have_chain_id) ||
(instruction == instructions::SELFBALANCE && !schedule.have_selfbalance)
{
return Err(vm::Error::BadInstruction {
instruction: instruction as u8
Expand Down Expand Up @@ -847,6 +853,9 @@ impl<Cost: CostType> Interpreter<Cost> {
instructions::CHAINID => {
self.stack.push(ext.chain_id().into())
},
instructions::SELFBALANCE => {
self.stack.push(ext.balance(&self.params.address)?);
}

// Stack instructions

Expand Down
26 changes: 26 additions & 0 deletions ethcore/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,32 @@ fn test_origin(factory: super::Factory) {
assert_store(&ext, 0, "000000000000000000000000cd1722f2947def4cf144679da39c4c32bdc35681");
}

evm_test!{test_selfbalance: test_selfbalance_int}
fn test_selfbalance(factory: super::Factory) {
let own_addr = Address::from_str("1337000000000000000000000000000000000000").unwrap();
// 47 SELFBALANCE
// 60 ff PUSH ff
// 55 SSTORE
let code = hex!("47 60 ff 55").to_vec();

let mut params = ActionParams::default();
params.address = own_addr.clone();
params.gas = U256::from(100_000);
params.code = Some(Arc::new(code));
let mut ext = FakeExt::new_istanbul();
ext.balances = {
let mut x = HashMap::new();
x.insert(own_addr, U256::from(1_025)); // 0x401
x
};
let gas_left = {
let vm = factory.create(params, ext.schedule(), ext.depth());
test_finalize(vm.exec(&mut ext).ok().unwrap()).unwrap()
};
assert_eq!(gas_left, U256::from(79_992)); // TODO[dvdplm]: do the sums here, SELFBALANCE-5 + PUSH1-3 + ONEBYTE-4 + SSTORE-?? = 100_000 - 79_992
assert_store(&ext, 0xff, "0000000000000000000000000000000000000000000000000000000000000401");
}

evm_test!{test_sender: test_sender_int}
fn test_sender(factory: super::Factory) {
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
Expand Down
13 changes: 13 additions & 0 deletions ethcore/types/src/engines/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ pub struct CommonParams {
pub eip1014_transition: BlockNumber,
/// Number of first block where EIP-1344 rules begin: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1344.md
pub eip1344_transition: BlockNumber,
/// Number of first block where EIP-1884 rules begin:https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1884.md
pub eip1884_transition: BlockNumber,
/// Number of first block where EIP-2028 rules begin.
pub eip2028_transition: BlockNumber,
/// Number of first block where dust cleanup rules (EIP-168 and EIP169) begin.
Expand Down Expand Up @@ -165,6 +167,13 @@ impl CommonParams {
schedule.have_extcodehash = block_number >= self.eip1052_transition;
schedule.have_chain_id = block_number >= self.eip1344_transition;
schedule.eip1283 = block_number >= self.eip1283_transition && !(block_number >= self.eip1283_disable_transition);

if block_number >= self.eip1884_transition {
schedule.have_selfbalance = true;
schedule.sload_gas = 800;
schedule.balance_gas = 700;
schedule.extcodehash_gas = 700;
}
if block_number >= self.eip2028_transition {
schedule.tx_data_non_zero_gas = 16;
}
Expand Down Expand Up @@ -289,6 +298,10 @@ impl From<ethjson::spec::Params> for CommonParams {
BlockNumber::max_value,
Into::into,
),
eip1884_transition: p.eip1884_transition.map_or_else(
BlockNumber::max_value,
Into::into,
),
eip2028_transition: p.eip2028_transition.map_or_else(
BlockNumber::max_value,
Into::into,
Expand Down
2 changes: 1 addition & 1 deletion ethcore/vm/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub trait Ext {

/// Creates new contract.
///
/// Returns gas_left and contract address if contract creation was succesfull.
/// Returns gas_left and contract address if contract creation was successful.
fn create(
&mut self,
gas: &U256,
Expand Down
6 changes: 1 addition & 5 deletions ethcore/vm/src/return_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ impl ReturnData {
}
/// Create `ReturnData` from give buffer and slice.
pub fn new(mem: Vec<u8>, offset: usize, size: usize) -> Self {
ReturnData {
mem: mem,
offset: offset,
size: size,
}
ReturnData { mem, offset, size }
}
}

Expand Down
17 changes: 14 additions & 3 deletions ethcore/vm/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ use std::collections::HashMap;
use ethereum_types::U256;

/// Definition of schedules that can be applied to a version.
#[derive(Debug)]
pub enum VersionedSchedule {
PWasm,
}

/// Definition of the cost schedule and other parameterisations for the EVM.
#[derive(Debug)]
pub struct Schedule {
/// Does it support exceptional failed code deposit
pub exceptional_failed_code_deposit: bool,
Expand Down Expand Up @@ -124,6 +126,8 @@ pub struct Schedule {
pub have_bitwise_shifting: bool,
/// CHAINID opcode enabled.
pub have_chain_id: bool,
/// SELFBALANCE opcode enabled.
pub have_selfbalance: bool,
/// Kill basic accounts below this balance if touched.
pub kill_dust: CleanDustMode,
/// Enable EIP-1283 rules
Expand All @@ -139,6 +143,7 @@ pub struct Schedule {
}

/// Wasm cost table
#[derive(Debug)]
pub struct WasmCosts {
/// Default opcode cost
pub regular: u32,
Expand Down Expand Up @@ -192,7 +197,7 @@ impl Default for WasmCosts {
}

/// Dust accounts cleanup mode.
#[derive(PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq)]
pub enum CleanDustMode {
/// Dust cleanup is disabled.
Off,
Expand Down Expand Up @@ -223,6 +228,7 @@ impl Schedule {
have_return_data: false,
have_bitwise_shifting: false,
have_chain_id: false,
have_selfbalance: false,
have_extcodehash: false,
stack_limit: 1024,
max_depth: 1024,
Expand Down Expand Up @@ -294,8 +300,12 @@ impl Schedule {
/// Schedule for the Istanbul fork of the Ethereum main net.
pub fn new_istanbul() -> Schedule {
let mut schedule = Self::new_constantinople();
schedule.have_chain_id = true;
schedule.tx_data_non_zero_gas = 16;
schedule.have_chain_id = true; // EIP 1344
schedule.tx_data_non_zero_gas = 16; // EIP 2028
schedule.sload_gas = 800; // EIP 1884
schedule.balance_gas = 700; // EIP 1884
schedule.extcodehash_gas = 700; // EIP 1884
schedule.have_selfbalance = true; // EIP 1884
schedule
}

Expand All @@ -308,6 +318,7 @@ impl Schedule {
have_return_data: false,
have_bitwise_shifting: false,
have_chain_id: false,
have_selfbalance: false,
have_extcodehash: false,
stack_limit: 1024,
max_depth: 1024,
Expand Down
2 changes: 2 additions & 0 deletions json/src/spec/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub struct Params {
/// See `CommonParams` docs.
pub eip1344_transition: Option<Uint>,
/// See `CommonParams` docs.
pub eip1884_transition: Option<Uint>,
/// See `CommonParams` docs.
pub eip2028_transition: Option<Uint>,
/// See `CommonParams` docs.
pub dust_protection_transition: Option<Uint>,
Expand Down