mirror of
https://github.com/pezkuwichain/wasm-instrument.git
synced 2026-05-30 04:11:06 +00:00
contract3, fixed issues with ser/de
This commit is contained in:
Generated
+4
-4
@@ -2,7 +2,7 @@
|
|||||||
name = "gas"
|
name = "gas"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
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]]
|
[[package]]
|
||||||
@@ -12,12 +12,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parity-wasm"
|
name = "parity-wasm"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
source = "git+https://github.com/nikvolf/parity-wasm#4011af4f75e9334a2a018fdb2f464d9c7eb21617"
|
source = "git+https://github.com/nikvolf/parity-wasm#afb5b8d523227445d648deaee6ca6c9448d24a73"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8"
|
"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)" = "<none>"
|
"checksum parity-wasm 0.3.0 (git+https://github.com/nikvolf/parity-wasm)" = "<none>"
|
||||||
|
|||||||
+13
-3
@@ -7,7 +7,7 @@ pub fn update_call_index(opcodes: &mut elements::Opcodes, inserted_index: u32) {
|
|||||||
use parity_wasm::elements::Opcode::*;
|
use parity_wasm::elements::Opcode::*;
|
||||||
for opcode in opcodes.elements_mut().iter_mut() {
|
for opcode in opcodes.elements_mut().iter_mut() {
|
||||||
match opcode {
|
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)
|
update_call_index(block, inserted_index)
|
||||||
},
|
},
|
||||||
&mut Call(ref mut call_index) | &mut CallIndirect(ref mut call_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::*;
|
use parity_wasm::elements::Opcode::*;
|
||||||
for opcode in opcodes.elements_mut().iter_mut() {
|
for opcode in opcodes.elements_mut().iter_mut() {
|
||||||
match opcode {
|
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)
|
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;
|
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));
|
opcodes.elements_mut().insert(1, Call(gas_func));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +85,16 @@ fn main() {
|
|||||||
inject_counter(func_body.code_mut(), gas_func);
|
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}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => { }
|
_ => { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,4 +20,5 @@ then
|
|||||||
echo "cargo build --release"
|
echo "cargo build --release"
|
||||||
else
|
else
|
||||||
./../gas/target/release/gas ./out/contract.wasm ./out/contract.wasm
|
./../gas/target/release/gas ./out/contract.wasm ./out/contract.wasm
|
||||||
|
# echo "Removed gasification"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
|
|
||||||
use std::slice;
|
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 {}
|
extern {}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn call(input: *mut u8) {
|
pub fn call(input: *mut u8) {
|
||||||
let mut slice = unsafe { slice::from_raw_parts_mut(input, 8192) }; // 8kb input data
|
let slice = unsafe { slice::from_raw_parts_mut(input, 8192) }; // 8kb input data
|
||||||
for i in 0..slice.len() {
|
for i in 0..8192 {
|
||||||
slice[i] = slice[i] + 2;
|
slice[i] = slice[i] + 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user