Skip to content

fixed MSTORE typo in libevmasm tests #14503

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

Merged
merged 1 commit into from
Sep 18, 2023
Merged
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
4 changes: 2 additions & 2 deletions test/libevmasm/Assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps)
auto const NumExpectedMappings =
(
2 + // PUSH <a> PUSH <b>
(numActualRefs - 1) * 5 + // DUP DUP PUSH <n> ADD MTOSRE
3 // PUSH <n> ADD MSTORkhbE
(numActualRefs - 1) * 5 + // DUP DUP PUSH <n> ADD MSTORE
3 // PUSH <n> ADD MSTORE
Comment on lines +232 to +233
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christianparpart , what are the assumption on the stack before the DUP opcodes? What are we dupping and is <n> supposed to be the immutable value?

this was introduced in:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the BOOST_AUTO_TEST_CASE(immutable) it seems like on top of the stack we have:

<CODE_OFFSET> <IMMUTABLE_VALUE>

and <n>. represents the relative offset of the immutable position to the code offset.

Perhaps the assumptions about the stack should be documented and wether we are always using DUP2 DUP2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snippet from Assembly::assemble():

case AssignImmutable:
{
	// Expect 2 elements on stack (source, dest_base)
	auto const& offsets = immutableReferencesBySub[i.data()].second;
	for (size_t i = 0; i < offsets.size(); ++i)
	{
		if (i != offsets.size() - 1)
		{
			ret.bytecode.push_back(uint8_t(Instruction::DUP2));
			ret.bytecode.push_back(uint8_t(Instruction::DUP2));
		}
		// TODO: should we make use of the constant optimizer methods for pushing the offsets?
		bytes offsetBytes = toCompactBigEndian(u256(offsets[i]));
		ret.bytecode.push_back(static_cast<uint8_t>(pushInstruction(static_cast<unsigned>(offsetBytes.size()))));
		ret.bytecode += offsetBytes;
		ret.bytecode.push_back(uint8_t(Instruction::ADD));
		ret.bytecode.push_back(uint8_t(Instruction::MSTORE));
	}
	if (offsets.empty())
	{
		ret.bytecode.push_back(uint8_t(Instruction::POP));
		ret.bytecode.push_back(uint8_t(Instruction::POP));
	}
	immutableReferencesBySub.erase(i.data());
	break;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the assumptions about the stack should be documented and wether we are always using DUP2 DUP2.

Maybe that's a good idea, but then it would be better if done in other PR.

) * numImmutables;

auto constexpr NumSubs = 1;
Expand Down