Skip to content

Commit

Permalink
Merge pull request #15667 from ethereum/fix-eof-data-section-size-val…
Browse files Browse the repository at this point in the history
…idation

Fix EOF data section size validation
  • Loading branch information
cameel authored Dec 19, 2024
2 parents cea1551 + bb9d694 commit 55c6578
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions libevmasm/Assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void Assembly::importAssemblyItemsFromJSON(Json const& _code, std::vector<std::s
solAssert(m_codeSections.size() == 1);
solAssert(m_codeSections[0].items.empty());
// TODO: Add support for EOF and more than one code sections.
solUnimplementedAssert(!m_eofVersion.has_value(), "Assembly output for EOF is not yet implemented.");
solUnimplementedAssert(!m_eofVersion.has_value(), "Assembly import for EOF is not yet implemented.");
solRequire(_code.is_array(), AssemblyImportException, "Supplied JSON is not an array.");
for (auto jsonItemIter = std::begin(_code); jsonItemIter != std::end(_code); ++jsonItemIter)
{
Expand Down Expand Up @@ -452,7 +452,7 @@ Json Assembly::assemblyJSON(std::map<std::string, unsigned> const& _sourceIndice
Json root;
root[".code"] = Json::array();
Json& code = root[".code"];
// TODO: support EOF
// TODO: support EOF
solUnimplementedAssert(!m_eofVersion.has_value(), "Assembly output for EOF is not yet implemented.");
solAssert(m_codeSections.size() == 1);
for (AssemblyItem const& item: m_codeSections.front().items)
Expand Down Expand Up @@ -1683,8 +1683,12 @@ LinkerObject const& Assembly::assembleEOF() const
// DATALOADN loads 32 bytes from EOF data section zero padded if reading out of data bounds.
// In our case we do not allow DATALOADN with offsets which reads out of data bounds.
auto const staticAuxDataSize = maxAuxDataLoadNOffset.has_value() ? (*maxAuxDataLoadNOffset + 32u) : 0u;
solRequire(preDeployDataSectionSize + staticAuxDataSize < std::numeric_limits<uint16_t>::max(), AssemblyException,
"Invalid DATALOADN offset.");
auto const preDeployAndStaticAuxDataSize = preDeployDataSectionSize + staticAuxDataSize;
solRequire(
preDeployAndStaticAuxDataSize <= std::numeric_limits<uint16_t>::max(),
AssemblyException,
"Invalid DATALOADN offset."
);

// If some data was already added to data section we need to update data section refs accordingly
if (preDeployDataSectionSize > 0)
Expand All @@ -1695,8 +1699,6 @@ LinkerObject const& Assembly::assembleEOF() const
setBigEndianUint16(ret.bytecode, refPosition, staticAuxDataOffset + preDeployDataSectionSize);
}

auto const preDeployAndStaticAuxDataSize = preDeployDataSectionSize + staticAuxDataSize;

setBigEndianUint16(ret.bytecode, dataSectionSizePosition, preDeployAndStaticAuxDataSize);

return ret;
Expand Down

0 comments on commit 55c6578

Please sign in to comment.