Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EOF data section size validation #15667

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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