2020-05-12 19:01:39 +00:00
|
|
|
|
2020-11-04 18:20:49 +00:00
|
|
|
======= evm_to_wasm_break/input.yul (Ewasm) =======
|
2020-05-12 19:01:39 +00:00
|
|
|
|
|
|
|
Pretty printed source:
|
|
|
|
object "object" {
|
|
|
|
code {
|
|
|
|
{
|
|
|
|
let x := calldataload(0)
|
|
|
|
for { } lt(x, 10) { x := add(x, 1) }
|
|
|
|
{
|
|
|
|
if eq(x, 2) { break }
|
|
|
|
if eq(x, 4) { continue }
|
|
|
|
}
|
|
|
|
sstore(0, x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
==========================
|
|
|
|
|
|
|
|
Translated source:
|
|
|
|
object "object" {
|
|
|
|
code {
|
|
|
|
function main()
|
|
|
|
{
|
|
|
|
let _1 := 0
|
|
|
|
let x, x_1, x_2, x_3 := calldataload(_1, _1, _1, _1)
|
|
|
|
let x_4 := x
|
|
|
|
let x_5 := x_1
|
|
|
|
let x_6 := x_2
|
|
|
|
let x_7 := x_3
|
|
|
|
let _2 := 1
|
2020-07-14 10:04:55 +00:00
|
|
|
let _3:i32 := i32.eqz(i32.eqz(i64.eqz(i64.or(i64.or(_1, _1), i64.or(_1, _2)))))
|
2020-05-12 19:01:39 +00:00
|
|
|
for { }
|
2020-07-14 10:04:55 +00:00
|
|
|
i32.eqz(_3)
|
2020-05-12 19:01:39 +00:00
|
|
|
{
|
|
|
|
let x_8, x_9, x_10, x_11 := add(x_4, x_5, x_6, x_7, _1, _1, _1, _2)
|
|
|
|
x_4 := x_8
|
|
|
|
x_5 := x_9
|
|
|
|
x_6 := x_10
|
|
|
|
x_7 := x_11
|
|
|
|
}
|
|
|
|
{
|
2021-01-25 15:57:25 +00:00
|
|
|
let _4, _5, _6, _7 := iszero_887(_1, _1, _1, lt(x_4, x_5, x_6, x_7, _1, _1, _1, 10))
|
2020-07-14 10:04:55 +00:00
|
|
|
if i32.eqz(i64.eqz(i64.or(i64.or(_4, _5), i64.or(_6, _7)))) { break }
|
2021-01-25 15:57:25 +00:00
|
|
|
let _8, _9, _10, _11 := eq_888(x_4, x_5, x_6, x_7, _1, _1, _1, 2)
|
2020-07-14 10:04:55 +00:00
|
|
|
if i32.eqz(i64.eqz(i64.or(i64.or(_8, _9), i64.or(_10, _11)))) { break }
|
2021-01-25 15:57:25 +00:00
|
|
|
let _12, _13, _14, _15 := eq_888(x_4, x_5, x_6, x_7, _1, _1, _1, 4)
|
2020-07-14 10:04:55 +00:00
|
|
|
if i32.eqz(i64.eqz(i64.or(i64.or(_12, _13), i64.or(_14, _15)))) { continue }
|
2020-05-12 19:01:39 +00:00
|
|
|
}
|
|
|
|
sstore(_1, _1, _1, _1, x_4, x_5, x_6, x_7)
|
|
|
|
}
|
|
|
|
function add_carry(x, y, c) -> r, r_c
|
|
|
|
{
|
|
|
|
let t := i64.add(x, y)
|
|
|
|
r := i64.add(t, c)
|
|
|
|
r_c := i64.extend_i32_u(i32.or(i64.lt_u(t, x), i64.lt_u(r, t)))
|
|
|
|
}
|
|
|
|
function add(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4
|
|
|
|
{
|
|
|
|
let t := i64.add(x4, y4)
|
|
|
|
r4 := i64.add(t, 0)
|
|
|
|
let r3_1, carry := add_carry(x3, y3, i64.extend_i32_u(i32.or(i64.lt_u(t, x4), i64.lt_u(r4, t))))
|
|
|
|
r3 := r3_1
|
|
|
|
let r2_1, carry_1 := add_carry(x2, y2, carry)
|
|
|
|
r2 := r2_1
|
|
|
|
let r1_1, carry_2 := add_carry(x1, y1, carry_1)
|
|
|
|
r1 := r1_1
|
|
|
|
}
|
2021-01-25 15:57:25 +00:00
|
|
|
function iszero_887(x1, x2, x3, x4) -> r1, r2, r3, r4
|
2020-05-12 19:01:39 +00:00
|
|
|
{
|
|
|
|
r4 := i64.extend_i32_u(i64.eqz(i64.or(i64.or(x1, x2), i64.or(x3, x4))))
|
|
|
|
}
|
2021-01-25 15:57:25 +00:00
|
|
|
function eq_888(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4
|
2020-05-12 19:01:39 +00:00
|
|
|
{
|
2020-07-14 10:04:55 +00:00
|
|
|
r4 := i64.extend_i32_u(i32.and(i64.eq(x1, y1), i32.and(i64.eq(x2, y2), i32.and(i64.eq(x3, y3), i64.eq(x4, y4)))))
|
2020-05-12 19:01:39 +00:00
|
|
|
}
|
2021-01-25 15:57:25 +00:00
|
|
|
function lt(x1, x2, x3, x4, y1, y2, y3, y4) -> z4
|
2020-05-12 19:01:39 +00:00
|
|
|
{
|
|
|
|
let z:i32 := false
|
2020-11-27 22:26:51 +00:00
|
|
|
let _1:i32 := 0xffffffff:i32
|
|
|
|
switch i32.select(_1, i64.ne(x1, y1), i64.lt_u(x1, y1))
|
2020-05-12 19:01:39 +00:00
|
|
|
case 0:i32 {
|
2020-11-27 22:26:51 +00:00
|
|
|
switch i32.select(_1, i64.ne(x2, y2), i64.lt_u(x2, y2))
|
2020-05-12 19:01:39 +00:00
|
|
|
case 0:i32 {
|
2020-11-27 22:26:51 +00:00
|
|
|
switch i32.select(_1, i64.ne(x3, y3), i64.lt_u(x3, y3))
|
2020-05-12 19:01:39 +00:00
|
|
|
case 0:i32 { z := i64.lt_u(x4, y4) }
|
|
|
|
case 1:i32 { z := 0:i32 }
|
|
|
|
default { z := 1:i32 }
|
|
|
|
}
|
|
|
|
case 1:i32 { z := 0:i32 }
|
|
|
|
default { z := 1:i32 }
|
|
|
|
}
|
|
|
|
case 1:i32 { z := 0:i32 }
|
|
|
|
default { z := 1:i32 }
|
|
|
|
z4 := i64.extend_i32_u(z)
|
|
|
|
}
|
2020-11-18 02:45:49 +00:00
|
|
|
function u256_to_i32(x1, x2, x3, x4) -> v:i32
|
|
|
|
{
|
|
|
|
if i64.ne(0, i64.or(i64.or(x1, x2), x3)) { unreachable() }
|
|
|
|
if i64.ne(0, i64.shr_u(x4, 32)) { unreachable() }
|
|
|
|
v := i32.wrap_i64(x4)
|
|
|
|
}
|
2020-11-21 20:05:39 +00:00
|
|
|
function bswap16(x:i32) -> y:i32
|
2020-05-12 19:01:39 +00:00
|
|
|
{
|
2020-11-21 20:05:39 +00:00
|
|
|
y := i32.or(i32.and(i32.shl(x, 8:i32), 0xff00:i32), i32.and(i32.shr_u(x, 8:i32), 0xff:i32))
|
2020-05-12 19:01:39 +00:00
|
|
|
}
|
2020-11-21 20:05:39 +00:00
|
|
|
function bswap32(x:i32) -> y:i32
|
2020-05-12 19:01:39 +00:00
|
|
|
{
|
2020-11-21 20:05:39 +00:00
|
|
|
let hi:i32 := i32.shl(bswap16(x), 16:i32)
|
|
|
|
y := i32.or(hi, bswap16(i32.shr_u(x, 16:i32)))
|
2020-05-12 19:01:39 +00:00
|
|
|
}
|
2020-11-18 02:30:06 +00:00
|
|
|
function bswap64(x) -> y
|
2020-05-12 19:01:39 +00:00
|
|
|
{
|
2020-11-21 20:05:39 +00:00
|
|
|
let hi := i64.shl(i64.extend_i32_u(bswap32(i32.wrap_i64(x))), 32)
|
|
|
|
y := i64.or(hi, i64.extend_i32_u(bswap32(i32.wrap_i64(i64.shr_u(x, 32)))))
|
2020-05-12 19:01:39 +00:00
|
|
|
}
|
2020-11-17 17:56:07 +00:00
|
|
|
function calldataload(x1, x2, x3, x4) -> z1, z2, z3, z4
|
|
|
|
{
|
2020-11-18 02:45:49 +00:00
|
|
|
let cds:i32 := eth.getCallDataSize()
|
|
|
|
let _1 := 0
|
|
|
|
let destination:i32 := u256_to_i32(_1, _1, _1, _1)
|
|
|
|
let offset:i32 := u256_to_i32(x1, x2, x3, x4)
|
|
|
|
let requested_size:i32 := u256_to_i32(_1, _1, _1, 32)
|
|
|
|
if i32.gt_u(offset, i32.sub(0xffffffff:i32, requested_size)) { eth.revert(0:i32, 0:i32) }
|
|
|
|
let available_size:i32 := i32.sub(cds, offset)
|
|
|
|
if i32.gt_u(offset, cds) { available_size := 0:i32 }
|
|
|
|
let _2:i32 := 0:i32
|
|
|
|
if i32.gt_u(available_size, _2)
|
|
|
|
{
|
|
|
|
eth.callDataCopy(destination, offset, available_size)
|
|
|
|
}
|
|
|
|
if i32.gt_u(requested_size, available_size)
|
|
|
|
{
|
|
|
|
let _3:i32 := i32.sub(requested_size, available_size)
|
|
|
|
let _4:i32 := i32.add(destination, available_size)
|
|
|
|
let i:i32 := _2
|
|
|
|
for { } i32.lt_u(i, _3) { i := i32.add(i, 1:i32) }
|
|
|
|
{
|
|
|
|
i32.store8(i32.add(_4, i), _2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let z1_1 := bswap64(i64.load(_2))
|
|
|
|
let z2_1 := bswap64(i64.load(i32.add(_2, 8:i32)))
|
|
|
|
let z3_1 := bswap64(i64.load(i32.add(_2, 16:i32)))
|
|
|
|
let z4_1 := bswap64(i64.load(i32.add(_2, 24:i32)))
|
2020-11-17 17:56:07 +00:00
|
|
|
z1 := z1_1
|
|
|
|
z2 := z2_1
|
|
|
|
z3 := z3_1
|
|
|
|
z4 := z4_1
|
|
|
|
}
|
2020-11-21 20:05:39 +00:00
|
|
|
function sstore(x1, x2, x3, x4, y1, y2, y3, y4)
|
|
|
|
{
|
|
|
|
mstore_internal(0:i32, x1, x2, x3, x4)
|
|
|
|
mstore_internal(32:i32, y1, y2, y3, y4)
|
|
|
|
eth.storageStore(0:i32, 32:i32)
|
|
|
|
}
|
2020-05-12 19:01:39 +00:00
|
|
|
function mstore_internal(pos:i32, y1, y2, y3, y4)
|
|
|
|
{
|
2020-11-18 02:30:06 +00:00
|
|
|
i64.store(pos, bswap64(y1))
|
|
|
|
i64.store(i32.add(pos, 8:i32), bswap64(y2))
|
|
|
|
i64.store(i32.add(pos, 16:i32), bswap64(y3))
|
|
|
|
i64.store(i32.add(pos, 24:i32), bswap64(y4))
|
2020-05-12 19:01:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Binary representation:
|
2020-11-21 20:05:39 +00:00
|
|
|
0061736d0100000001530c6000006000017f60017e017e60037e7e7e017e60047e7e7e7e017e60047e7e7e7e017f60087e7e7e7e7e7e7e7e0060087e7e7e7e7e7e7e7e017e60017f017f60057f7e7e7e7e0060027f7f0060037f7f7f00025e0408657468657265756d0c73746f7261676553746f7265000a08657468657265756d06726576657274000a08657468657265756d0f67657443616c6c4461746153697a65000108657468657265756d0c63616c6c44617461436f7079000b030e0d0003070407070508080204060905030100010610037e0142000b7e0142000b7e0142000b071102066d656d6f72790200046d61696e00040ac0090dcb02030a7e017f107e02404200210002402000200020002000100e21012300210223012103230221040b20012105200221062003210720042108420121092000200084200020098484504545210a02400340200a45450d01024002402000200020002005200620072008200020002000420a10091007210b2300210c2301210d2302210e0b200b200c84200d200e8484504504400c030b0240200520062007200820002000200042021008210f2300211023012111230221120b200f201084201120128484504504400c030b024020052006200720082000200020004204100821132300211423012115230221160b2013201484201520168484504504400c010b0b0240200520062007200820002000200020091006211723002118230121192302211a0b201721052018210620192107201a21080c000b0b20002000200020002005200620072008100f0b0b2901037e0240200020017c2105200520027c21032005200054200320055472ad21040b2004240020030b6c010b7e0240200320077c210c200c42007c210b024020022006200c200354200b200c5472ad1005210d2300210e0b200d210a024020012005200e1005210f230021100b200f2109024020002004201010052111230021120b201121080b20092400200a2401200b240220080b2401047e0240200020018420022003848450ad21070b20052400200624012007240220040b2f01047e02402000200451200120055120022006512003200751717171ad210b0b20092400200a2401200b240220080ba30102017e057f024041002109417f210a0240200a200020045220002004541b210b200b41004604400240200a200120055220012005541b210c200c41004604400240200a200220065220022006541b210d200d41004604402003200754210905200d41014604404100210905410121090b0b0b05200c41014604404100210905410121090b0b0b05200b41014604404100210905410121090b0b0b2009ad21080b20080b2901017f024042002000200184200284520440000b42002003422088520440000b2003a721040b20040b1f01017f024020004108744180fe0371200041087641ff01717221010b20010b1e01027f02402000100b411074210220022000411076100b7221010b20010b2201027e02402000a7100cad422086210220022000422088a7100cad8421010b20010bfc0105047e017f017e087f047e024010022108420021092009200920092009100a210a2000200120022003100a210b2009200920094220100a210c200b417f200c6b4b04404100410010010b2008200b6b210d200b20084b04404100210d0b4100210e200d200e4b0440200a200b200d10030b200c200d4b0440200c200d6b210f200a200d6a2110200e2111024003402011200f49450d010240201020116a200e3a00000b201141016a21110c000b0b0b200e290000100d2112200e41086a290000100d2113200e41106a290000100d2114200e41186a290000100d2115201221042013210520142106201521070b20052400200624012007240220040b230002404100200020012002200310104120200420052006200710104100412010000b0b3200024020002001100d370000200041086a2002100d370000200041106a2003100d370000200041186a2004100d3700000b0b
|
2020-05-12 19:01:39 +00:00
|
|
|
|
|
|
|
Text representation:
|
|
|
|
(module
|
|
|
|
(import "ethereum" "storageStore" (func $eth.storageStore (param i32 i32)))
|
2020-11-18 02:45:49 +00:00
|
|
|
(import "ethereum" "revert" (func $eth.revert (param i32 i32)))
|
|
|
|
(import "ethereum" "getCallDataSize" (func $eth.getCallDataSize (result i32)))
|
2020-05-12 19:01:39 +00:00
|
|
|
(import "ethereum" "callDataCopy" (func $eth.callDataCopy (param i32 i32 i32)))
|
|
|
|
(memory $memory (export "memory") 1)
|
|
|
|
(export "main" (func $main))
|
|
|
|
(global $global_ (mut i64) (i64.const 0))
|
|
|
|
(global $global__1 (mut i64) (i64.const 0))
|
|
|
|
(global $global__2 (mut i64) (i64.const 0))
|
|
|
|
|
|
|
|
(func $main
|
|
|
|
(local $_1 i64)
|
|
|
|
(local $x i64)
|
|
|
|
(local $x_1 i64)
|
|
|
|
(local $x_2 i64)
|
|
|
|
(local $x_3 i64)
|
|
|
|
(local $x_4 i64)
|
|
|
|
(local $x_5 i64)
|
|
|
|
(local $x_6 i64)
|
|
|
|
(local $x_7 i64)
|
|
|
|
(local $_2 i64)
|
2020-07-14 10:04:55 +00:00
|
|
|
(local $_3 i32)
|
|
|
|
(local $_4 i64)
|
2020-05-12 19:01:39 +00:00
|
|
|
(local $_5 i64)
|
|
|
|
(local $_6 i64)
|
|
|
|
(local $_7 i64)
|
|
|
|
(local $_8 i64)
|
2020-07-14 10:04:55 +00:00
|
|
|
(local $_9 i64)
|
|
|
|
(local $_10 i64)
|
|
|
|
(local $_11 i64)
|
|
|
|
(local $_12 i64)
|
|
|
|
(local $_13 i64)
|
|
|
|
(local $_14 i64)
|
|
|
|
(local $_15 i64)
|
2020-05-12 19:01:39 +00:00
|
|
|
(local $x_8 i64)
|
|
|
|
(local $x_9 i64)
|
|
|
|
(local $x_10 i64)
|
|
|
|
(local $x_11 i64)
|
|
|
|
(block $label_
|
2020-05-25 21:33:59 +00:00
|
|
|
(local.set $_1 (i64.const 0))
|
|
|
|
(block
|
|
|
|
(local.set $x (call $calldataload (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1)))
|
|
|
|
(local.set $x_1 (global.get $global_))
|
|
|
|
(local.set $x_2 (global.get $global__1))
|
|
|
|
(local.set $x_3 (global.get $global__2))
|
2020-05-12 19:01:39 +00:00
|
|
|
|
2020-05-25 21:33:59 +00:00
|
|
|
)
|
|
|
|
(local.set $x_4 (local.get $x))
|
|
|
|
(local.set $x_5 (local.get $x_1))
|
|
|
|
(local.set $x_6 (local.get $x_2))
|
|
|
|
(local.set $x_7 (local.get $x_3))
|
|
|
|
(local.set $_2 (i64.const 1))
|
2020-07-14 10:04:55 +00:00
|
|
|
(local.set $_3 (i32.eqz (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_1) (local.get $_1)) (i64.or (local.get $_1) (local.get $_2)))))))
|
2020-05-25 21:33:59 +00:00
|
|
|
(block $label__3
|
|
|
|
(loop $label__5
|
2020-07-14 10:04:55 +00:00
|
|
|
(br_if $label__3 (i32.eqz (i32.eqz (local.get $_3))))
|
2020-05-25 21:33:59 +00:00
|
|
|
(block $label__4
|
|
|
|
(block
|
2021-01-25 15:57:25 +00:00
|
|
|
(local.set $_4 (call $iszero_887 (local.get $_1) (local.get $_1) (local.get $_1) (call $lt (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 10))))
|
2020-07-14 10:04:55 +00:00
|
|
|
(local.set $_5 (global.get $global_))
|
|
|
|
(local.set $_6 (global.get $global__1))
|
|
|
|
(local.set $_7 (global.get $global__2))
|
2020-05-12 19:01:39 +00:00
|
|
|
|
2020-05-25 21:33:59 +00:00
|
|
|
)
|
2020-07-14 10:04:55 +00:00
|
|
|
(if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_4) (local.get $_5)) (i64.or (local.get $_6) (local.get $_7))))) (then
|
2020-05-25 21:33:59 +00:00
|
|
|
(br $label__3)
|
|
|
|
))
|
2020-07-14 10:04:55 +00:00
|
|
|
(block
|
2021-01-25 15:57:25 +00:00
|
|
|
(local.set $_8 (call $eq_888 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 2)))
|
2020-07-14 10:04:55 +00:00
|
|
|
(local.set $_9 (global.get $global_))
|
|
|
|
(local.set $_10 (global.get $global__1))
|
|
|
|
(local.set $_11 (global.get $global__2))
|
|
|
|
|
|
|
|
)
|
|
|
|
(if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_8) (local.get $_9)) (i64.or (local.get $_10) (local.get $_11))))) (then
|
2020-05-25 21:33:59 +00:00
|
|
|
(br $label__3)
|
|
|
|
))
|
2020-07-14 10:04:55 +00:00
|
|
|
(block
|
2021-01-25 15:57:25 +00:00
|
|
|
(local.set $_12 (call $eq_888 (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 4)))
|
2020-07-14 10:04:55 +00:00
|
|
|
(local.set $_13 (global.get $global_))
|
|
|
|
(local.set $_14 (global.get $global__1))
|
|
|
|
(local.set $_15 (global.get $global__2))
|
|
|
|
|
|
|
|
)
|
|
|
|
(if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $_12) (local.get $_13)) (i64.or (local.get $_14) (local.get $_15))))) (then
|
2020-05-25 21:33:59 +00:00
|
|
|
(br $label__4)
|
|
|
|
))
|
2020-05-12 19:01:39 +00:00
|
|
|
|
|
|
|
)
|
|
|
|
(block
|
2020-05-25 21:33:59 +00:00
|
|
|
(local.set $x_8 (call $add (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_2)))
|
|
|
|
(local.set $x_9 (global.get $global_))
|
|
|
|
(local.set $x_10 (global.get $global__1))
|
|
|
|
(local.set $x_11 (global.get $global__2))
|
2020-05-12 19:01:39 +00:00
|
|
|
|
|
|
|
)
|
2020-05-25 21:33:59 +00:00
|
|
|
(local.set $x_4 (local.get $x_8))
|
|
|
|
(local.set $x_5 (local.get $x_9))
|
|
|
|
(local.set $x_6 (local.get $x_10))
|
|
|
|
(local.set $x_7 (local.get $x_11))
|
|
|
|
(br $label__5)
|
2020-05-12 19:01:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
)
|
2020-05-25 21:33:59 +00:00
|
|
|
(call $sstore (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $x_4) (local.get $x_5) (local.get $x_6) (local.get $x_7))
|
2020-05-12 19:01:39 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
(func $add_carry
|
|
|
|
(param $x i64)
|
|
|
|
(param $y i64)
|
|
|
|
(param $c i64)
|
|
|
|
(result i64)
|
|
|
|
(local $r i64)
|
|
|
|
(local $r_c i64)
|
|
|
|
(local $t i64)
|
2020-05-25 21:33:59 +00:00
|
|
|
(block $label__6
|
|
|
|
(local.set $t (i64.add (local.get $x) (local.get $y)))
|
|
|
|
(local.set $r (i64.add (local.get $t) (local.get $c)))
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $r_c (i64.extend_i32_u (i32.or (i64.lt_u (local.get $t) (local.get $x)) (i64.lt_u (local.get $r) (local.get $t)))))
|
2020-05-25 21:33:59 +00:00
|
|
|
|
|
|
|
)
|
2020-05-12 19:01:39 +00:00
|
|
|
(global.set $global_ (local.get $r_c))
|
|
|
|
(local.get $r)
|
|
|
|
)
|
|
|
|
|
|
|
|
(func $add
|
|
|
|
(param $x1 i64)
|
|
|
|
(param $x2 i64)
|
|
|
|
(param $x3 i64)
|
|
|
|
(param $x4 i64)
|
|
|
|
(param $y1 i64)
|
|
|
|
(param $y2 i64)
|
|
|
|
(param $y3 i64)
|
|
|
|
(param $y4 i64)
|
|
|
|
(result i64)
|
|
|
|
(local $r1 i64)
|
|
|
|
(local $r2 i64)
|
|
|
|
(local $r3 i64)
|
|
|
|
(local $r4 i64)
|
|
|
|
(local $t i64)
|
|
|
|
(local $r3_1 i64)
|
|
|
|
(local $carry i64)
|
|
|
|
(local $r2_1 i64)
|
|
|
|
(local $carry_1 i64)
|
|
|
|
(local $r1_1 i64)
|
|
|
|
(local $carry_2 i64)
|
2020-05-25 21:33:59 +00:00
|
|
|
(block $label__7
|
|
|
|
(local.set $t (i64.add (local.get $x4) (local.get $y4)))
|
|
|
|
(local.set $r4 (i64.add (local.get $t) (i64.const 0)))
|
|
|
|
(block
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $r3_1 (call $add_carry (local.get $x3) (local.get $y3) (i64.extend_i32_u (i32.or (i64.lt_u (local.get $t) (local.get $x4)) (i64.lt_u (local.get $r4) (local.get $t))))))
|
2020-05-25 21:33:59 +00:00
|
|
|
(local.set $carry (global.get $global_))
|
2020-05-12 19:01:39 +00:00
|
|
|
|
2020-05-25 21:33:59 +00:00
|
|
|
)
|
|
|
|
(local.set $r3 (local.get $r3_1))
|
|
|
|
(block
|
|
|
|
(local.set $r2_1 (call $add_carry (local.get $x2) (local.get $y2) (local.get $carry)))
|
|
|
|
(local.set $carry_1 (global.get $global_))
|
2020-05-12 19:01:39 +00:00
|
|
|
|
2020-05-25 21:33:59 +00:00
|
|
|
)
|
|
|
|
(local.set $r2 (local.get $r2_1))
|
|
|
|
(block
|
|
|
|
(local.set $r1_1 (call $add_carry (local.get $x1) (local.get $y1) (local.get $carry_1)))
|
|
|
|
(local.set $carry_2 (global.get $global_))
|
|
|
|
|
|
|
|
)
|
|
|
|
(local.set $r1 (local.get $r1_1))
|
2020-05-12 19:01:39 +00:00
|
|
|
|
|
|
|
)
|
|
|
|
(global.set $global_ (local.get $r2))
|
|
|
|
(global.set $global__1 (local.get $r3))
|
|
|
|
(global.set $global__2 (local.get $r4))
|
|
|
|
(local.get $r1)
|
|
|
|
)
|
|
|
|
|
2021-01-25 15:57:25 +00:00
|
|
|
(func $iszero_887
|
2020-05-12 19:01:39 +00:00
|
|
|
(param $x1 i64)
|
|
|
|
(param $x2 i64)
|
|
|
|
(param $x3 i64)
|
|
|
|
(param $x4 i64)
|
|
|
|
(result i64)
|
|
|
|
(local $r1 i64)
|
|
|
|
(local $r2 i64)
|
|
|
|
(local $r3 i64)
|
|
|
|
(local $r4 i64)
|
2020-05-25 21:33:59 +00:00
|
|
|
(block $label__8
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $r4 (i64.extend_i32_u (i64.eqz (i64.or (i64.or (local.get $x1) (local.get $x2)) (i64.or (local.get $x3) (local.get $x4))))))
|
2020-05-25 21:33:59 +00:00
|
|
|
|
|
|
|
)
|
2020-05-12 19:01:39 +00:00
|
|
|
(global.set $global_ (local.get $r2))
|
|
|
|
(global.set $global__1 (local.get $r3))
|
|
|
|
(global.set $global__2 (local.get $r4))
|
|
|
|
(local.get $r1)
|
|
|
|
)
|
|
|
|
|
2021-01-25 15:57:25 +00:00
|
|
|
(func $eq_888
|
2020-05-12 19:01:39 +00:00
|
|
|
(param $x1 i64)
|
|
|
|
(param $x2 i64)
|
|
|
|
(param $x3 i64)
|
|
|
|
(param $x4 i64)
|
|
|
|
(param $y1 i64)
|
|
|
|
(param $y2 i64)
|
|
|
|
(param $y3 i64)
|
|
|
|
(param $y4 i64)
|
|
|
|
(result i64)
|
2020-07-14 10:04:55 +00:00
|
|
|
(local $r1 i64)
|
|
|
|
(local $r2 i64)
|
|
|
|
(local $r3 i64)
|
2020-05-12 19:01:39 +00:00
|
|
|
(local $r4 i64)
|
2020-05-25 21:33:59 +00:00
|
|
|
(block $label__9
|
2020-07-14 10:04:55 +00:00
|
|
|
(local.set $r4 (i64.extend_i32_u (i32.and (i64.eq (local.get $x1) (local.get $y1)) (i32.and (i64.eq (local.get $x2) (local.get $y2)) (i32.and (i64.eq (local.get $x3) (local.get $y3)) (i64.eq (local.get $x4) (local.get $y4)))))))
|
2020-05-25 21:33:59 +00:00
|
|
|
|
|
|
|
)
|
2020-07-14 10:04:55 +00:00
|
|
|
(global.set $global_ (local.get $r2))
|
|
|
|
(global.set $global__1 (local.get $r3))
|
|
|
|
(global.set $global__2 (local.get $r4))
|
|
|
|
(local.get $r1)
|
2020-05-12 19:01:39 +00:00
|
|
|
)
|
|
|
|
|
2021-01-25 15:57:25 +00:00
|
|
|
(func $lt
|
2020-05-12 19:01:39 +00:00
|
|
|
(param $x1 i64)
|
|
|
|
(param $x2 i64)
|
|
|
|
(param $x3 i64)
|
|
|
|
(param $x4 i64)
|
|
|
|
(param $y1 i64)
|
|
|
|
(param $y2 i64)
|
|
|
|
(param $y3 i64)
|
|
|
|
(param $y4 i64)
|
|
|
|
(result i64)
|
|
|
|
(local $z4 i64)
|
2020-06-05 19:36:44 +00:00
|
|
|
(local $z i32)
|
2020-11-27 22:26:51 +00:00
|
|
|
(local $_1 i32)
|
|
|
|
(local $condition i32)
|
|
|
|
(local $condition_11 i32)
|
2020-06-05 19:36:44 +00:00
|
|
|
(local $condition_12 i32)
|
2020-11-27 22:26:51 +00:00
|
|
|
(block $label__10
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $z (i32.const 0))
|
2020-11-27 22:26:51 +00:00
|
|
|
(local.set $_1 (i32.const 4294967295))
|
2020-05-25 21:33:59 +00:00
|
|
|
(block
|
2020-12-01 02:00:45 +00:00
|
|
|
(local.set $condition (select (local.get $_1) (i64.ne (local.get $x1) (local.get $y1)) (i64.lt_u (local.get $x1) (local.get $y1))))
|
2020-11-27 22:26:51 +00:00
|
|
|
(if (i32.eq (local.get $condition) (i32.const 0)) (then
|
2020-05-25 21:33:59 +00:00
|
|
|
(block
|
2020-12-01 02:00:45 +00:00
|
|
|
(local.set $condition_11 (select (local.get $_1) (i64.ne (local.get $x2) (local.get $y2)) (i64.lt_u (local.get $x2) (local.get $y2))))
|
2020-11-27 22:26:51 +00:00
|
|
|
(if (i32.eq (local.get $condition_11) (i32.const 0)) (then
|
2020-05-25 21:33:59 +00:00
|
|
|
(block
|
2020-12-01 02:00:45 +00:00
|
|
|
(local.set $condition_12 (select (local.get $_1) (i64.ne (local.get $x3) (local.get $y3)) (i64.lt_u (local.get $x3) (local.get $y3))))
|
2020-11-27 22:26:51 +00:00
|
|
|
(if (i32.eq (local.get $condition_12) (i32.const 0)) (then
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $z (i64.lt_u (local.get $x4) (local.get $y4)))
|
2020-05-12 19:01:39 +00:00
|
|
|
)(else
|
2020-11-27 22:26:51 +00:00
|
|
|
(if (i32.eq (local.get $condition_12) (i32.const 1)) (then
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $z (i32.const 0))
|
2020-05-25 21:33:59 +00:00
|
|
|
)(else
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $z (i32.const 1))
|
2020-05-25 21:33:59 +00:00
|
|
|
))
|
2020-05-12 19:01:39 +00:00
|
|
|
))
|
|
|
|
|
2020-05-25 21:33:59 +00:00
|
|
|
)
|
2020-05-12 19:01:39 +00:00
|
|
|
)(else
|
2020-11-27 22:26:51 +00:00
|
|
|
(if (i32.eq (local.get $condition_11) (i32.const 1)) (then
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $z (i32.const 0))
|
2020-05-25 21:33:59 +00:00
|
|
|
)(else
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $z (i32.const 1))
|
2020-05-25 21:33:59 +00:00
|
|
|
))
|
2020-05-12 19:01:39 +00:00
|
|
|
))
|
|
|
|
|
2020-05-25 21:33:59 +00:00
|
|
|
)
|
2020-05-12 19:01:39 +00:00
|
|
|
)(else
|
2020-11-27 22:26:51 +00:00
|
|
|
(if (i32.eq (local.get $condition) (i32.const 1)) (then
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $z (i32.const 0))
|
2020-05-25 21:33:59 +00:00
|
|
|
)(else
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $z (i32.const 1))
|
2020-05-25 21:33:59 +00:00
|
|
|
))
|
2020-05-12 19:01:39 +00:00
|
|
|
))
|
2020-05-25 21:33:59 +00:00
|
|
|
|
|
|
|
)
|
2020-06-05 19:36:44 +00:00
|
|
|
(local.set $z4 (i64.extend_i32_u (local.get $z)))
|
2020-05-12 19:01:39 +00:00
|
|
|
|
|
|
|
)
|
2020-08-20 14:56:25 +00:00
|
|
|
(local.get $z4)
|
2020-05-12 19:01:39 +00:00
|
|
|
)
|
|
|
|
|
2020-11-18 02:45:49 +00:00
|
|
|
(func $u256_to_i32
|
|
|
|
(param $x1 i64)
|
|
|
|
(param $x2 i64)
|
|
|
|
(param $x3 i64)
|
|
|
|
(param $x4 i64)
|
|
|
|
(result i32)
|
|
|
|
(local $v i32)
|
2020-11-27 22:26:51 +00:00
|
|
|
(block $label__13
|
2020-11-18 02:45:49 +00:00
|
|
|
(if (i64.ne (i64.const 0) (i64.or (i64.or (local.get $x1) (local.get $x2)) (local.get $x3))) (then
|
|
|
|
(unreachable)))
|
|
|
|
(if (i64.ne (i64.const 0) (i64.shr_u (local.get $x4) (i64.const 32))) (then
|
|
|
|
(unreachable)))
|
|
|
|
(local.set $v (i32.wrap_i64 (local.get $x4)))
|
|
|
|
|
|
|
|
)
|
|
|
|
(local.get $v)
|
|
|
|
)
|
|
|
|
|
2020-11-18 02:30:06 +00:00
|
|
|
(func $bswap16
|
2020-11-21 20:05:39 +00:00
|
|
|
(param $x i32)
|
|
|
|
(result i32)
|
|
|
|
(local $y i32)
|
2020-11-27 22:26:51 +00:00
|
|
|
(block $label__14
|
2020-11-21 20:05:39 +00:00
|
|
|
(local.set $y (i32.or (i32.and (i32.shl (local.get $x) (i32.const 8)) (i32.const 65280)) (i32.and (i32.shr_u (local.get $x) (i32.const 8)) (i32.const 255))))
|
2020-11-17 17:56:07 +00:00
|
|
|
|
|
|
|
)
|
|
|
|
(local.get $y)
|
|
|
|
)
|
|
|
|
|
2020-11-18 02:30:06 +00:00
|
|
|
(func $bswap32
|
2020-11-21 20:05:39 +00:00
|
|
|
(param $x i32)
|
|
|
|
(result i32)
|
|
|
|
(local $y i32)
|
|
|
|
(local $hi i32)
|
2020-11-27 22:26:51 +00:00
|
|
|
(block $label__15
|
2020-11-21 20:05:39 +00:00
|
|
|
(local.set $hi (i32.shl (call $bswap16 (local.get $x)) (i32.const 16)))
|
|
|
|
(local.set $y (i32.or (local.get $hi) (call $bswap16 (i32.shr_u (local.get $x) (i32.const 16)))))
|
2020-11-17 17:56:07 +00:00
|
|
|
|
|
|
|
)
|
|
|
|
(local.get $y)
|
|
|
|
)
|
|
|
|
|
2020-11-18 02:30:06 +00:00
|
|
|
(func $bswap64
|
2020-11-17 17:56:07 +00:00
|
|
|
(param $x i64)
|
|
|
|
(result i64)
|
|
|
|
(local $y i64)
|
|
|
|
(local $hi i64)
|
2020-11-27 22:26:51 +00:00
|
|
|
(block $label__16
|
2020-11-21 20:05:39 +00:00
|
|
|
(local.set $hi (i64.shl (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (local.get $x)))) (i64.const 32)))
|
|
|
|
(local.set $y (i64.or (local.get $hi) (i64.extend_i32_u (call $bswap32 (i32.wrap_i64 (i64.shr_u (local.get $x) (i64.const 32)))))))
|
2020-11-17 17:56:07 +00:00
|
|
|
|
|
|
|
)
|
|
|
|
(local.get $y)
|
|
|
|
)
|
|
|
|
|
2020-05-12 19:01:39 +00:00
|
|
|
(func $calldataload
|
|
|
|
(param $x1 i64)
|
|
|
|
(param $x2 i64)
|
|
|
|
(param $x3 i64)
|
|
|
|
(param $x4 i64)
|
|
|
|
(result i64)
|
|
|
|
(local $z1 i64)
|
|
|
|
(local $z2 i64)
|
|
|
|
(local $z3 i64)
|
|
|
|
(local $z4 i64)
|
2020-11-18 02:45:49 +00:00
|
|
|
(local $cds i32)
|
|
|
|
(local $_1 i64)
|
|
|
|
(local $destination i32)
|
|
|
|
(local $offset i32)
|
|
|
|
(local $requested_size i32)
|
|
|
|
(local $available_size i32)
|
|
|
|
(local $_2 i32)
|
|
|
|
(local $_3 i32)
|
|
|
|
(local $_4 i32)
|
|
|
|
(local $i i32)
|
2020-05-12 19:01:39 +00:00
|
|
|
(local $z1_1 i64)
|
|
|
|
(local $z2_1 i64)
|
|
|
|
(local $z3_1 i64)
|
|
|
|
(local $z4_1 i64)
|
2020-11-27 22:26:51 +00:00
|
|
|
(block $label__17
|
2020-11-18 02:45:49 +00:00
|
|
|
(local.set $cds (call $eth.getCallDataSize))
|
|
|
|
(local.set $_1 (i64.const 0))
|
|
|
|
(local.set $destination (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1)))
|
|
|
|
(local.set $offset (call $u256_to_i32 (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)))
|
|
|
|
(local.set $requested_size (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (i64.const 32)))
|
|
|
|
(if (i32.gt_u (local.get $offset) (i32.sub (i32.const 4294967295) (local.get $requested_size))) (then
|
|
|
|
(call $eth.revert (i32.const 0) (i32.const 0))))
|
|
|
|
(local.set $available_size (i32.sub (local.get $cds) (local.get $offset)))
|
|
|
|
(if (i32.gt_u (local.get $offset) (local.get $cds)) (then
|
|
|
|
(local.set $available_size (i32.const 0))
|
|
|
|
))
|
|
|
|
(local.set $_2 (i32.const 0))
|
|
|
|
(if (i32.gt_u (local.get $available_size) (local.get $_2)) (then
|
|
|
|
(call $eth.callDataCopy (local.get $destination) (local.get $offset) (local.get $available_size))))
|
|
|
|
(if (i32.gt_u (local.get $requested_size) (local.get $available_size)) (then
|
|
|
|
(local.set $_3 (i32.sub (local.get $requested_size) (local.get $available_size)))
|
|
|
|
(local.set $_4 (i32.add (local.get $destination) (local.get $available_size)))
|
|
|
|
(local.set $i (local.get $_2))
|
2020-11-27 22:26:51 +00:00
|
|
|
(block $label__18
|
|
|
|
(loop $label__20
|
|
|
|
(br_if $label__18 (i32.eqz (i32.lt_u (local.get $i) (local.get $_3))))
|
|
|
|
(block $label__19
|
2020-11-18 02:45:49 +00:00
|
|
|
(i32.store8 (i32.add (local.get $_4) (local.get $i)) (local.get $_2))
|
|
|
|
)
|
|
|
|
(local.set $i (i32.add (local.get $i) (i32.const 1)))
|
2020-11-27 22:26:51 +00:00
|
|
|
(br $label__20)
|
2020-11-18 02:45:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
))
|
|
|
|
(local.set $z1_1 (call $bswap64 (i64.load (local.get $_2))))
|
|
|
|
(local.set $z2_1 (call $bswap64 (i64.load (i32.add (local.get $_2) (i32.const 8)))))
|
|
|
|
(local.set $z3_1 (call $bswap64 (i64.load (i32.add (local.get $_2) (i32.const 16)))))
|
|
|
|
(local.set $z4_1 (call $bswap64 (i64.load (i32.add (local.get $_2) (i32.const 24)))))
|
2020-05-25 21:33:59 +00:00
|
|
|
(local.set $z1 (local.get $z1_1))
|
|
|
|
(local.set $z2 (local.get $z2_1))
|
|
|
|
(local.set $z3 (local.get $z3_1))
|
|
|
|
(local.set $z4 (local.get $z4_1))
|
|
|
|
|
|
|
|
)
|
2020-05-12 19:01:39 +00:00
|
|
|
(global.set $global_ (local.get $z2))
|
|
|
|
(global.set $global__1 (local.get $z3))
|
|
|
|
(global.set $global__2 (local.get $z4))
|
|
|
|
(local.get $z1)
|
|
|
|
)
|
|
|
|
|
2020-11-21 20:05:39 +00:00
|
|
|
(func $sstore
|
|
|
|
(param $x1 i64)
|
|
|
|
(param $x2 i64)
|
|
|
|
(param $x3 i64)
|
|
|
|
(param $x4 i64)
|
2020-05-12 19:01:39 +00:00
|
|
|
(param $y1 i64)
|
|
|
|
(param $y2 i64)
|
|
|
|
(param $y3 i64)
|
|
|
|
(param $y4 i64)
|
2020-11-27 22:26:51 +00:00
|
|
|
(block $label__21
|
2020-11-21 20:05:39 +00:00
|
|
|
(call $mstore_internal (i32.const 0) (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4))
|
|
|
|
(call $mstore_internal (i32.const 32) (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4))
|
|
|
|
(call $eth.storageStore (i32.const 0) (i32.const 32))
|
2020-05-25 21:33:59 +00:00
|
|
|
)
|
2020-05-12 19:01:39 +00:00
|
|
|
)
|
|
|
|
|
2020-11-21 20:05:39 +00:00
|
|
|
(func $mstore_internal
|
|
|
|
(param $pos i32)
|
2020-05-12 19:01:39 +00:00
|
|
|
(param $y1 i64)
|
|
|
|
(param $y2 i64)
|
|
|
|
(param $y3 i64)
|
|
|
|
(param $y4 i64)
|
2020-11-27 22:26:51 +00:00
|
|
|
(block $label__22
|
2020-11-21 20:05:39 +00:00
|
|
|
(i64.store (local.get $pos) (call $bswap64 (local.get $y1)))
|
|
|
|
(i64.store (i32.add (local.get $pos) (i32.const 8)) (call $bswap64 (local.get $y2)))
|
|
|
|
(i64.store (i32.add (local.get $pos) (i32.const 16)) (call $bswap64 (local.get $y3)))
|
|
|
|
(i64.store (i32.add (local.get $pos) (i32.const 24)) (call $bswap64 (local.get $y4)))
|
2020-05-25 21:33:59 +00:00
|
|
|
)
|
2020-05-12 19:01:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
)
|