diff --git a/libyul/backends/wasm/EVMToEWasmTranslator.cpp b/libyul/backends/wasm/EVMToEWasmTranslator.cpp index 54e80fdcd..bd95c27a5 100644 --- a/libyul/backends/wasm/EVMToEWasmTranslator.cpp +++ b/libyul/backends/wasm/EVMToEWasmTranslator.cpp @@ -138,6 +138,10 @@ function div(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 { // TODO implement properly r4 := i64.div_u(x4, y4) } +function sdiv(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 { + // TODO implement properly + unreachable() +} function mod(x1, x2, x3, x4, y1, y2, y3, y4) -> r1, r2, r3, r4 { // TODO implement properly r4 := i64.rem_u(x4, y4) @@ -318,11 +322,11 @@ function sar(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 { // TODO implement unreachable() } -function addmod(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 { +function addmod(x1, x2, x3, x4, y1, y2, y3, y4, m1, m2, m3, m4) -> z1, z2, z3, z4 { // TODO implement unreachable() } -function mulmod(x1, x2, x3, x4, y1, y2, y3, y4) -> z1, z2, z3, z4 { +function mulmod(x1, x2, x3, x4, y1, y2, y3, y4, m1, m2, m3, m4) -> z1, z2, z3, z4 { // TODO implement unreachable() } diff --git a/test/libyul/EWasmTranslationTest.cpp b/test/libyul/EWasmTranslationTest.cpp index dc174ff7b..b38bb8b5c 100644 --- a/test/libyul/EWasmTranslationTest.cpp +++ b/test/libyul/EWasmTranslationTest.cpp @@ -131,7 +131,7 @@ string EWasmTranslationTest::interpret() { InterpreterState state; state.maxTraceSize = 10000; - state.maxSteps = 10000; + state.maxSteps = 100000; WasmDialect dialect; Interpreter interpreter(state, dialect); try diff --git a/test/libyul/ewasmTranslationTests/arithmetic_add.yul b/test/libyul/ewasmTranslationTests/arithmetic_add.yul new file mode 100644 index 000000000..b2203070f --- /dev/null +++ b/test/libyul/ewasmTranslationTests/arithmetic_add.yul @@ -0,0 +1,35 @@ +{ + sstore(0, add(0, 1)) + sstore(1, add(1, not(0))) + sstore(2, add(0, 0)) + sstore(3, add(1, 2)) + sstore(4, add(0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, 1)) + sstore(5, add( + 0x8000000000000000000000000000000000000000000000000000000000000000, 1 + )) + sstore(6, add(not(0), 1)) + sstore(7, add(0xffffffffffffffffffffffffffffffff, 1)) + sstore(8, add(0xffffffffffffffff, 1)) + sstore(9, add(0xffffffffffffffffffffffffffffffff0000000000000000, 1)) + sstore(10, add(0xffffffffffffffffffffffffffffffffffffffffffffffff, 3)) + sstore(11, add(0xffffffffffffffffffffffffffffffff, 3)) + sstore(12, add(0xffffffffffffffff, 3)) + sstore(13, add(0xffffffffffffffffffffffffffffffff0000000000000000, 3)) +} +// ---- +// Trace: +// Memory dump: +// 0: 000000000000000000000000000000000000000000000000000000000000000d +// 20: 0000000000000000ffffffffffffffffffffffffffffffff0000000000000003 +// Storage dump: +// 0000000000000000000000000000000000000000000000000000000000000000: 0000000000000000000000000000000000000000000000000000000000000001 +// 0000000000000000000000000000000000000000000000000000000000000003: 0000000000000000000000000000000000000000000000000000000000000003 +// 0000000000000000000000000000000000000000000000000000000000000004: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// 0000000000000000000000000000000000000000000000000000000000000005: 8000000000000000000000000000000000000000000000000000000000000001 +// 0000000000000000000000000000000000000000000000000000000000000007: 0000000000000000000000000000000100000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000008: 0000000000000000000000000000000000000000000000010000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000009: 0000000000000000ffffffffffffffffffffffffffffffff0000000000000001 +// 000000000000000000000000000000000000000000000000000000000000000a: 0000000000000001000000000000000000000000000000000000000000000002 +// 000000000000000000000000000000000000000000000000000000000000000b: 0000000000000000000000000000000100000000000000000000000000000002 +// 000000000000000000000000000000000000000000000000000000000000000c: 0000000000000000000000000000000000000000000000010000000000000002 +// 000000000000000000000000000000000000000000000000000000000000000d: 0000000000000000ffffffffffffffffffffffffffffffff0000000000000003 diff --git a/test/libyul/ewasmTranslationTests/arithmetic_addmod.yul b/test/libyul/ewasmTranslationTests/arithmetic_addmod.yul new file mode 100644 index 000000000..c1d43a731 --- /dev/null +++ b/test/libyul/ewasmTranslationTests/arithmetic_addmod.yul @@ -0,0 +1,20 @@ +{ + sstore(0, addmod(0, 1, 1)) + sstore(1, addmod(0, 1, 2)) + sstore(2, addmod(3, 1, 2)) + sstore(3, addmod(1, not(0), 5)) + sstore(4, addmod(0, 0, 0)) + sstore(5, addmod(0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, 1, 1)) + sstore(6, addmod(0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, 1, 0)) + sstore(7, addmod(0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd, 1, 5)) + sstore(8, addmod( + 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, + 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, + 5 + )) +} +// ---- +// Trace: +// INVALID() +// Memory dump: +// Storage dump: diff --git a/test/libyul/ewasmTranslationTests/arithmetic_div.yul b/test/libyul/ewasmTranslationTests/arithmetic_div.yul new file mode 100644 index 000000000..3d97f464c --- /dev/null +++ b/test/libyul/ewasmTranslationTests/arithmetic_div.yul @@ -0,0 +1,23 @@ +{ + sstore(0, div(0, 1)) + sstore(1, div(1, not(0))) + sstore(2, div(0, 0)) + sstore(3, div(1, 2)) + sstore(4, div(0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, 1)) + sstore(5, div( + 0x8000000000000000000000000000000000000000000000000000000000000000, 1 + )) + sstore(6, div(not(0), 1)) + sstore(7, div(0xffffffffffffffffffffffffffffffff, 1)) + sstore(8, div(0xffffffffffffffff, 1)) + sstore(9, div(0xffffffffffffffffffffffffffffffff0000000000000000, 1)) + sstore(10, div(0xffffffffffffffffffffffffffffffffffffffffffffffff, 3)) + sstore(11, div(0xffffffffffffffffffffffffffffffff, 3)) + sstore(12, div(0xffffffffffffffff, 3)) + sstore(13, div(0xffffffffffffffffffffffffffffffff0000000000000000, 3)) +} +// ---- +// Trace: +// Memory dump: +// 0: 0000000000000000000000000000000000000000000000000000000000000001 +// Storage dump: diff --git a/test/libyul/ewasmTranslationTests/arithmetic_exp.yul b/test/libyul/ewasmTranslationTests/arithmetic_exp.yul new file mode 100644 index 000000000..328ac9c3b --- /dev/null +++ b/test/libyul/ewasmTranslationTests/arithmetic_exp.yul @@ -0,0 +1,25 @@ +{ + sstore(0, exp(0, 1)) + sstore(1, exp(1, not(0))) + sstore(2, exp(0, 0)) + sstore(3, exp(1, 2)) + sstore(4, exp(0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, 1)) + sstore(5, exp( + 0x8000000000000000000000000000000000000000000000000000000000000000, 1 + )) + sstore(6, exp(not(0), 1)) + sstore(7, exp(0xffffffffffffffffffffffffffffffff, 2)) + sstore(8, exp(0xffffffffffffffff, 2)) + sstore(9, exp(0xffffffffffffffffffffffffffffffff0000000000000000, 2)) + sstore(10, exp(0xffffffffffffffffffffffffffffffffffffffffffffffff, 3)) + sstore(11, exp(0xffffffffffffffffffffffffffffffff, 3)) + sstore(12, exp(0xffffffffffffffff, 3)) + sstore(13, exp(0xffffffffffffffffffffffffffffffff0000000000000000, 3)) + sstore(14, exp(2, 256)) + sstore(15, exp(2, 255)) +} +// ---- +// Trace: +// INVALID() +// Memory dump: +// Storage dump: diff --git a/test/libyul/ewasmTranslationTests/arithmetic_mod.yul b/test/libyul/ewasmTranslationTests/arithmetic_mod.yul new file mode 100644 index 000000000..4aa5c6997 --- /dev/null +++ b/test/libyul/ewasmTranslationTests/arithmetic_mod.yul @@ -0,0 +1,25 @@ +{ + sstore(0, mod(0, 1)) + sstore(1, mod(1, not(0))) + sstore(2, mod(0, 0)) + sstore(3, mod(1, 2)) + sstore(4, mod(not(0), 1)) + sstore(5, mod( + 0x8000000000000000000000000000000000000000000000000000000000000000, 1 + )) + sstore(6, mod(not(0), 1)) + sstore(7, mod(0xffffffffffffffffffffffffffffffff, 1)) + sstore(8, mod(0xffffffffffffffffffffffffffffffffffffffffffffffff, 0xfffffffffffffffffffffffffffffffe)) + sstore(9, mod(0xffffffffffffffffffffffffffffffffffffffffffffffff, 5)) + sstore(10, mod(0xffffffffffffffffffffffffffffffffffffffffffffffff, 4)) + sstore(11, mod(0xffffffffffffffffffffffffffffffff, 3)) + sstore(12, mod(0xffffffffffffffff, 3)) + sstore(13, mod(0xffffffffffffffffffffffffffffffff0000000000000000, 0xffffffffffffffff43342553000)) +} +// ---- +// Trace: +// Memory dump: +// 0: 0000000000000000000000000000000000000000000000000000000000000001 +// 20: 0000000000000000000000000000000000000000000000000000000000000001 +// Storage dump: +// 0000000000000000000000000000000000000000000000000000000000000001: 0000000000000000000000000000000000000000000000000000000000000001 diff --git a/test/libyul/ewasmTranslationTests/arithmetic_mul.yul b/test/libyul/ewasmTranslationTests/arithmetic_mul.yul new file mode 100644 index 000000000..73e1bf3d8 --- /dev/null +++ b/test/libyul/ewasmTranslationTests/arithmetic_mul.yul @@ -0,0 +1,36 @@ +{ + sstore(0, mul(0, 1)) + sstore(1, mul(1, not(0))) + sstore(2, mul(0, 0)) + sstore(3, mul(1, 2)) + sstore(4, mul(0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, 1)) + sstore(5, mul( + 0x8000000000000000000000000000000000000000000000000000000000000000, 1 + )) + sstore(6, mul(not(0), 1)) + sstore(7, mul(0xffffffffffffffffffffffffffffffff, 1)) + sstore(8, mul(0xffffffffffffffff, 1)) + sstore(9, mul(0xffffffffffffffffffffffffffffffff0000000000000000, 1)) + sstore(10, mul(0xffffffffffffffffffffffffffffffffffffffffffffffff, 3)) + sstore(11, mul(0xffffffffffffffffffffffffffffffff, 3)) + sstore(12, mul(0xffffffffffffffff, 3)) + sstore(13, mul(0xffffffffffffffffffffffffffffffff0000000000000000, 3)) +} +// ---- +// Trace: +// Memory dump: +// 0: 000000000000000000000000000000000000000000000000000000000000000d +// 20: 0000000000000002fffffffffffffffffffffffffffffffd0000000000000000 +// Storage dump: +// 0000000000000000000000000000000000000000000000000000000000000001: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// 0000000000000000000000000000000000000000000000000000000000000003: 0000000000000000000000000000000000000000000000000000000000000002 +// 0000000000000000000000000000000000000000000000000000000000000004: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe +// 0000000000000000000000000000000000000000000000000000000000000005: 8000000000000000000000000000000000000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000006: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// 0000000000000000000000000000000000000000000000000000000000000007: 00000000000000000000000000000000ffffffffffffffffffffffffffffffff +// 0000000000000000000000000000000000000000000000000000000000000008: 000000000000000000000000000000000000000000000000ffffffffffffffff +// 0000000000000000000000000000000000000000000000000000000000000009: 0000000000000000ffffffffffffffffffffffffffffffff0000000000000000 +// 000000000000000000000000000000000000000000000000000000000000000a: 0000000000000002fffffffffffffffffffffffffffffffffffffffffffffffd +// 000000000000000000000000000000000000000000000000000000000000000b: 00000000000000000000000000000002fffffffffffffffffffffffffffffffd +// 000000000000000000000000000000000000000000000000000000000000000c: 000000000000000000000000000000000000000000000002fffffffffffffffd +// 000000000000000000000000000000000000000000000000000000000000000d: 0000000000000002fffffffffffffffffffffffffffffffd0000000000000000 diff --git a/test/libyul/ewasmTranslationTests/arithmetic_mulmod.yul b/test/libyul/ewasmTranslationTests/arithmetic_mulmod.yul new file mode 100644 index 000000000..094723ae0 --- /dev/null +++ b/test/libyul/ewasmTranslationTests/arithmetic_mulmod.yul @@ -0,0 +1,22 @@ +{ + sstore(0, mulmod(0, 1, 2)) + sstore(1, mulmod(1, not(0), 5)) + sstore(2, mulmod(0, 0, 5)) + sstore(3, mulmod(1, 3, 2)) + sstore(4, mulmod(0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, + 1, + 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)) + sstore(5, mulmod(0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, 1, 1)) + sstore(6, mulmod(0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, 1, 0)) + sstore(7, mulmod(0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd, 1, 5)) + sstore(8, mulmod( + not(0), + 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, + 25 + )) +} +// ---- +// Trace: +// INVALID() +// Memory dump: +// Storage dump: diff --git a/test/libyul/ewasmTranslationTests/arithmetic_sdiv.yul b/test/libyul/ewasmTranslationTests/arithmetic_sdiv.yul new file mode 100644 index 000000000..fd4364185 --- /dev/null +++ b/test/libyul/ewasmTranslationTests/arithmetic_sdiv.yul @@ -0,0 +1,25 @@ +{ + sstore(0, sdiv(0, 1)) + sstore(1, sdiv(0, not(0))) + sstore(2, sdiv(0, 0)) + sstore(3, sdiv(1, 2)) + sstore(4, sdiv(not(0), 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe)) + sstore(5, sdiv(0x8000000000000000000000000000000000000000000000000000000000000000, not(0))) + sstore(6, sdiv(not(0), 0x8000000000000000000000000000000000000000000000000000000000000000)) + sstore(7, sdiv(0x7000000000000000000000000000000000000000000000000000000000000000, 1)) + sstore(8, sdiv(1, 0x7000000000000000000000000000000000000000000000000000000000000000)) + sstore(9, sdiv(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, not(0))) + sstore(10, sdiv(not(0), 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)) + sstore(11, sdiv(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 1)) + sstore(12, sdiv(not(0), not(0))) + sstore(13, sdiv( + 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe, + 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe + )) + sstore(14, sdiv(0x8000000000000000000000000000000000000000000000000000000000000001, not(0))) +} +// ---- +// Trace: +// INVALID() +// Memory dump: +// Storage dump: diff --git a/test/libyul/ewasmTranslationTests/arithmetic_smod.yul b/test/libyul/ewasmTranslationTests/arithmetic_smod.yul new file mode 100644 index 000000000..97983a463 --- /dev/null +++ b/test/libyul/ewasmTranslationTests/arithmetic_smod.yul @@ -0,0 +1,29 @@ +{ + sstore(0, smod(0, 1)) + sstore(1, smod(1, not(0))) + sstore(2, smod(0, 0)) + sstore(3, smod(1, 2)) + sstore(4, smod(not(0), 1)) + sstore(5, smod( + 0x8000000000000000000000000000000000000000000000000000000000000000, 1 + )) + sstore(6, smod(not(0), 1)) + sstore(7, smod(0xffffffffffffffffffffffffffffffff, 1)) + sstore(8, smod(0xffffffffffffffffffffffffffffffffffffffffffffffff, 0xfffffffffffffffffffffffffffffffe)) + sstore(9, smod(0xffffffffffffffffffffffffffffffffffffffffffffffff, 5)) + sstore(10, smod(0xffffffffffffffffffffffffffffffffffffffffffffffff, 4)) + sstore(11, smod(0xffffffffffffffffffffffffffffffff, 3)) + sstore(12, smod(0xffffffffffffffff, 3)) + sstore(13, smod(0xffffffffffffffffffffffffffffffff0000000000000000, 0xffffffffffffffff43342553000)) + sstore(14, smod( + 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd, + 0xffffffffffffffff43342553000 + )) +} +// ---- +// Trace: +// Memory dump: +// 0: 0000000000000000000000000000000000000000000000000000000000000001 +// 20: 0000000000000000000000000000000000000000000000000000000000000001 +// Storage dump: +// 0000000000000000000000000000000000000000000000000000000000000001: 0000000000000000000000000000000000000000000000000000000000000001 diff --git a/test/libyul/ewasmTranslationTests/arithmetic_sub.yul b/test/libyul/ewasmTranslationTests/arithmetic_sub.yul new file mode 100644 index 000000000..fefb5d682 --- /dev/null +++ b/test/libyul/ewasmTranslationTests/arithmetic_sub.yul @@ -0,0 +1,36 @@ +{ + sstore(0, sub(0, 1)) + sstore(1, sub(1, not(0))) + sstore(2, sub(0, 0)) + sstore(3, sub(1, 2)) + sstore(4, sub(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 1)) + sstore(5, sub( + 0x8000000000000000000000000000000000000000000000000000000000000000, 1 + )) + sstore(6, sub(not(0), 1)) + sstore(7, sub(not(0), not(0))) + sstore(8, sub(0x1000000000000000000000000000000000000000000000000, 1)) + sstore(9, sub(0x100000000000000000000000000000000, 1)) + sstore(10, sub(0x10000000000000000, 1)) + sstore(11, sub(0x1000000000000000000000000000000000000000000000000, 3)) + sstore(12, sub(0x100000000000000000000000000000000, 3)) + sstore(13, sub(0x10000000000000000, 3)) +} +// ---- +// Trace: +// Memory dump: +// 0: 000000000000000000000000000000000000000000000000000000000000000d +// 20: 000000000000000000000000000000000000000000000000fffffffffffffffd +// Storage dump: +// 0000000000000000000000000000000000000000000000000000000000000000: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// 0000000000000000000000000000000000000000000000000000000000000001: 0000000000000000000000000000000000000000000000000000000000000002 +// 0000000000000000000000000000000000000000000000000000000000000003: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// 0000000000000000000000000000000000000000000000000000000000000004: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe +// 0000000000000000000000000000000000000000000000000000000000000005: 7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +// 0000000000000000000000000000000000000000000000000000000000000006: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe +// 0000000000000000000000000000000000000000000000000000000000000008: 0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffff +// 0000000000000000000000000000000000000000000000000000000000000009: 00000000000000000000000000000000ffffffffffffffffffffffffffffffff +// 000000000000000000000000000000000000000000000000000000000000000a: 000000000000000000000000000000000000000000000000ffffffffffffffff +// 000000000000000000000000000000000000000000000000000000000000000b: 0000000000000000fffffffffffffffffffffffffffffffffffffffffffffffd +// 000000000000000000000000000000000000000000000000000000000000000c: 00000000000000000000000000000000fffffffffffffffffffffffffffffffd +// 000000000000000000000000000000000000000000000000000000000000000d: 000000000000000000000000000000000000000000000000fffffffffffffffd diff --git a/test/libyul/ewasmTranslationTests/shifts.yul b/test/libyul/ewasmTranslationTests/shifts.yul index f49092a30..c3e9b6036 100644 --- a/test/libyul/ewasmTranslationTests/shifts.yul +++ b/test/libyul/ewasmTranslationTests/shifts.yul @@ -4,11 +4,16 @@ let z := shr(136, y) sstore(0, y) sstore(1, z) + sstore(2, sar(136, 0x801112131415161718191a1b1c1d1e1f20000000000000000000000000000000)) + sstore(3, sar(256, 0x801112131415161718191a1b1c1d1e1f20000000000000000000000000000000)) + sstore(4, sar(136, 0x701112131415161718191a1b1c1d1e1f20000000000000000000000000000000)) + sstore(5, sar(256, 0x701112131415161718191a1b1c1d1e1f20000000000000000000000000000000)) } // ==== // EVMVersion: >=constantinople // ---- // Trace: +// INVALID() // Memory dump: // 0: 0000000000000000000000000000000000000000000000000000000000000001 // 20: 0000000000000000000000000000000000101112131415161718191a1b1c1d1e diff --git a/test/libyul/ewasmTranslationTests/signextend.yul b/test/libyul/ewasmTranslationTests/signextend.yul new file mode 100644 index 000000000..4b5433219 --- /dev/null +++ b/test/libyul/ewasmTranslationTests/signextend.yul @@ -0,0 +1,11 @@ +{ + sstore(0, signextend(0, 0x86)) + sstore(1, signextend(0, 0x76)) + sstore(2, signextend(32, not(0))) + sstore(3, signextend(5, 0xff8844553322)) +} +// ---- +// Trace: +// INVALID() +// Memory dump: +// Storage dump: