life icon indicating copy to clipboard operation
life copied to clipboard

How AddGas injected?

Open mrLSD opened this issue 6 years ago • 1 comments

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.

mrLSD avatar Aug 07 '19 16:08 mrLSD

The add_gas instruction is inserted here https://github.com/perlin-network/life/blob/master/compiler/gas.go

roman-kashitsyn avatar Mar 14 '20 23:03 roman-kashitsyn