mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
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:
co-authored by
Alex Beregszaszi
Daniel
matheusaaguiar
Nikola Matić
parent
d70d79af4a
commit
ef6ff2f055
@@ -3296,18 +3296,33 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
|
||||
(memberName == "min" || memberName == "max")
|
||||
)
|
||||
annotation.isPure = true;
|
||||
else if (magicType->kind() == MagicType::Kind::Block && memberName == "chainid" && !m_evmVersion.hasChainID())
|
||||
m_errorReporter.typeError(
|
||||
3081_error,
|
||||
_memberAccess.location(),
|
||||
"\"chainid\" is not supported by the VM version."
|
||||
);
|
||||
else if (magicType->kind() == MagicType::Kind::Block && memberName == "basefee" && !m_evmVersion.hasBaseFee())
|
||||
m_errorReporter.typeError(
|
||||
5921_error,
|
||||
_memberAccess.location(),
|
||||
"\"basefee\" is not supported by the VM version."
|
||||
);
|
||||
else if (magicType->kind() == MagicType::Kind::Block)
|
||||
{
|
||||
if (memberName == "chainid" && !m_evmVersion.hasChainID())
|
||||
m_errorReporter.typeError(
|
||||
3081_error,
|
||||
_memberAccess.location(),
|
||||
"\"chainid\" is not supported by the VM version."
|
||||
);
|
||||
else if (memberName == "basefee" && !m_evmVersion.hasBaseFee())
|
||||
m_errorReporter.typeError(
|
||||
5921_error,
|
||||
_memberAccess.location(),
|
||||
"\"basefee\" is not supported by the VM version."
|
||||
);
|
||||
else if (memberName == "prevrandao" && !m_evmVersion.hasPrevRandao())
|
||||
m_errorReporter.warning(
|
||||
9432_error,
|
||||
_memberAccess.location(),
|
||||
"\"prevrandao\" is not supported by the VM version and will be treated as \"difficulty\"."
|
||||
);
|
||||
else if (memberName == "difficulty" && m_evmVersion.hasPrevRandao())
|
||||
m_errorReporter.warning(
|
||||
8417_error,
|
||||
_memberAccess.location(),
|
||||
"Since the VM version paris, \"difficulty\" was replaced by \"prevrandao\", which now returns a random number based on the beacon chain."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
@@ -4067,6 +4067,7 @@ MemberList::MemberMap MagicType::nativeMembers(ASTNode const*) const
|
||||
{"timestamp", TypeProvider::uint256()},
|
||||
{"blockhash", TypeProvider::function(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, StateMutability::View)},
|
||||
{"difficulty", TypeProvider::uint256()},
|
||||
{"prevrandao", TypeProvider::uint256()},
|
||||
{"number", TypeProvider::uint256()},
|
||||
{"gaslimit", TypeProvider::uint256()},
|
||||
{"chainid", TypeProvider::uint256()},
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
RevertStrings _revertStrings,
|
||||
CompilerContext* _runtimeContext = nullptr
|
||||
):
|
||||
m_asm(std::make_shared<evmasm::Assembly>(_runtimeContext != nullptr, std::string{})),
|
||||
m_asm(std::make_shared<evmasm::Assembly>(_evmVersion, _runtimeContext != nullptr, std::string{})),
|
||||
m_evmVersion(_evmVersion),
|
||||
m_revertStrings(_revertStrings),
|
||||
m_reservedMemory{0},
|
||||
|
||||
@@ -1808,8 +1808,8 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
||||
m_context << Instruction::COINBASE;
|
||||
else if (member == "timestamp")
|
||||
m_context << Instruction::TIMESTAMP;
|
||||
else if (member == "difficulty")
|
||||
m_context << Instruction::DIFFICULTY;
|
||||
else if (member == "difficulty" || member == "prevrandao")
|
||||
m_context << Instruction::PREVRANDAO;
|
||||
else if (member == "number")
|
||||
m_context << Instruction::NUMBER;
|
||||
else if (member == "gaslimit")
|
||||
|
||||
@@ -1822,8 +1822,13 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
|
||||
define(_memberAccess) << "coinbase()\n";
|
||||
else if (member == "timestamp")
|
||||
define(_memberAccess) << "timestamp()\n";
|
||||
else if (member == "difficulty")
|
||||
define(_memberAccess) << "difficulty()\n";
|
||||
else if (member == "difficulty" || member == "prevrandao")
|
||||
{
|
||||
if (m_context.evmVersion().hasPrevRandao())
|
||||
define(_memberAccess) << "prevrandao()\n";
|
||||
else
|
||||
define(_memberAccess) << "difficulty()\n";
|
||||
}
|
||||
else if (member == "number")
|
||||
define(_memberAccess) << "number()\n";
|
||||
else if (member == "gaslimit")
|
||||
|
||||
@@ -381,6 +381,7 @@ Json::Value formatImmutableReferences(map<u256, pair<string, vector<size_t>>> co
|
||||
}
|
||||
|
||||
Json::Value collectEVMObject(
|
||||
langutil::EVMVersion _evmVersion,
|
||||
evmasm::LinkerObject const& _object,
|
||||
string const* _sourceMap,
|
||||
Json::Value _generatedSources,
|
||||
@@ -392,7 +393,7 @@ Json::Value collectEVMObject(
|
||||
if (_artifactRequested("object"))
|
||||
output["object"] = _object.toHex();
|
||||
if (_artifactRequested("opcodes"))
|
||||
output["opcodes"] = evmasm::disassemble(_object.bytecode);
|
||||
output["opcodes"] = evmasm::disassemble(_object.bytecode, _evmVersion);
|
||||
if (_artifactRequested("sourceMap"))
|
||||
output["sourceMap"] = _sourceMap ? *_sourceMap : "";
|
||||
if (_artifactRequested("functionDebugData"))
|
||||
@@ -1328,6 +1329,7 @@ Json::Value StandardCompiler::compileSolidity(StandardCompiler::InputsAndSetting
|
||||
wildcardMatchesExperimental
|
||||
))
|
||||
evmData["bytecode"] = collectEVMObject(
|
||||
_inputsAndSettings.evmVersion,
|
||||
compilerStack.object(contractName),
|
||||
compilerStack.sourceMapping(contractName),
|
||||
compilerStack.generatedSources(contractName),
|
||||
@@ -1349,6 +1351,7 @@ Json::Value StandardCompiler::compileSolidity(StandardCompiler::InputsAndSetting
|
||||
wildcardMatchesExperimental
|
||||
))
|
||||
evmData["deployedBytecode"] = collectEVMObject(
|
||||
_inputsAndSettings.evmVersion,
|
||||
compilerStack.runtimeObject(contractName),
|
||||
compilerStack.runtimeSourceMapping(contractName),
|
||||
compilerStack.generatedSources(contractName, true),
|
||||
@@ -1491,6 +1494,7 @@ Json::Value StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
|
||||
if (o.bytecode)
|
||||
output["contracts"][sourceName][contractName]["evm"][kind] =
|
||||
collectEVMObject(
|
||||
_inputsAndSettings.evmVersion,
|
||||
*o.bytecode,
|
||||
o.sourceMappings.get(),
|
||||
Json::arrayValue,
|
||||
|
||||
Reference in New Issue
Block a user