mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Sol->Yul] Implement keccak256
This commit is contained in:
parent
15eb8fec50
commit
37f04976a2
@ -607,6 +607,26 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
|
||||
break;
|
||||
}
|
||||
case FunctionType::Kind::KECCAK256:
|
||||
{
|
||||
solAssert(arguments.size() == 1, "");
|
||||
|
||||
ArrayType const* arrayType = TypeProvider::bytesMemory();
|
||||
string const& array = m_context.newYulVariable();
|
||||
m_code << "let " << array << " := " << expressionAsType(*arguments[0], *arrayType) << "\n";
|
||||
|
||||
defineExpression(_functionCall) <<
|
||||
"keccak256(" <<
|
||||
m_utils.arrayDataAreaFunction(*arrayType) << "(" <<
|
||||
array <<
|
||||
"), " <<
|
||||
m_utils.arrayLengthFunction(*arrayType) <<
|
||||
"(" <<
|
||||
array <<
|
||||
"))\n";
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
solUnimplemented("FunctionKind " + toString(static_cast<int>(functionType->kind())) + " not yet implemented");
|
||||
}
|
||||
|
@ -3470,8 +3470,10 @@ BOOST_AUTO_TEST_CASE(keccak256_empty)
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
ABI_CHECK(callContractFunction("f()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
||||
ALSO_VIA_YUL(
|
||||
compileAndRun(sourceCode);
|
||||
ABI_CHECK(callContractFunction("f()"), fromHex("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(keccak256_multiple_arguments)
|
||||
|
14
test/libsolidity/semanticTests/viaYul/keccak.sol
Normal file
14
test/libsolidity/semanticTests/viaYul/keccak.sol
Normal file
@ -0,0 +1,14 @@
|
||||
contract C {
|
||||
function keccak1() public pure returns (bytes32) {
|
||||
return keccak256("123");
|
||||
}
|
||||
function keccak2() public pure returns (bytes32) {
|
||||
bytes memory a = "123";
|
||||
return keccak256(a);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: only
|
||||
// ----
|
||||
// keccak1() -> 0x64e604787cbf194841e7b68d7cd28786f6c9a0a3ab9f8b0a0e87cb4387ab0107
|
||||
// keccak2() -> 0x64e604787cbf194841e7b68d7cd28786f6c9a0a3ab9f8b0a0e87cb4387ab0107
|
Loading…
Reference in New Issue
Block a user