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

fixed MSTORE typo in libevmasm tests #14503

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

Saw-mon-and-Natalie
Copy link
Contributor

No description provided.

@github-actions
Copy link

Thank you for your contribution to the Solidity compiler! A team member will follow up shortly.

If you haven't read our contributing guidelines and our review checklist before, please do it now, this makes the reviewing process and accepting your contribution smoother.

If you have any questions or need our help, feel free to post them in the PR or talk to us directly on the #solidity-dev channel on Matrix.

Comment on lines +232 to +233
(numActualRefs - 1) * 5 + // DUP DUP PUSH <n> ADD MSTORE
3 // PUSH <n> ADD MSTORE
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.

Copy link
Collaborator

@matheusaaguiar matheusaaguiar left a comment

Choose a reason for hiding this comment

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

@Saw-mon-and-Natalie , thanks for the PR.
Let's stick only with the fixed typos on this one.
Can you rebase, please?

Comment on lines +232 to +233
(numActualRefs - 1) * 5 + // DUP DUP PUSH <n> ADD MSTORE
3 // PUSH <n> ADD MSTORE
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.

@ekpyron ekpyron merged commit 586a7c5 into ethereum:develop Sep 18, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants