life
life copied to clipboard
How AddGas injected?
For Gas control flow life used AddGas instruction.
From source code it's not clear how it injected to Wasm instructions.
case opcodes.AddGas:
delta := LE.Uint64(frame.Code[frame.IP : frame.IP+8])
where delta are formed?
The root question from strange behavior:
#[no_mangle]
pub extern "C" fn sum(n: u64) -> u64 {
let mut res = 0;
for x in 0..n {
res += x;
}
return res;
}
#[no_mangle]
pub extern "C" fn app_main() -> u64 {
sum(1_000_000)
}
And after execution vm.Gas == 2. It's strange.
The add_gas instruction is inserted here https://github.com/perlin-network/life/blob/master/compiler/gas.go