Skip to content

Commit

Permalink
Replace several unnecessary EOF validations with assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
cameel committed Dec 17, 2024
1 parent 29511bc commit ef2a623
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions libevmasm/Assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,9 +1520,9 @@ LinkerObject const& Assembly::assembleEOF() const
auto const subIdsReplacements = findReferencedContainers();
auto const referencedSubIds = keys(subIdsReplacements);

solRequire(!m_codeSections.empty(), AssemblyException, "Expected at least one code section.");
solRequire(
m_codeSections.front().inputs == 0 && m_codeSections.front().outputs == 0x80, AssemblyException,
solAssert(!m_codeSections.empty(), "Expected at least one code section.");
solAssert(
m_codeSections.front().inputs == 0 && m_codeSections.front().outputs == 0x80,
"Expected the first code section to have zero inputs and be non-returning."
);

Expand Down Expand Up @@ -1659,7 +1659,8 @@ LinkerObject const& Assembly::assembleEOF() const
solAssert(tagPos != std::numeric_limits<size_t>::max(), "Reference to tag without position.");

ptrdiff_t const relativeJumpOffset = static_cast<ptrdiff_t>(tagPos) - (static_cast<ptrdiff_t>(refPos) + 2);
solRequire(-0x8000 <= relativeJumpOffset && relativeJumpOffset <= 0x7FFF, AssemblyException, "Relative jump too far");
// This cannot happen in practice because we'll run into section size limit first.
solAssert(-0x8000 <= relativeJumpOffset && relativeJumpOffset <= 0x7FFF, "Relative jump too far");
solAssert(relativeJumpOffset < -2 || 0 <= relativeJumpOffset, "Relative jump offset into immediate argument.");
setBigEndianUint16(ret.bytecode, refPos, static_cast<size_t>(static_cast<uint16_t>(relativeJumpOffset)));
}
Expand Down

0 comments on commit ef2a623

Please sign in to comment.