Skip to content

Commit e210881

Browse files
authored
Merge pull request #8 from s1na/update-parity
Update upstream parity
2 parents 0376ff4 + cf1cddc commit e210881

File tree

4 files changed

+54
-44
lines changed

4 files changed

+54
-44
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ewasm_api = { git = "https://github.com/ewasm/ewasm-rust-api", tag = "0.4.0" }
1212
#ewasm_api = { path = "../ewasm-rust-api" }
1313
evm = { path = "parity-ethereum/ethcore/evm" }
1414
vm = { path = "parity-ethereum/ethcore/vm" }
15-
ethereum-types = "0.3"
15+
ethereum-types = "0.4"
1616
parity-bytes = { git = "https://github.com/paritytech/parity-common" }
1717

1818
[lib]

build.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ set -e
44

55
# build interpreter
66
cargo build --release --target wasm32-unknown-unknown
7-
echo "Code size after compilation: $(stat -f%z target/wasm32-unknown-unknown/release/runevm.wasm)"
7+
echo "Code size after compilation: $(wc -c < target/wasm32-unknown-unknown/release/runevm.wasm)"
88

99
# strip code
10-
wasm-gc target/wasm32-unknown-unknown/release/runevm.wasm
11-
echo "Code size after stripping: $(stat -f%z target/wasm32-unknown-unknown/release/runevm.wasm)"
10+
chisel target/wasm32-unknown-unknown/release/runevm.wasm target/wasm32-unknown-unknown/release/runevm.wasm
11+
echo "Code size after stripping: $(wc -c < target/wasm32-unknown-unknown/release/runevm.wasm)"
1212

1313
# build deployer
14-
./wat2wasm -o target/deployer.wasm src/deployer.wast
14+
wat2wasm -o target/deployer.wasm src/deployer.wast
1515

1616
# calculate size
17-
size=$(stat -f%z target/wasm32-unknown-unknown/release/runevm.wasm)
17+
size=$(wc -c < target/wasm32-unknown-unknown/release/runevm.wasm)
1818
# store the file size as a 32-bit little endian number
1919
printf "0: %.8x" $size | sed -E 's/0: (..)(..)(..)(..)/0: \4\3\2\1/' | xxd -r -g0 >target/le32size.bin
2020
echo "Interpreter code size: $size"
2121

2222
# create deployment code
2323
cat target/deployer.wasm target/wasm32-unknown-unknown/release/runevm.wasm target/le32size.bin >target/runevm.wasm
2424
echo "Built evm2wasm compatible version as target/runevm.wasm"
25-
echo "Total size: $(stat -f%z target/runevm.wasm)"
25+
echo "Total size: $(wc -c < target/runevm.wasm)"

parity-ethereum

src/lib.rs

+46-36
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ use self::ethereum_types::{Address, H160, H256, U128, U256};
1212

1313
use self::bytes::Bytes;
1414

15+
use self::evm::Ext;
1516
use self::evm::Factory;
1617

1718
use self::vm::{
1819
ActionParams, ActionValue, CallType, CleanDustMode, ContractCreateResult,
1920
CreateContractAddress, EnvInfo, GasLeft, MessageCallResult, Result, ReturnData, Schedule,
21+
TrapKind,
2022
};
2123

2224
// For some explanation see ethcore/vm/src/tests.rs::FakeExt
@@ -29,6 +31,11 @@ struct EwasmExt {
2931
}
3032

