From 7386869de60855429fa2587b2ad51b0cee9ab9d2 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 20 Apr 2015 14:09:41 +0200 Subject: [PATCH] Fixed byte alignment for return type of ripemd160 built-in contract. --- libsolidity/ExpressionCompiler.cpp | 8 +++++++- test/libsolidity/SolidityEndToEndTest.cpp | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index 7ea71a7a4..02f22593a 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -1066,7 +1066,13 @@ void ExpressionCompiler::appendExternalFunctionCall(FunctionType const& _functio m_context << eth::Instruction::POP; m_context << eth::Instruction::POP; // pop contract address - if (firstType) + if (_functionType.getLocation() == FunctionType::Location::RIPEMD160) + { + // fix: built-in contract returns right-aligned data + CompilerUtils(m_context).loadFromMemory(0, IntegerType(160), false, true); + appendTypeConversion(IntegerType(160), FixedBytesType(20)); + } + else if (firstType) CompilerUtils(m_context).loadFromMemory(0, *firstType, false, true); } diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index c345f5204..1d437ee5f 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1499,7 +1499,7 @@ BOOST_AUTO_TEST_CASE(ripemd) { h256 ret; dev::ripemd160(dev::ref(toBigEndian(_input)), bytesRef(&ret[0], 32)); - return u256(ret) >> (256 - 160); + return u256(ret); }; testSolidityAgainstCpp("a(bytes32)", f, u256(4)); testSolidityAgainstCpp("a(bytes32)", f, u256(5)); @@ -1814,7 +1814,7 @@ BOOST_AUTO_TEST_CASE(gas_for_builtin) )"; compileAndRun(sourceCode); BOOST_CHECK(callContractFunction("test(uint256)", 500) == bytes()); - BOOST_CHECK(callContractFunction("test(uint256)", 800) == encodeArgs(u256("0x8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"), true)); + BOOST_CHECK(callContractFunction("test(uint256)", 800) == encodeArgs(u256("0x8eb208f7e05d987a9b044a8e98c6b087f15a0bfc000000000000000000000000"), true)); } BOOST_AUTO_TEST_CASE(value_complex)