Skip to content

Commit 8607690

Browse files
authored
Merge pull request #6029 from ethereum/fixDelegatecallV2
Fix combination of delegatecall and ABIEncoderV2.
2 parents f74a139 + d5791fe commit 8607690

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Compiler Features:
88

99

1010
Bugfixes:
11+
* ABIEncoderV2: Fix internal error related to bare delegatecall.
1112
* ABIEncoderV2: Fix internal error related to mappings as library parameters.
1213
* Yul: Properly detect name clashes with functions before their declaration.
1314

libsolidity/codegen/ExpressionCompiler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1967,12 +1967,13 @@ void ExpressionCompiler::appendExternalFunctionCall(
19671967
// If the function takes arbitrary parameters or is a bare call, copy dynamic length data in place.
19681968
// Move arguments to memory, will not update the free memory pointer (but will update the memory
19691969
// pointer on the stack).
1970+
bool encodeForLibraryCall = funKind == FunctionType::Kind::DelegateCall;
19701971
utils().encodeToMemory(
19711972
argumentTypes,
19721973
parameterTypes,
19731974
_functionType.padArguments(),
19741975
_functionType.takesArbitraryParameters() || _functionType.isBareCall(),
1975-
isDelegateCall
1976+
encodeForLibraryCall
19761977
);
19771978

19781979
// Stack now:

test/libsolidity/SolidityEndToEndTest.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4440,23 +4440,29 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall)
44404440
}
44414441
}
44424442
)**";
4443-
compileAndRun(sourceCode, 0, "Receiver");
4444-
u160 const c_receiverAddress = m_contractAddress;
4445-
compileAndRun(sourceCode, 50, "Sender");
4446-
u160 const c_senderAddress = m_contractAddress;
4447-
BOOST_CHECK(m_sender != c_senderAddress); // just for sanity
4448-
ABI_CHECK(callContractFunctionWithValue("doSend(address)", 11, c_receiverAddress), encodeArgs());
4449-
ABI_CHECK(callContractFunction("received()"), encodeArgs(u256(23)));
4450-
ABI_CHECK(callContractFunction("sender()"), encodeArgs(u160(m_sender)));
4451-
ABI_CHECK(callContractFunction("value()"), encodeArgs(u256(11)));
4452-
m_contractAddress = c_receiverAddress;
4453-
ABI_CHECK(callContractFunction("received()"), encodeArgs(u256(0)));
4454-
ABI_CHECK(callContractFunction("sender()"), encodeArgs(u256(0)));
4455-
ABI_CHECK(callContractFunction("value()"), encodeArgs(u256(0)));
4456-
BOOST_CHECK(storageEmpty(c_receiverAddress));
4457-
BOOST_CHECK(!storageEmpty(c_senderAddress));
4458-
BOOST_CHECK_EQUAL(balanceAt(c_receiverAddress), 0);
4459-
BOOST_CHECK_EQUAL(balanceAt(c_senderAddress), 50 + 11);
4443+
4444+
for (auto v2: {false, true})
4445+
{
4446+
string source = (v2 ? "pragma experimental ABIEncoderV2;\n" : "") + string(sourceCode);
4447+
4448+
compileAndRun(source, 0, "Receiver");
4449+
u160 const c_receiverAddress = m_contractAddress;
4450+
compileAndRun(source, 50, "Sender");
4451+
u160 const c_senderAddress = m_contractAddress;
4452+
BOOST_CHECK(m_sender != c_senderAddress); // just for sanity
4453+
ABI_CHECK(callContractFunctionWithValue("doSend(address)", 11, c_receiverAddress), encodeArgs());
4454+
ABI_CHECK(callContractFunction("received()"), encodeArgs(u256(23)));
4455+
ABI_CHECK(callContractFunction("sender()"), encodeArgs(u160(m_sender)));
4456+
ABI_CHECK(callContractFunction("value()"), encodeArgs(u256(11)));
4457+
m_contractAddress = c_receiverAddress;
4458+
ABI_CHECK(callContractFunction("received()"), encodeArgs(u256(0)));
4459+
ABI_CHECK(callContractFunction("sender()"), encodeArgs(u256(0)));
4460+
ABI_CHECK(callContractFunction("value()"), encodeArgs(u256(0)));
4461+
BOOST_CHECK(storageEmpty(c_receiverAddress));
4462+
BOOST_CHECK(!storageEmpty(c_senderAddress));
4463+
BOOST_CHECK_EQUAL(balanceAt(c_receiverAddress), 0);
4464+
BOOST_CHECK_EQUAL(balanceAt(c_senderAddress), 50 + 11);
4465+
}
44604466
}
44614467

44624468
BOOST_AUTO_TEST_CASE(generic_staticcall)

0 commit comments

Comments
 (0)