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

Commit da8c4df

Browse files
authored
v2.6.3-beta (rev2) (#11050)
* EIP 1884 Re-pricing of trie-size dependent operations (#10992) * Implement EIP-1283 reenable transition, EIP-1706 and EIP-2200 (#10191)
1 parent 06287c4 commit da8c4df

File tree

10 files changed

+120
-19
lines changed

10 files changed

+120
-19
lines changed

ethcore/evm/src/evm.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,18 @@ pub trait Finalize {
4444
impl Finalize for Result<GasLeft> {
4545
fn finalize<E: Ext>(self, ext: E) -> Result<FinalizationResult> {
4646
match self {
47-
Ok(GasLeft::Known(gas_left)) => Ok(FinalizationResult { gas_left: gas_left, apply_state: true, return_data: ReturnData::empty() }),
48-
Ok(GasLeft::NeedsReturn { gas_left, data, apply_state }) => ext.ret(&gas_left, &data, apply_state).map(|gas_left| FinalizationResult {
49-
gas_left: gas_left,
50-
apply_state: apply_state,
51-
return_data: data,
52-
}),
47+
Ok(GasLeft::Known(gas_left)) => {
48+
Ok(FinalizationResult {
49+
gas_left,
50+
apply_state: true,
51+
return_data: ReturnData::empty()
52+
})
53+
},
54+
Ok(GasLeft::NeedsReturn { gas_left, data, apply_state }) => {
55+
ext.ret(&gas_left, &data, apply_state).map(|gas_left|
56+
FinalizationResult { gas_left, apply_state, return_data: data }
57+
)
58+
},
5359
Err(err) => Err(err),
5460
}
5561
}

ethcore/evm/src/instructions.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ enum_with_from_u8! {
151151
GASLIMIT = 0x45,
152152
#[doc = "get chain ID"]
153153
CHAINID = 0x46,
154+
#[doc = "get balance of own account"]
155+
SELFBALANCE = 0x47,
154156

155157
#[doc = "remove item from stack"]
156158
POP = 0x50,
@@ -502,6 +504,7 @@ lazy_static! {
502504
arr[DIFFICULTY as usize] = Some(InstructionInfo::new("DIFFICULTY", 0, 1, GasPriceTier::Base));
503505
arr[GASLIMIT as usize] = Some(InstructionInfo::new("GASLIMIT", 0, 1, GasPriceTier::Base));
504506
arr[CHAINID as usize] = Some(InstructionInfo::new("CHAINID", 0, 1, GasPriceTier::Base));
507+
arr[SELFBALANCE as usize] = Some(InstructionInfo::new("SELFBALANCE", 0, 1, GasPriceTier::Low));
505508
arr[POP as usize] = Some(InstructionInfo::new("POP", 1, 0, GasPriceTier::Base));
506509
arr[MLOAD as usize] = Some(InstructionInfo::new("MLOAD", 1, 1, GasPriceTier::VeryLow));
507510
arr[MSTORE as usize] = Some(InstructionInfo::new("MSTORE", 2, 0, GasPriceTier::VeryLow));

ethcore/evm/src/interpreter/gasometer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ impl<Gas: evm::CostType> Gasometer<Gas> {
121121
Request::Gas(Gas::from(1))
122122
},
123123
instructions::SSTORE => {
124+
if schedule.eip1706 && self.current_gas <= Gas::from(schedule.call_stipend) {
125+
return Err(vm::Error::OutOfGas);
126+
}
127+
124128
let address = BigEndianHash::from_uint(stack.peek(0));
125129
let newval = stack.peek(1);
126130
let val = ext.storage_at(&address)?.into_uint();

ethcore/evm/src/interpreter/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,12 @@ impl<Cost: CostType> Interpreter<Cost> {
298298
let result = if self.gasometer.is_none() {
299299
InterpreterResult::Done(Err(vm::Error::OutOfGas))
300300
} else if self.reader.len() == 0 {
301-
InterpreterResult::Done(Ok(GasLeft::Known(self.gasometer.as_ref().expect("Gasometer None case is checked above; qed").current_gas.as_u256())))
301+
let current_gas = self.gasometer
302+
.as_ref()
303+
.expect("Gasometer None case is checked above; qed")
304+
.current_gas
305+
.as_u256();
306+
InterpreterResult::Done(Ok(GasLeft::Known(current_gas)))
302307
} else {
303308
self.step_inner(ext)
304309
};
@@ -307,7 +312,7 @@ impl<Cost: CostType> Interpreter<Cost> {
307312
self.done = true;
308313
self.informant.done();
309314
}
310-
return result;
315+
result
311316
}
312317

313318
/// Inner helper function for step.
@@ -436,7 +441,8 @@ impl<Cost: CostType> Interpreter<Cost> {
436441
(instruction == instructions::REVERT && !schedule.have_revert) ||
437442
((instruction == instructions::SHL || instruction == instructions::SHR || instruction == instructions::SAR) && !schedule.have_bitwise_shifting) ||
438443
(instruction == instructions::EXTCODEHASH && !schedule.have_extcodehash) ||
439-
(instruction == instructions::CHAINID && !schedule.have_chain_id)
444+
(instruction == instructions::CHAINID && !schedule.have_chain_id) ||
445+
(instruction == instructions::SELFBALANCE && !schedule.have_selfbalance)
440446
{
441447
return Err(vm::Error::BadInstruction {
442448
instruction: instruction as u8
@@ -854,6 +860,9 @@ impl<Cost: CostType> Interpreter<Cost> {
854860
instructions::CHAINID => {
855861
self.stack.push(ext.chain_id().into())
856862
},
863+
instructions::SELFBALANCE => {
864+
self.stack.push(ext.balance(&self.params.address)?);
865+
}
857866

858867
// Stack instructions
859868

ethcore/evm/src/tests.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,32 @@ fn test_origin(factory: super::Factory) {
109109
assert_store(&ext, 0, "000000000000000000000000cd1722f2947def4cf144679da39c4c32bdc35681");
110110
}
111111

112+
evm_test!{test_selfbalance: test_selfbalance_int}
113+
fn test_selfbalance(factory: super::Factory) {
114+
let own_addr = Address::from_str("1337000000000000000000000000000000000000").unwrap();
115+
// 47 SELFBALANCE
116+
// 60 ff PUSH ff
117+
// 55 SSTORE
118+
let code = hex!("47 60 ff 55").to_vec();
119+
120+
let mut params = ActionParams::default();
121+
params.address = own_addr.clone();
122+
params.gas = U256::from(100_000);
123+
params.code = Some(Arc::new(code));
124+
let mut ext = FakeExt::new_istanbul();
125+
ext.balances = {
126+
let mut x = HashMap::new();
127+
x.insert(own_addr, U256::from(1_025)); // 0x401
128+
x
129+
};
130+
let gas_left = {
131+
let vm = factory.create(params, ext.schedule(), ext.depth());
132+
test_finalize(vm.exec(&mut ext).ok().unwrap()).unwrap()
133+
};
134+
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
135+
assert_store(&ext, 0xff, "0000000000000000000000000000000000000000000000000000000000000401");
136+
}
137+
112138
evm_test!{test_sender: test_sender_int}
113139
fn test_sender(factory: super::Factory) {
114140
let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();

ethcore/src/spec/spec.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,16 @@ pub struct CommonParams {
121121
pub eip1283_transition: BlockNumber,
122122
/// Number of first block where EIP-1283 rules end.
123123
pub eip1283_disable_transition: BlockNumber,
124+
/// Number of first block where EIP-1283 rules re-enabled.
125+
pub eip1283_reenable_transition: BlockNumber,
124126
/// Number of first block where EIP-1014 rules begin.
125127
pub eip1014_transition: BlockNumber,
128+
/// Number of first block where EIP-1706 rules begin.
129+
pub eip1706_transition: BlockNumber,
126130
/// Number of first block where EIP-1344 rules begin: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1344.md
127131
pub eip1344_transition: BlockNumber,
132+
/// Number of first block where EIP-1884 rules begin:https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1884.md
133+
pub eip1884_transition: BlockNumber,
128134
/// Number of first block where EIP-2028 rules begin.
129135
pub eip2028_transition: BlockNumber,
130136
/// Number of first block where dust cleanup rules (EIP-168 and EIP169) begin.
@@ -194,7 +200,18 @@ impl CommonParams {
194200
schedule.have_bitwise_shifting = block_number >= self.eip145_transition;
195201
schedule.have_extcodehash = block_number >= self.eip1052_transition;
196202
schedule.have_chain_id = block_number >= self.eip1344_transition;
197-
schedule.eip1283 = block_number >= self.eip1283_transition && !(block_number >= self.eip1283_disable_transition);
203+
schedule.eip1283 =
204+
(block_number >= self.eip1283_transition &&
205+
!(block_number >= self.eip1283_disable_transition)) ||
206+
block_number >= self.eip1283_reenable_transition;
207+
schedule.eip1706 = block_number >= self.eip1706_transition;
208+
209+
if block_number >= self.eip1884_transition {
210+
schedule.have_selfbalance = true;
211+
schedule.sload_gas = 800;
212+
schedule.balance_gas = 700;
213+
schedule.extcodehash_gas = 700;
214+
}
198215
if block_number >= self.eip2028_transition {
199216
schedule.tx_data_non_zero_gas = 16;
200217
}
@@ -312,6 +329,14 @@ impl From<ethjson::spec::Params> for CommonParams {
312329
BlockNumber::max_value,
313330
Into::into,
314331
),
332+
eip1283_reenable_transition: p.eip1283_reenable_transition.map_or_else(
333+
BlockNumber::max_value,
334+
Into::into,
335+
),
336+
eip1706_transition: p.eip1706_transition.map_or_else(
337+
BlockNumber::max_value,
338+
Into::into,
339+
),
315340
eip1014_transition: p.eip1014_transition.map_or_else(
316341
BlockNumber::max_value,
317342
Into::into,
@@ -320,6 +345,10 @@ impl From<ethjson::spec::Params> for CommonParams {
320345
BlockNumber::max_value,
321346
Into::into,
322347
),
348+
eip1884_transition: p.eip1884_transition.map_or_else(
349+
BlockNumber::max_value,
350+
Into::into,
351+
),
323352
eip2028_transition: p.eip2028_transition.map_or_else(
324353
BlockNumber::max_value,
325354
Into::into,

ethcore/vm/src/ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub trait Ext {
9191

9292
/// Creates new contract.
9393
///
94-
/// Returns gas_left and contract address if contract creation was succesfull.
94+
/// Returns gas_left and contract address if contract creation was successful.
9595
fn create(
9696
&mut self,
9797
gas: &U256,

ethcore/vm/src/return_data.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ impl ReturnData {
4444
}
4545
/// Create `ReturnData` from give buffer and slice.
4646
pub fn new(mem: Vec<u8>, offset: usize, size: usize) -> Self {
47-
ReturnData {
48-
mem: mem,
49-
offset: offset,
50-
size: size,
51-
}
47+
ReturnData { mem, offset, size }
5248
}
5349
}
5450

ethcore/vm/src/schedule.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,17 @@
1515
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
1616

1717
//! Cost schedule and other parameterisations for the EVM.
18+
use std::collections::HashMap;
19+
use ethereum_types::U256;
20+
21+
/// Definition of schedules that can be applied to a version.
22+
#[derive(Debug)]
23+
pub enum VersionedSchedule {
24+
PWasm,
25+
}
1826

1927
/// Definition of the cost schedule and other parameterisations for the EVM.
28+
#[derive(Debug)]
2029
pub struct Schedule {
2130
/// Does it support exceptional failed code deposit
2231
pub exceptional_failed_code_deposit: bool,
@@ -117,17 +126,22 @@ pub struct Schedule {
117126
pub have_bitwise_shifting: bool,
118127
/// CHAINID opcode enabled.
119128
pub have_chain_id: bool,
129+
/// SELFBALANCE opcode enabled.
130+
pub have_selfbalance: bool,
120131
/// Kill basic accounts below this balance if touched.
121132
pub kill_dust: CleanDustMode,
122133
/// Enable EIP-1283 rules
123134
pub eip1283: bool,
135+
/// Enable EIP-1706 rules
136+
pub eip1706: bool,
124137
/// VM execution does not increase null signed address nonce if this field is true.
125138
pub keep_unsigned_nonce: bool,
126139
/// Wasm extra schedule settings, if wasm activated
127140
pub wasm: Option<WasmCosts>,
128141
}
129142

130143
/// Wasm cost table
144+
#[derive(Debug)]
131145
pub struct WasmCosts {
132146
/// Default opcode cost
133147
pub regular: u32,
@@ -181,7 +195,7 @@ impl Default for WasmCosts {
181195
}
182196

183197
/// Dust accounts cleanup mode.
184-
#[derive(PartialEq, Eq)]
198+
#[derive(Debug, PartialEq, Eq)]
185199
pub enum CleanDustMode {
186200
/// Dust cleanup is disabled.
187201
Off,
@@ -212,6 +226,7 @@ impl Schedule {
212226
have_return_data: false,
213227
have_bitwise_shifting: false,
214228
have_chain_id: false,
229+
have_selfbalance: false,
215230
have_extcodehash: false,
216231
stack_limit: 1024,
217232
max_depth: 1024,
@@ -256,6 +271,7 @@ impl Schedule {
256271
have_static_call: false,
257272
kill_dust: CleanDustMode::Off,
258273
eip1283: false,
274+
eip1706: false,
259275
keep_unsigned_nonce: false,
260276
wasm: None,
261277
}
@@ -281,8 +297,12 @@ impl Schedule {
281297
/// Schedule for the Istanbul fork of the Ethereum main net.
282298
pub fn new_istanbul() -> Schedule {
283299
let mut schedule = Self::new_constantinople();
284-
schedule.have_chain_id = true;
285-
schedule.tx_data_non_zero_gas = 16;
300+
schedule.have_chain_id = true; // EIP 1344
301+
schedule.tx_data_non_zero_gas = 16; // EIP 2028
302+
schedule.sload_gas = 800; // EIP 1884
303+
schedule.balance_gas = 700; // EIP 1884
304+
schedule.extcodehash_gas = 700; // EIP 1884
305+
schedule.have_selfbalance = true; // EIP 1884
286306
schedule
287307
}
288308

@@ -295,6 +315,7 @@ impl Schedule {
295315
have_return_data: false,
296316
have_bitwise_shifting: false,
297317
have_chain_id: false,
318+
have_selfbalance: false,
298319
have_extcodehash: false,
299320
stack_limit: 1024,
300321
max_depth: 1024,
@@ -339,6 +360,7 @@ impl Schedule {
339360
have_static_call: false,
340361
kill_dust: CleanDustMode::Off,
341362
eip1283: false,
363+
eip1706: false,
342364
keep_unsigned_nonce: false,
343365
wasm: None,
344366
}

json/src/spec/params.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,16 @@ pub struct Params {
9292
/// See `CommonParams` docs.
9393
pub eip1283_disable_transition: Option<Uint>,
9494
/// See `CommonParams` docs.
95+
pub eip1283_reenable_transition: Option<Uint>,
96+
/// See `CommonParams` docs.
9597
pub eip1014_transition: Option<Uint>,
9698
/// See `CommonParams` docs.
99+
pub eip1706_transition: Option<Uint>,
100+
/// See `CommonParams` docs.
97101
pub eip1344_transition: Option<Uint>,
98102
/// See `CommonParams` docs.
103+
pub eip1884_transition: Option<Uint>,
104+
/// See `CommonParams` docs.
99105
pub eip2028_transition: Option<Uint>,
100106
/// See `CommonParams` docs.
101107
pub dust_protection_transition: Option<Uint>,

0 commit comments

Comments
 (0)