3133
impl vm::Ext for EwasmExt {
34+
/// Returns the storage value for a given key if reversion happens on the current transaction.
35+
fn initial_storage_at(&self, key: &H256) -> Result<H256> {
36+
unimplemented!()
37+
}
38+
3239
/// Returns a value for given key.
3340
fn storage_at(&self, key: &H256) -> Result<H256> {
3441
// FIXME: why isn't there a From trait for converting between [u8;32] and H256?
@@ -90,7 +97,8 @@ impl vm::Ext for EwasmExt {
9097
value: &U256,
9198
code: &[u8],
9299
address: CreateContractAddress,
93-
) -> ContractCreateResult {
100+
trap: bool,
101+
) -> ::std::result::Result<ContractCreateResult, TrapKind> {
94102
// FIXME: implement
95103
unimplemented!()
96104
// ContractCreateResult::Failed
@@ -109,9 +117,9 @@ impl vm::Ext for EwasmExt {
109117
value: Option<U256>,
110118
data: &[u8],
111119
code_address: &Address,
112-
output: &mut [u8],
113120
call_type: CallType,
114-
) -> MessageCallResult {
121+
trap: bool,
122+
) -> ::std::result::Result<MessageCallResult, TrapKind> {
115123
// FIXME: set this properly
116124
//let gas_limit = u64::from(gas);
117125
let gas_limit = gas.as_u64();
@@ -148,26 +156,22 @@ impl vm::Ext for EwasmExt {
148156
// Retrieve the entire returndata as it needs to be returned
149157
let ret = ewasm_api::returndata_acquire();
150158

151-
// Copy from returndata into the requested output len
152-
// The requested len may be smaller than available or returndata may be smaller than requested
153-
let copy_len = cmp::min(output.len(), ret.len());
154-
output.copy_from_slice(&ret[0..copy_len]);
155-
156159
let ret_len = ret.len();
157-
MessageCallResult::Success(gas_used, ReturnData::new(ret, 0, ret_len))
160+
Ok(MessageCallResult::Success(
161+
gas_used,
162+
ReturnData::new(ret, 0, ret_len),
163+
))
158164
}
159-
ewasm_api::CallResult::Failure => MessageCallResult::Failed,
165+
ewasm_api::CallResult::Failure => Ok(MessageCallResult::Failed),
160166
ewasm_api::CallResult::Revert => {
161167
// Retrieve the entire returndata as it needs to be returned
162168
let ret = ewasm_api::returndata_acquire();
163169

164-
// Copy from returndata into the requested output len
165-
// The requested len may be smaller than available or returndata may be smaller than requested
166-
let copy_len = cmp::min(output.len(), ret.len());
167-
output.copy_from_slice(&ret[0..copy_len]);
168-
169170
let ret_len = ret.len();
170-
MessageCallResult::Reverted(gas_used, ReturnData::new(ret, 0, ret_len))
171+
Ok(MessageCallResult::Reverted(
172+
gas_used,
173+
ReturnData::new(ret, 0, ret_len),
174+
))
171175
}
172176
}
173177

@@ -234,10 +238,14 @@ impl vm::Ext for EwasmExt {
234238
0
235239
}
236240

237-
/// Increments sstore refunds count by 1.
238-
fn inc_sstore_clears(&mut self) {
239-
// NOTE: used for gas refund on SSTORE deletion (non-zero to zero)
240-
// FIXME: implement
241+
/// Increments sstore refunds counter.
242+
fn add_sstore_refund(&mut self, value: usize) {
243+
unimplemented!()
244+
}
245+
246+
/// Decrements sstore refunds counter.
247+
fn sub_sstore_refund(&mut self, value: usize) {
248+
unimplemented!()
241249
}
242250

243251
/// Decide if any more operations should be traced. Passthrough for the VM trace.
@@ -246,18 +254,19 @@ impl vm::Ext for EwasmExt {
246254
}
247255

248256
/// Prepare to trace an operation. Passthrough for the VM trace.
249-
fn trace_prepare_execute(&mut self, _pc: usize, _instruction: u8, _gas_cost: U256) {}
250-
251-
/// Trace the finalised execution of a single instruction.
252-
fn trace_executed(
257+
fn trace_prepare_execute(
253258
&mut self,
254-
_gas_used: U256,
255-
_stack_push: &[U256],
256-
_mem_diff: Option<(usize, &[u8])>,
257-
_store_diff: Option<(U256, U256)>,
259+
_pc: usize,
260+
_instruction: u8,
261+
_gas_cost: U256,
262+
_mem_written: Option<(usize, usize)>,
263+
_store_written: Option<(U256, U256)>,
258264
) {
259265
}
260266

267+
/// Trace the finalised execution of a single instruction.
268+
fn trace_executed(&mut self, _gas_used: U256, _stack_push: &[U256], _mem: &[u8]) {}
269+
261270
/// Check if running in static context.
262271
fn is_static(&self) -> bool {
263272
// NOTE: this is used by CREATE/CALL*, but since ewasm in the upper layer will handle this anyway, we can just ignore it here
@@ -267,11 +276,8 @@ impl vm::Ext for EwasmExt {
267276

268277
#[no_mangle]
269278
pub extern "C" fn main() {
270-
// It is fine using U256::zero() here because the main point of the
271-
// factory is to determine if gas is 64bit or not. In ewasm it is always 64bit.
272-
let mut instance = Factory::default().create(&U256::zero());
273-
274279
let mut params = ActionParams::default();
280+
275281
// FIXME: do we need to set this?
276282
// params.call_type = if code.is_none() { CallType::Call } else { CallType::None };
277283
params.code_address = Address::from(ewasm_api::current_address());
@@ -285,22 +291,26 @@ pub extern "C" fn main() {
285291
params.data = Some(ewasm_api::calldata_acquire());
286292

287293
let mut ext = EwasmExt::default();
288-
let result = instance.exec(params, &mut ext);
294+
295+
let mut instance = Factory::default().create(params, ext.schedule(), ext.depth());
296+
let result = instance.exec(&mut ext);
289297
// Could run `result.finalize(ext)` here, but processing manually seemed simpler.
290298
match result {
291-
Ok(GasLeft::Known(gas_left)) => {
299+
Ok(Ok(GasLeft::Known(gas_left))) => {
292300
if ext.selfdestruct_address.is_some() {
293301
let beneficiary: [u8; 20] = ext.selfdestruct_address.unwrap().into();
294302
ewasm_api::selfdestruct(&beneficiary)
295303
} else {
296304
ewasm_api::finish()
297305
}
298306
}
299-
Ok(GasLeft::NeedsReturn {
307+
Ok(Ok(GasLeft::NeedsReturn {
300308
gas_left,
301309
data,
302310
apply_state,
303-
}) => ewasm_api::finish_data(&data.deref()),
311+
})) => ewasm_api::finish_data(&data.deref()),
312+
// FIXME: not sure what this state means
313+
Ok(Err(err)) => ewasm_api::revert(),
304314
// FIXME: add support for pushing the error message as revert data
305315
Err(err) => ewasm_api::revert(),
306316
}

0 commit comments

Comments
 (0)