Merge pull request #8014 from imapp-pl/yul-ewasm-tests-imapp

Add arithmetic test cases for EVM->Ewasm translator
This commit is contained in:
Alex Beregszaszi 2019-12-18 13:50:16 +00:00 committed by GitHub
commit f58137acdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 299 additions and 3 deletions

View File

@ -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()
}

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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: