From d0ea1f97fdbc62fa119965096623849910097bb7 Mon Sep 17 00:00:00 2001 From: Bhargava Shastry Date: Tue, 30 Jun 2020 13:34:38 +0200 Subject: [PATCH] Yul interpreter: Return selfbalance constant for the expression balance(address()) and balance constant otherwise. --- test/libyul/yulInterpreterTests/self_balance.yul | 16 ++++++++++++++++ .../yulInterpreter/EVMInstructionInterpreter.cpp | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/libyul/yulInterpreterTests/self_balance.yul diff --git a/test/libyul/yulInterpreterTests/self_balance.yul b/test/libyul/yulInterpreterTests/self_balance.yul new file mode 100644 index 000000000..99b1f960c --- /dev/null +++ b/test/libyul/yulInterpreterTests/self_balance.yul @@ -0,0 +1,16 @@ +{ + mstore(0, balance(address())) + mstore(0x20, selfbalance()) + mstore(0x40, balance(div(mul(address(), 2), 2))) + mstore(0x60, balance(add(address(), 1))) +} +// ==== +// EVMVersion: >=istanbul +// ---- +// Trace: +// Memory dump: +// 0: 0000000000000000000000000000000000000000000000000000000022223333 +// 20: 0000000000000000000000000000000000000000000000000000000022223333 +// 40: 0000000000000000000000000000000000000000000000000000000022223333 +// 60: 0000000000000000000000000000000000000000000000000000000022222222 +// Storage dump: diff --git a/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp b/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp index 9c46ea856..c17fa33e8 100644 --- a/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp +++ b/test/tools/yulInterpreter/EVMInstructionInterpreter.cpp @@ -182,7 +182,10 @@ u256 EVMInstructionInterpreter::eval( case Instruction::ADDRESS: return m_state.address; case Instruction::BALANCE: - return m_state.balance; + if (arg[0] == m_state.address) + return m_state.selfbalance; + else + return m_state.balance; case Instruction::SELFBALANCE: return m_state.selfbalance; case Instruction::ORIGIN: