Fix abi encode with signature shortcut.

This commit is contained in:
chriseth 2021-01-14 23:12:12 +01:00
parent 6ac87a144e
commit 4f3839e4ba
2 changed files with 16 additions and 0 deletions

View File

@ -1121,6 +1121,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
"))\n";
IRVariable selectorVariable(m_context.newYulVariable(), *TypeProvider::fixedBytes(4));
define(selectorVariable, hashVariable);
selector = selectorVariable.name();
m_code << "mstore(" << to_string(CompilerUtils::freeMemoryPointer) << ", " << freeMemoryPre << ")\n";
}
}

View File

@ -0,0 +1,15 @@
contract C {
function f() public pure returns (bytes memory r1, bytes memory r2) {
string memory x = "my_signature";
r1 = abi.encodeWithSignature("my_signature", 1);
r2 = abi.encodeWithSignature(x, 1);
assert(r1.length == r2.length);
for (uint i = 0; i < r1.length; i++)
assert(r1[i] == r2[i]);
}
}
// ====
// compileToEwasm: false
// compileViaYul: also
// ----
// f() -> 0x40, 0xa0, 0x24, -813742827273327954027712588510533233455028711326166692885570228492575965184, 26959946667150639794667015087019630673637144422540572481103610249216, 0x24, -813742827273327954027712588510533233455028711326166692885570228492575965184, 26959946667150639794667015087019630673637144422540572481103610249216