diff --git a/gas/Cargo.lock b/gas/Cargo.lock index 4353571..dc3dffb 100644 --- a/gas/Cargo.lock +++ b/gas/Cargo.lock @@ -2,7 +2,7 @@ name = "gas" version = "0.1.0" dependencies = [ - "parity-wasm 0.2.0 (git+https://github.com/nikvolf/parity-wasm)", + "parity-wasm 0.3.0 (git+https://github.com/nikvolf/parity-wasm)", ] [[package]] @@ -12,12 +12,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "parity-wasm" -version = "0.2.0" -source = "git+https://github.com/nikvolf/parity-wasm#4011af4f75e9334a2a018fdb2f464d9c7eb21617" +version = "0.3.0" +source = "git+https://github.com/nikvolf/parity-wasm#afb5b8d523227445d648deaee6ca6c9448d24a73" dependencies = [ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [metadata] "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" -"checksum parity-wasm 0.2.0 (git+https://github.com/nikvolf/parity-wasm)" = "" +"checksum parity-wasm 0.3.0 (git+https://github.com/nikvolf/parity-wasm)" = "" diff --git a/gas/src/main.rs b/gas/src/main.rs index e1f44ec..f188c48 100644 --- a/gas/src/main.rs +++ b/gas/src/main.rs @@ -7,7 +7,7 @@ pub fn update_call_index(opcodes: &mut elements::Opcodes, inserted_index: u32) { use parity_wasm::elements::Opcode::*; for opcode in opcodes.elements_mut().iter_mut() { match opcode { - &mut Block(_, ref mut block) | &mut If(_, ref mut block) => { + &mut Block(_, ref mut block) | &mut If(_, ref mut block) | &mut Loop(_, ref mut block) => { update_call_index(block, inserted_index) }, &mut Call(ref mut call_index) | &mut CallIndirect(ref mut call_index, _) => { @@ -22,7 +22,7 @@ pub fn inject_counter(opcodes: &mut elements::Opcodes, gas_func: u32) { use parity_wasm::elements::Opcode::*; for opcode in opcodes.elements_mut().iter_mut() { match opcode { - &mut Block(_, ref mut block) | &mut If(_, ref mut block) => { + &mut Block(_, ref mut block) | &mut If(_, ref mut block) | &mut Loop(_, ref mut block) => { inject_counter(block, gas_func) }, _ => { } @@ -30,7 +30,7 @@ pub fn inject_counter(opcodes: &mut elements::Opcodes, gas_func: u32) { } let ops = opcodes.elements_mut().len() as u32; - opcodes.elements_mut().insert(0, I32Const(ops)); + opcodes.elements_mut().insert(0, I32Const(ops as i32)); opcodes.elements_mut().insert(1, Call(gas_func)); } @@ -85,6 +85,16 @@ fn main() { inject_counter(func_body.code_mut(), gas_func); } }, + &mut elements::Section::Export(ref mut export_section) => { + for ref mut export in export_section.entries_mut() { + match export.internal_mut() { + &mut elements::Internal::Function(ref mut func_index) => { + if *func_index >= gas_func { *func_index += 1} + }, + _ => {} + } + } + } _ => { } } } diff --git a/runner/build.sh b/runner/build.sh index 532c533..f27428e 100755 --- a/runner/build.sh +++ b/runner/build.sh @@ -20,4 +20,5 @@ then echo "cargo build --release" else ./../gas/target/release/gas ./out/contract.wasm ./out/contract.wasm + # echo "Removed gasification" fi diff --git a/samples/contract3.rs b/samples/contract3.rs index a03d6c0..ec72451 100644 --- a/samples/contract3.rs +++ b/samples/contract3.rs @@ -4,13 +4,13 @@ use std::slice; -#[link_args = "-s WASM=1 -s NO_EXIT_RUNTIME=1 -s NO_FILESYSTEM=1"] +#[link_args = "-s WASM=1 -s NO_EXIT_RUNTIME=1 -s NO_FILESYSTEM=1 -s EXPORTED_FUNCTIONS=['_call']"] extern {} #[no_mangle] pub fn call(input: *mut u8) { - let mut slice = unsafe { slice::from_raw_parts_mut(input, 8192) }; // 8kb input data - for i in 0..slice.len() { + let slice = unsafe { slice::from_raw_parts_mut(input, 8192) }; // 8kb input data + for i in 0..8192 { slice[i] = slice[i] + 2; } } \ No newline at end of file