Adds support for the EVM version "Paris".

Deprecates `block.difficulty` and disallow `difficulty()` in inline assembly for EVM versions >= paris.
The change is due to the renaming introduced by EIP-4399 (see: https://eips.ethereum.org/EIPS/eip-4399).
Introduces `block.prevrandao` in Solidity and `prevrandao()` in inline assembly for EVM versions >= paris.

Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
Co-authored-by: Daniel <daniel@ekpyron.org>
Co-authored-by: matheusaaguiar <95899911+matheusaaguiar@users.noreply.github.com>
Co-authored-by: Nikola Matić <nikola.matic@ethereum.org>
This commit is contained in:
Rodrigo Q. Saramago
2023-01-23 18:50:36 +00:00
co-authored by Alex Beregszaszi Daniel matheusaaguiar Nikola Matić
parent d70d79af4a
commit ef6ff2f055
114 changed files with 842 additions and 221 deletions
@@ -98,7 +98,7 @@ u256 EVMInstructionInterpreter::eval(
using namespace solidity::evmasm;
using evmasm::Instruction;
auto info = instructionInfo(_instruction);
auto info = instructionInfo(_instruction, m_evmVersion);
yulAssert(static_cast<size_t>(info.args) == _arguments.size(), "");
auto const& arg = _arguments;
@@ -268,8 +268,8 @@ u256 EVMInstructionInterpreter::eval(
return m_state.timestamp;
case Instruction::NUMBER:
return m_state.blockNumber;
case Instruction::DIFFICULTY:
return m_state.difficulty;
case Instruction::PREVRANDAO:
return (m_evmVersion < langutil::EVMVersion::paris()) ? m_state.difficulty : m_state.prevrandao;
case Instruction::GASLIMIT:
return m_state.gaslimit;
// --------------- memory / storage / logs ---------------
@@ -543,7 +543,7 @@ void EVMInstructionInterpreter::logTrace(
)
{
logTrace(
evmasm::instructionInfo(_instruction).name,
evmasm::instructionInfo(_instruction, m_evmVersion).name,
SemanticInformation::memory(_instruction) == SemanticInformation::Effect::Write,
_arguments,
_data
@@ -26,6 +26,8 @@
#include <libsolutil/CommonData.h>
#include <libsolutil/Numeric.h>
#include <liblangutil/EVMVersion.h>
#include <vector>
namespace solidity::evmasm
@@ -74,7 +76,8 @@ struct InterpreterState;
class EVMInstructionInterpreter
{
public:
explicit EVMInstructionInterpreter(InterpreterState& _state, bool _disableMemWriteTrace):
explicit EVMInstructionInterpreter(langutil::EVMVersion _evmVersion, InterpreterState& _state, bool _disableMemWriteTrace):
m_evmVersion(_evmVersion),
m_state(_state),
m_disableMemoryWriteInstructions(_disableMemWriteTrace)
{}
@@ -128,6 +131,7 @@ private:
return m_disableMemoryWriteInstructions;
}
langutil::EVMVersion m_evmVersion;
InterpreterState& m_state;
/// Flag to disable trace of instructions that write to memory.
bool m_disableMemoryWriteInstructions;
@@ -597,7 +597,7 @@ u256 EwasmBuiltinInterpreter::readU256(uint64_t _offset, size_t _croppedTo)
void EwasmBuiltinInterpreter::logTrace(evmasm::Instruction _instruction, std::vector<u256> const& _arguments, bytes const& _data)
{
logTrace(evmasm::instructionInfo(_instruction).name, _arguments, _data);
logTrace(evmasm::instructionInfo(_instruction, langutil::EVMVersion()).name, _arguments, _data);
}
void EwasmBuiltinInterpreter::logTrace(std::string const& _pseudoInstruction, std::vector<u256> const& _arguments, bytes const& _data)
+1 -1
View File
@@ -314,7 +314,7 @@ void ExpressionEvaluator::operator()(FunctionCall const& _funCall)
{
if (BuiltinFunctionForEVM const* fun = dialect->builtin(_funCall.functionName.name))
{
EVMInstructionInterpreter interpreter(m_state, m_disableMemoryTrace);
EVMInstructionInterpreter interpreter(dialect->evmVersion(), m_state, m_disableMemoryTrace);
u256 const value = interpreter.evalBuiltin(*fun, _funCall.arguments, values());
+1
View File
@@ -94,6 +94,7 @@ struct InterpreterState
u256 timestamp = 0x88888888;
u256 blockNumber = 1024;
u256 difficulty = 0x9999999;
u256 prevrandao = (u256(1) << 64) + 1;
u256 gaslimit = 4000000;
u256 chainid = 0x01;
/// The minimum value of basefee: 7 wei.