Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6277577

Browse files
authored
Merge pull request argotorg#15637 from ipsilon/eof-fix-contructor-arguments-copying
eof: Fix constructor argument copying for EOF
2 parents 82cefdf + b1d3143 commit 6277577

34 files changed

+99
-25
lines changed

libsolidity/codegen/ABIFunctions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ class ABIFunctions
5656
public:
5757
explicit ABIFunctions(
5858
langutil::EVMVersion _evmVersion,
59+
std::optional<uint8_t> _eofVersion,
5960
RevertStrings _revertStrings,
6061
MultiUseYulFunctionCollector& _functionCollector
6162
):
6263
m_evmVersion(_evmVersion),
6364
m_revertStrings(_revertStrings),
6465
m_functionCollector(_functionCollector),
65-
m_utils(_evmVersion, m_revertStrings, m_functionCollector)
66+
m_utils(_evmVersion, _eofVersion, m_revertStrings, m_functionCollector)
6667
{}
6768

6869
/// @returns name of an assembly function to ABI-encode values of @a _givenTypes

libsolidity/codegen/Compiler.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ namespace solidity::frontend
3737
class Compiler
3838
{
3939
public:
40-
Compiler(langutil::EVMVersion _evmVersion, RevertStrings _revertStrings, OptimiserSettings _optimiserSettings):
40+
Compiler(
41+
langutil::EVMVersion _evmVersion,
42+
std::optional<uint8_t> _eofVersion,
43+
RevertStrings _revertStrings,
44+
OptimiserSettings _optimiserSettings
45+
):
4146
m_optimiserSettings(std::move(_optimiserSettings)),
42-
m_runtimeContext(_evmVersion, _revertStrings),
43-
m_context(_evmVersion, _revertStrings, &m_runtimeContext)
47+
m_runtimeContext(_evmVersion, _eofVersion, _revertStrings),
48+
m_context(_evmVersion, _eofVersion, _revertStrings, &m_runtimeContext)
4449
{ }
4550

4651
/// Compiles a contract.

libsolidity/codegen/CompilerContext.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class CompilerContext
6262
public:
6363
explicit CompilerContext(
6464
langutil::EVMVersion _evmVersion,
65+
std::optional<uint8_t> _eofVersion,
6566
RevertStrings _revertStrings,
6667
CompilerContext* _runtimeContext = nullptr
6768
):
@@ -70,8 +71,8 @@ class CompilerContext
7071
m_revertStrings(_revertStrings),
7172
m_reservedMemory{0},
7273
m_runtimeContext(_runtimeContext),
73-
m_abiFunctions(m_evmVersion, m_revertStrings, m_yulFunctionCollector),
74-
m_yulUtilFunctions(m_evmVersion, m_revertStrings, m_yulFunctionCollector)
74+
m_abiFunctions(m_evmVersion, _eofVersion, m_revertStrings, m_yulFunctionCollector),
75+
m_yulUtilFunctions(m_evmVersion, _eofVersion, m_revertStrings, m_yulFunctionCollector)
7576
{
7677
if (m_runtimeContext)
7778
m_runtimeSub = size_t(m_asm->newSub(m_runtimeContext->m_asm).data());

libsolidity/codegen/YulUtilFunctions.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ std::string YulUtilFunctions::revertWithError(
285285
errorArgumentTypes.push_back(arg->annotation().type);
286286
}
287287
templ("argumentVars", joinHumanReadablePrefixed(errorArgumentVars));
288-
templ("encode", ABIFunctions(m_evmVersion, m_revertStrings, m_functionCollector).tupleEncoder(errorArgumentTypes, _parameterTypes));
288+
templ("encode", ABIFunctions(m_evmVersion, m_eofVersion, m_revertStrings, m_functionCollector).tupleEncoder(errorArgumentTypes, _parameterTypes));
289289

290290
return templ.render();
291291
}
@@ -2592,7 +2592,7 @@ std::string YulUtilFunctions::copyArrayFromStorageToMemoryFunction(ArrayType con
25922592
if (_from.baseType()->isValueType())
25932593
{
25942594
solAssert(*_from.baseType() == *_to.baseType(), "");
2595-
ABIFunctions abi(m_evmVersion, m_revertStrings, m_functionCollector);
2595+
ABIFunctions abi(m_evmVersion, m_eofVersion, m_revertStrings, m_functionCollector);
25962596
return Whiskers(R"(
25972597
function <functionName>(slot) -> memPtr {
25982598
memPtr := <allocateUnbounded>()
@@ -2697,7 +2697,7 @@ std::string YulUtilFunctions::bytesOrStringConcatFunction(
26972697
templ("finalizeAllocation", finalizeAllocationFunction());
26982698
templ(
26992699
"encodePacked",
2700-
ABIFunctions{m_evmVersion, m_revertStrings, m_functionCollector}.tupleEncoderPacked(
2700+
ABIFunctions{m_evmVersion, m_eofVersion, m_revertStrings, m_functionCollector}.tupleEncoderPacked(
27012701
_argumentTypes,
27022702
targetTypes
27032703
)
@@ -3578,7 +3578,7 @@ std::string YulUtilFunctions::conversionFunction(Type const& _from, Type const&
35783578
)")
35793579
(
35803580
"abiDecode",
3581-
ABIFunctions(m_evmVersion, m_revertStrings, m_functionCollector).abiDecodingFunctionStruct(
3581+
ABIFunctions(m_evmVersion, m_eofVersion, m_revertStrings, m_functionCollector).abiDecodingFunctionStruct(
35823582
toStructType,
35833583
false
35843584
)
@@ -3907,6 +3907,7 @@ std::string YulUtilFunctions::arrayConversionFunction(ArrayType const& _from, Ar
39073907
_from.dataStoredIn(DataLocation::CallData) ?
39083908
ABIFunctions(
39093909
m_evmVersion,
3910+
m_eofVersion,
39103911
m_revertStrings,
39113912
m_functionCollector
39123913
).abiDecodingFunctionArrayAvailableLength(_to, false) :
@@ -4105,7 +4106,10 @@ std::string YulUtilFunctions::packedHashFunction(
41054106
templ("variables", suffixedVariableNameList("var_", 1, 1 + sizeOnStack));
41064107
templ("comma", sizeOnStack > 0 ? "," : "");
41074108
templ("allocateUnbounded", allocateUnboundedFunction());
4108-
templ("packedEncode", ABIFunctions(m_evmVersion, m_revertStrings, m_functionCollector).tupleEncoderPacked(_givenTypes, _targetTypes));
4109+
templ(
4110+
"packedEncode",
4111+
ABIFunctions(m_evmVersion, m_eofVersion, m_revertStrings, m_functionCollector).tupleEncoderPacked(_givenTypes, _targetTypes)
4112+
);
41094113
return templ.render();
41104114
});
41114115
}
@@ -4726,15 +4730,21 @@ std::string YulUtilFunctions::copyConstructorArgumentsToMemoryFunction(
47264730

47274731
return m_functionCollector.createFunction(functionName, [&]() {
47284732
std::string returnParams = suffixedVariableNameList("ret_param_",0, CompilerUtils::sizeOnStack(_contract.constructor()->parameters()));
4729-
ABIFunctions abiFunctions(m_evmVersion, m_revertStrings, m_functionCollector);
4733+
ABIFunctions abiFunctions(m_evmVersion, m_eofVersion, m_revertStrings, m_functionCollector);
47304734

47314735
return util::Whiskers(R"(
47324736
function <functionName>() -> <retParams> {
4733-
let programSize := datasize("<object>")
4734-
let argSize := sub(codesize(), programSize)
4735-
4736-
let memoryDataOffset := <allocate>(argSize)
4737-
codecopy(memoryDataOffset, programSize, argSize)
4737+
<?eof>
4738+
let argSize := calldatasize()
4739+
let memoryDataOffset := <allocate>(argSize)
4740+
calldatacopy(memoryDataOffset, 0, argSize)
4741+
<!eof>
4742+
let programSize := datasize("<object>")
4743+
let argSize := sub(codesize(), programSize)
4744+
4745+
let memoryDataOffset := <allocate>(argSize)
4746+
codecopy(memoryDataOffset, programSize, argSize)
4747+
</eof>
47384748
47394749
<retParams> := <abiDecode>(memoryDataOffset, add(memoryDataOffset, argSize))
47404750
}
@@ -4744,6 +4754,7 @@ std::string YulUtilFunctions::copyConstructorArgumentsToMemoryFunction(
47444754
("object", _creationObjectName)
47454755
("allocate", allocationFunction())
47464756
("abiDecode", abiFunctions.tupleDecoder(FunctionType(*_contract.constructor()).parameterTypes(), true))
4757+
("eof", m_eofVersion.has_value())
47474758
.render();
47484759
});
47494760
}

libsolidity/codegen/YulUtilFunctions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ class YulUtilFunctions
5252
public:
5353
explicit YulUtilFunctions(
5454
langutil::EVMVersion _evmVersion,
55+
std::optional<uint8_t> _eofVersion,
5556
RevertStrings _revertStrings,
5657
MultiUseYulFunctionCollector& _functionCollector
5758
):
5859
m_evmVersion(_evmVersion),
60+
m_eofVersion(_eofVersion),
5961
m_revertStrings(_revertStrings),
6062
m_functionCollector(_functionCollector)
6163
{}
@@ -640,6 +642,7 @@ class YulUtilFunctions
640642
std::string longByteArrayStorageIndexAccessNoCheckFunction();
641643

642644
langutil::EVMVersion m_evmVersion;
645+
std::optional<uint8_t> m_eofVersion;
643646
RevertStrings m_revertStrings;
644647
MultiUseYulFunctionCollector& m_functionCollector;
645648
};

libsolidity/codegen/ir/IRGenerationContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ void IRGenerationContext::internalFunctionCalledThroughDispatch(YulArity const&
224224

225225
YulUtilFunctions IRGenerationContext::utils()
226226
{
227-
return YulUtilFunctions(m_evmVersion, m_revertStrings, m_functions);
227+
return YulUtilFunctions(m_evmVersion, m_eofVersion, m_revertStrings, m_functions);
228228
}
229229

230230
ABIFunctions IRGenerationContext::abiFunctions()
231231
{
232-
return ABIFunctions(m_evmVersion, m_revertStrings, m_functions);
232+
return ABIFunctions(m_evmVersion, m_eofVersion, m_revertStrings, m_functions);
233233
}

libsolidity/codegen/ir/IRGenerator.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ std::string IRGenerator::generate(
177177
constructorParams.emplace_back(m_context.newYulVariable());
178178
t(
179179
"copyConstructorArguments",
180-
m_utils.copyConstructorArgumentsToMemoryFunction(_contract, IRNames::creationObject(_contract))
180+
m_utils.copyConstructorArgumentsToMemoryFunction(
181+
_contract,
182+
IRNames::creationObject(_contract)
183+
)
181184
);
182185
}
183186
t("constructorParams", joinHumanReadable(constructorParams));
@@ -768,7 +771,7 @@ std::string IRGenerator::generateExternalFunction(ContractDefinition const& _con
768771
unsigned paramVars = std::make_shared<TupleType>(_functionType.parameterTypes())->sizeOnStack();
769772
unsigned retVars = std::make_shared<TupleType>(_functionType.returnParameterTypes())->sizeOnStack();
770773

771-
ABIFunctions abiFunctions(m_evmVersion, m_context.revertStrings(), m_context.functionCollector());
774+
ABIFunctions abiFunctions(m_evmVersion, m_eofVersion, m_context.revertStrings(), m_context.functionCollector());
772775
t("abiDecode", abiFunctions.tupleDecoder(_functionType.parameterTypes()));
773776
t("params", suffixedVariableNameList("param_", 0, paramVars));
774777
t("retParams", suffixedVariableNameList("ret_", 0, retVars));

libsolidity/codegen/ir/IRGenerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class IRGenerator
6666
_debugInfoSelection,
6767
_soliditySourceProvider
6868
),
69-
m_utils(_evmVersion, m_context.revertStrings(), m_context.functionCollector()),
69+
m_utils(_evmVersion, _eofVersion, m_context.revertStrings(), m_context.functionCollector()),
7070
m_optimiserSettings(_optimiserSettings)
7171
{}
7272

libsolidity/codegen/ir/IRGeneratorForStatements.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
10721072
{
10731073
auto const& event = dynamic_cast<EventDefinition const&>(functionType->declaration());
10741074
TypePointers paramTypes = functionType->parameterTypes();
1075-
ABIFunctions abi(m_context.evmVersion(), m_context.revertStrings(), m_context.functionCollector());
1075+
ABIFunctions abi(m_context.evmVersion(), m_context.eofVersion(), m_context.revertStrings(), m_context.functionCollector());
10761076

10771077
std::vector<IRVariable> indexedArgs;
10781078
std::vector<std::string> nonIndexedArgs;
@@ -2843,7 +2843,7 @@ void IRGeneratorForStatements::appendBareCall(
28432843
else
28442844
{
28452845
templ("needsEncoding", true);
2846-
ABIFunctions abi(m_context.evmVersion(), m_context.revertStrings(), m_context.functionCollector());
2846+
ABIFunctions abi(m_context.evmVersion(), m_context.eofVersion(), m_context.revertStrings(), m_context.functionCollector());
28472847
templ("encode", abi.tupleEncoderPacked({&argType}, {TypeProvider::bytesMemory()}));
28482848
}
28492849

libsolidity/interface/CompilerStack.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,12 @@ void CompilerStack::compileContract(
15021502

15031503
Contract& compiledContract = m_contracts.at(_contract.fullyQualifiedName());
15041504

1505-
std::shared_ptr<Compiler> compiler = std::make_shared<Compiler>(m_evmVersion, m_revertStrings, m_optimiserSettings);
1505+
std::shared_ptr<Compiler> compiler = std::make_shared<Compiler>(
1506+
m_evmVersion,
1507+
m_eofVersion,
1508+
m_revertStrings,
1509+
m_optimiserSettings
1510+
);
15061511

15071512
solAssert(!m_viaIR, "");
15081513
bytes cborEncodedMetadata = createCBORMetadata(compiledContract, /* _forIR */ false);

0 commit comments

Comments
 (0)