From deffb7ffc8ea251184c091d3e4279a8820ecea07 Mon Sep 17 00:00:00 2001 From: Bhargava Shastry Date: Mon, 13 Jul 2020 14:23:43 +0200 Subject: [PATCH] Yul interpreter: Return addresses of type u160 for create and create2 calls --- test/libyul/yulInterpreterTests/and_create.yul | 13 +++++++++++++ test/libyul/yulInterpreterTests/and_create2.yul | 15 +++++++++++++++ .../yulInterpreter/EVMInstructionInterpreter.cpp | 4 ++-- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/libyul/yulInterpreterTests/and_create.yul create mode 100644 test/libyul/yulInterpreterTests/and_create2.yul diff --git a/test/libyul/yulInterpreterTests/and_create.yul b/test/libyul/yulInterpreterTests/and_create.yul new file mode 100644 index 000000000..890708150 --- /dev/null +++ b/test/libyul/yulInterpreterTests/and_create.yul @@ -0,0 +1,13 @@ +{ + let u160max := 0xffffffffffffffffffffffffffffffffffffffff + let a := create(0, u160max, 0) + let b := and(u160max, create(0, u160max, 0)) + mstore(0, eq(a, b)) +} +// ---- +// Trace: +// CREATE(0, 0xffffffffffffffffffffffffffffffffffffffff, 0) +// CREATE(0, 0xffffffffffffffffffffffffffffffffffffffff, 0) +// Memory dump: +// 0: 0000000000000000000000000000000000000000000000000000000000000001 +// Storage dump: diff --git a/test/libyul/yulInterpreterTests/and_create2.yul b/test/libyul/yulInterpreterTests/and_create2.yul new file mode 100644 index 000000000..46df2a9ca --- /dev/null +++ b/test/libyul/yulInterpreterTests/and_create2.yul @@ -0,0 +1,15 @@ +{ + let u160max := 0xffffffffffffffffffffffffffffffffffffffff + let a := create2(0, u160max, 0, 0) + let b := and(u160max, create2(0, u160max, 0, 0)) + mstore(0, eq(a, b)) +} +// ==== +// EVMVersion: >=constantinople +// ---- +// Trace: +// CREATE2(0, 0xffffffffffffffffffffffffffffffffffffffff, 0, 0) +// CREATE2(0, 0xffffffffffffffffffffffffffffffffffffffff, 0, 0) +// Memory dump: +// 0: 0000000000000000000000000000000000000000000000000000000000000001 +// Storage dump: diff --git a/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp b/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp index 956db124f..b3cf78bab 100644 --- a/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp +++ b/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp @@ -303,11 +303,11 @@ u256 EVMInstructionInterpreter::eval( case Instruction::CREATE: accessMemory(arg[1], arg[2]); logTrace(_instruction, arg); - return 0xcccccc + arg[1]; + return u160(0xcccccc + arg[1]); case Instruction::CREATE2: accessMemory(arg[2], arg[3]); logTrace(_instruction, arg); - return 0xdddddd + arg[1]; + return u160(0xdddddd + arg[1]); case Instruction::CALL: case Instruction::CALLCODE: // TODO assign returndata