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
Add VM Version Paris and new built in function prevrandao
#13531
Conversation
1913d9c
to
9e901fa
Compare
I've done a bit of grepping, and it seems like you're missing a case in Also in |
9e901fa
to
ca9605d
Compare
They both have the same value, so it can only contain either
same with the other cases, all switches just use the number and the semantics didn't really change. Whether we want to update the yul interpreter m_state.difficulty part is a different question, but nothing breaks if we keep it like this. |
Not quiet sure why the grammar test fails:
|
ca9605d
to
46edbbc
Compare
found an exception in the grammar test for |
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.
Nice, that was quick :-)!
I'm missing two things:
evmasm output (so solc --asm
and related outputs) will contain opcode names - in those 0x44
should appear as difficulty
pre-paris and as prevrandao
with post-paris set as evm-version - I don't see that part accounted for in code or tests yet... test/libyul/evmCodeTransform
tests can be abused for this, and/or test/libevmasm/Assembler.cpp
.
There might also be some related complication in solidity::evmasm::c_instructions
and c_instructionInfo
getting initialized with the same key twice. This will only keep one version, won't it? We'll probably have to decide for PREVRANDAO
only there and replace accesses to those two maps by a function taking an evm-version as argument, which adjusts accordingly.
The second thing is:
Ideally, the use of difficulty()
and prevrandao()
in inline assembly and yul would also cause warnings similar to the block
members on mismatching evm versions. We usually don't warn about such things on the Yul level, so there may be some complication there and we may have to weigh whether the warning is worth adding additional infrastructure there, if needed, but ideally those should be warnings.
@@ -1,10 +1,11 @@ | |||
### 0.8.18 (unreleased) | |||
|
|||
Language Features: | |||
* Add support for ``prevrandao()`` which was introduced in EVM version to "Paris", supplanting ``difficulty`` in the process. Both can be used interchangeably. |
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.
As mentioned on the issue I think this is a bad idea, because the two outputs are expected to be vastly different and hence expect different use cases.
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.
Well, this is exactly implemented according to the summary after the discussion, so I'm not sure what to tell you here...
#13512 (comment)
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.
The main point is that we should not suggest to use them interchangeably. Supporting both (with a warning on mismatch) is a compromise for not being breaking for hypothetical libraries that want to use it as a source of randomness in a way that can rely on either version - but in general you should still very much use the correct one and not use them interchangeably.
libyul/backends/evm/EVMDialect.cpp
Outdated
_instr == evmasm::Instruction::PREVRANDAO && | ||
_instrName == "prevrandao" | ||
) | ||
return _evmVersion.hasPrevRandAO(); |
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.
What is this weird capitalisation, RandAO
?
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 dunno, I tried my best to make sense of the weird name...
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.
It comes from
A DAO (decentralised autonomous organisation) that anyone can participate in, and the random number is generated by all participants together!
So the names used are RANDAO, randao, Randao -- in this order in the consensus-specs.
Likely hasPrevRandao
is the best choice here.
This issue solves #13517 as well, right? Should be added to the top comment. |
docs/yul.rst
Outdated
@@ -935,6 +935,8 @@ the ``dup`` and ``swap`` instructions as well as ``jump`` instructions, labels a | |||
+-------------------------+-----+---+-----------------------------------------------------------------+ | |||
| difficulty() | | F | difficulty of the current block | | |||
+-------------------------+-----+---+-----------------------------------------------------------------+ | |||
| prevrandao() | | P | randomness provided by the beacon chain | |
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 this documentation piece makes it look like that both opcodes exists and return a different value.
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.
Hm what would be a good way to present it here, with the one letter column allowing very limited space
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.
We also need a test for the view-pure checker.
@@ -0,0 +1,7 @@ | |||
function f() view returns (uint) { | |||
return block.prevrandao; |
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.
Nit: indent and file name. Similarly, for other files as well. Somewhat
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.
As far as I know we use both tabs/spaces in test files, just not mixed in the same file.
About the name.. you don't like the pre-
part? I guess I could just remove it
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.
As far as I know we use both tabs/spaces in test files
We do, but I think that's not on purpose. We should settle on one version.
DIFFICULTY, ///< get the block's difficulty | ||
GASLIMIT, ///< get the block's gas limit | ||
PREVRANDAO = DIFFICULTY, ///< get randomness provided by the beacon chain | ||
GASLIMIT = 0x45, ///< get the block's gas limit |
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.
Hmm, didn't know this works.
It should. But just to note, this PR hasn't made Paris the default. |
If that is desired I can change that, no problem :) |
7c87ced
to
1228b04
Compare
There was an error when running
Please check that your changes are working as intended. |
"\"basefee\" is not supported by the VM version." | ||
); | ||
else if (memberName == "difficulty" && m_evmVersion.hasPrevRandao()) | ||
m_errorReporter.warning( |
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 would say this should be an error - because the semantic of difficulty
vs. prevrandao
is different. There is no case where difficulty
in Paris
means difficulty
- that's why I would argue that compilation need to fail 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.
A bit late to the discussion I'd say :)
I don't really mind either way, but as I understand it, this all already has been discussed
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.
The current plan is to make it a warning, since making it an error right away is borderline breaking (even though one can argue about that). With 0.9 it should definitely become an error.
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.
"\"difficulty\" was renamed and supplanted by \"prevrandao\" in the VM version paris." | ||
); | ||
else if (memberName == "prevrandao" && !m_evmVersion.hasPrevRandao()) | ||
m_errorReporter.warning( |
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 this should be an error from my point of view.
} | ||
} | ||
// ---- | ||
// ParserError 5568: (98-108): Cannot use builtin function name "difficulty" as identifier name. |
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.
Maybe also EVMVersion: <paris
here? Is a difficulty
identifier allowed again for >=paris?
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.
If yes, I think the test for this is missing.
// ==== | ||
// EVMVersion: >=paris | ||
// ---- | ||
// Warning 8417: (43-59): "difficulty" was renamed and supplanted by "prevrandao" in the VM version paris. |
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.
As written above, I think it's better to create an error instead of a warning.
// ==== | ||
// EVMVersion: <paris | ||
// ---- | ||
// Warning 9432: (43-59): "prevrandao" is not supported by the VM version and will be treated like "difficulty". |
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.
Error?
@@ -73,7 +73,7 @@ contract C { | |||
pop(coinbase()) | |||
pop(timestamp()) | |||
pop(number()) | |||
pop(difficulty()) | |||
pop(prevrandao()) |
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.
Maybe it's better to have two tests here, one <paris
and one >= paris
?
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 introduced another test inline_assembly_instructions_allowed_view_london.sol for london that contains only the changed opcode
m_errorReporter.warning( | ||
8417_error, | ||
_memberAccess.location(), | ||
"\"difficulty\" was renamed and supplanted by \"prevrandao\" in the VM version paris." |
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.
Why renamed and supplanted
and not just replaced
?
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.
It's the terminology they used in the EIP and I believe makes it most clear that it's the same opcode behind it
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.
Yeah, I saw that the EIP is using the exact same words - but I needed to check it's translation ;) that's why I thought it could make sense to use an easier wording
libevmasm/Instruction.cpp
Outdated
// { Instruction::PREVRANDAO, { "PREVRANDAO", 0, 0, 1, false, Tier::Base } }, | ||
// TODO Replace with PREVRANDAO in the next breaking release | ||
{ Instruction::DIFFICULTY, { "DIFFICULTY", 0, 0, 1, false, Tier::Base } }, |
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.
IMHO, this doesn't make sense.
It's a question of the EVM version, not with source compatibility - with the next breaking release compiling to <paris still should result in DIFFICULTY
and already now, it's weird to emit a non-existent opcode name for >=paris.
So should really do this right away, as already described in #13531 (review).
The EIP just changes the fact that there is a constant mapping from the binary opcode to instruction infos - we have to account for that in the code one way or another (and it's not like dragging an EVM version dependency through here is that much of a hassle).
…M Version Paris and new built in function ``prevrandao``
There was an error when running
Please check that your changes are working as intended. |
@@ -16,6 +16,8 @@ | |||
*/ | |||
// SPDX-License-Identifier: GPL-3.0 | |||
|
|||
#include "libevmasm/Instruction.h" |
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.
Coding style error
@@ -16,6 +16,8 @@ | |||
*/ | |||
// SPDX-License-Identifier: GPL-3.0 | |||
|
|||
#include "libevmasm/Instruction.h" | |||
#include "liblangutil/EVMVersion.h" |
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.
Coding style error
I tried to keep my automatic Search & Replace in that commit. Tests & style are not yet updated, probably some broken due to the rename. |
if (!isValidInstruction(_instr)) | ||
ret << "0x" << std::uppercase << std::hex << static_cast<int>(_instr) << _delimiter; |
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.
This doesn't look right - in case the byte wasn't a valid instruction, it should output the byte directly, not the internal enum value... so both this and eachInstruction
will probably need to change slightly.
/// Virtual machine bytecode instruction. | ||
enum class Instruction: uint8_t | ||
enum class InstructionOpCode: uint8_t |
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.
Do we really still need this one? The instruction info array can just contain the plain bytecode and the traits like inline bool isPushInstruction
can all be easily implemented on top of the other enum, can't they? Not sure I've seen all remaining uses of this yet, though.
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.
Oh, good thought. Yeah, it is very very rarely used, I think only in Disassembly.
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.
The inline functions are already implemented on top of the internal one, true
}); | ||
}; | ||
|
||
// TODO remove this in 0.9.0. We allow creating functions or identifiers in Yul with the name |
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.
Do you think it would be a good idea to open an issue preemptively, so we don't forget, or is this something that will actively cause problems once we bump to 0.9.0. and will have to be removed anyway?
This pull request is stale because it has been open for 14 days with no activity. |
Closing this as it will be superseded by #13759. |
fixes #13512
fixes #13517