-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
eof: auxdatastore
as a tool to store immutables in data section of EOF
#15521
Conversation
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. |
c801f5b
to
f6a3a6e
Compare
loadimmutable
and setimmutable
in EOFauxdatastore
in EOF
auxdatastore
in EOFauxdatastore
as a tool to store immutables in data section of EOF
97c8d46
to
6fc82fe
Compare
90e0cf2
to
5539222
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not done with this yet, but I already have some comments so I thought I may just as well post them already since it's late.
libevmasm/Assembly.h
Outdated
@@ -91,8 +92,10 @@ class Assembly | |||
void appendProgramSize() { append(AssemblyItem(PushProgramSize)); } | |||
void appendLibraryAddress(std::string const& _identifier) { append(newPushLibraryAddress(_identifier)); } | |||
void appendImmutable(std::string const& _identifier) { append(newPushImmutable(_identifier)); } | |||
void appendImmutableAssignment(std::string const& _identifier) { append(newImmutableAssignment(_identifier)); } | |||
void appendImmutableAssignment(std::string const& _identifier) { append(newImmutableAssignment(_identifier));} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void appendImmutableAssignment(std::string const& _identifier) { append(newImmutableAssignment(_identifier));} | |
void appendImmutableAssignment(std::string const& _identifier) { append(newImmutableAssignment(_identifier)); } |
libevmasm/AssemblyItem.h
Outdated
@@ -55,6 +55,8 @@ enum AssemblyItemType | |||
/// Loads 32 bytes from static auxiliary data of EOF data section. The offset does *not* have to be always from the beginning | |||
/// of the data EOF section. More details here: https://github.com/ipsilon/eof/blob/main/spec/eof.md#data-section-lifecycle | |||
AuxDataLoadN, | |||
/// Stores value in a memory which which will be appended to EOF data section as static axuliary data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Stores value in a memory which which will be appended to EOF data section as static axuliary data. | |
/// Stores value in memory which will be appended to EOF data section as static auxiliary data. |
libevmasm/Assembly.cpp
Outdated
assertThrow( | ||
storesAuxData != loadsAuxData, | ||
AssemblyException, | ||
"Cannot store and load auxilairy data in the same assembly subroutine." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Cannot store and load auxilairy data in the same assembly subroutine." | |
"Cannot store and load auxiliary data in the same assembly subroutine." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please use solRequire()
instead of assertThrow()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Sorry. Legacy from assembleLegacy
:)
bool storesAuxData = false; | ||
bool loadsAuxData = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be inside the loop. Otherwise true
from the previous section will carry
over to the next one, and I think that was not the intention here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok. We want to make sure that there is no container which stores and loads auxiliary data. So storing container is init container and loading is runtime container.
@@ -173,6 +173,8 @@ std::set<YulName> createReservedIdentifiers(langutil::EVMVersion _evmVersion) | |||
"datacopy"_yulname, | |||
"setimmutable"_yulname, | |||
"loadimmutable"_yulname, | |||
"auxdataloadn"_yulname, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to note that it would be best to put left-overs from previous PRs like this in a separate commit. That's really a bugfix.
That commit could also include the other similar change, i.e. moving the auxdataloadn
test to eof/
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I will move it.
libevmasm/Assembly.cpp
Outdated
for (auto& codeSection: m_codeSections) | ||
{ | ||
for (auto const& item: codeSection.items) | ||
if (item.type() == AuxDataStore) | ||
storesAuxData = true; | ||
else if (item.type() == AuxDataLoadN) | ||
loadsAuxData = true; | ||
if (storesAuxData || loadsAuxData) | ||
assertThrow( | ||
storesAuxData != loadsAuxData, | ||
AssemblyException, | ||
"Cannot store and load auxilairy data in the same assembly subroutine." | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You asked about testing this check and there's really no good way to do it directly, because any checks here are just the last line of defense. They should be detected during analysis instead, where we have a proper error reporting mechanism.
The thing is, we don't have analysis stage for assembly, since we don't support it as input. We can get here only via Yul or through assembly import. So this check should really be at Yul level (probably in AsmAnalysis.cpp
) and later be also added as validation in the import. Here it should just be an assert (and I'm not sure this is really the right spot for this assert, since we have to scan the whole bytecode to check it, maybe we can detect it when processing AuxDataStore
and/or AuxDataLoadN
instead?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, was the problem with testing it that AssemblyException
crashes the compiler instead of showing up as an error in syntax tests? I'm not sure we're actually catching AssemblyException
up the stack, but we definitely should.
TBH, most of the errors in Assembly.cpp
should instead be assertions since they are things that should be caught by analysis. There are probably only a few that can't and have a legit reason to have validations here. And then they should be presented to to user as as errors, not crashes.
ffbd5b2
to
ba4cd55
Compare
ba4cd55
to
35e0796
Compare
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the current discussion looks like we won't need auxdatastore
after all. For now I'll focus on #15512 and we'll see later whether there's a need to return to this.
I still have a half-finished review from last week with some corrections, so I may just as well post those.
Also, good that you made #15529 not just a commit but actually a separate PR, since that part we do want.
case AuxDataStore: | ||
{ | ||
// Expect 3 elements on stack (source, dest_base, value_offset_dest) | ||
ret.bytecode.push_back(uint8_t(Instruction::ADD)); | ||
ret.bytecode.push_back(uint8_t(Instruction::MSTORE)); | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need a separate assembly item for this. I think you can simply define the Yul builtin with:
_assembly.appendInstruction(evmasm::Instruction::ADD);
_assembly.appendInstruction(evmasm::Instruction::MSTORE);
@@ -167,6 +169,8 @@ size_t AssemblyItem::bytesRequired(size_t _addressLength, langutil::EVMVersion _ | |||
return std::get<2>(*m_verbatimBytecode).size(); | |||
case AuxDataLoadN: | |||
return 1 + 2; | |||
case AuxDataStore: | |||
return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it take up 2 bytes? 1 for ADD
and 1 for MSTORE
?
@@ -110,7 +110,10 @@ class AbstractAssembly | |||
/// Appends loading an immutable variable. | |||
virtual void appendImmutable(std::string const& _identifier) = 0; | |||
/// Appends an assignment to an immutable variable. | |||
virtual void appendImmutableAssignment(std::string const& _identifier) = 0; | |||
virtual void appendImmutableAssignment(std::string const&) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd leave the variable name in. Especially since this does not have an implementation, the name of the argument is an important hint as to what it means.
This idea of having |
Depends on: #15529