Skip to content

Commit 95091f6

Browse files
committed
Implemented block.basefee in Solidilty and basefee() in Yul.
Also added basefee to Yul grammar.
1 parent d92b211 commit 95091f6

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed

docs/grammar/SolidityLexer.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ YulEVMBuiltin:
284284
| 'returndatacopy' | 'extcodehash' | 'create' | 'create2' | 'call' | 'callcode'
285285
| 'delegatecall' | 'staticcall' | 'return' | 'revert' | 'selfdestruct' | 'invalid'
286286
| 'log0' | 'log1' | 'log2' | 'log3' | 'log4' | 'chainid' | 'origin' | 'gasprice'
287-
| 'blockhash' | 'coinbase' | 'timestamp' | 'number' | 'difficulty' | 'gaslimit';
287+
| 'blockhash' | 'coinbase' | 'timestamp' | 'number' | 'difficulty' | 'gaslimit'
288+
| 'basefee';
288289
289290
YulLBrace: '{' -> pushMode(YulMode);
290291
YulRBrace: '}' -> popMode;

libsolidity/analysis/TypeChecker.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,6 +2947,12 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
29472947
_memberAccess.location(),
29482948
"\"chainid\" is not supported by the VM version."
29492949
);
2950+
else if (magicType->kind() == MagicType::Kind::Block && memberName == "basefee" && !m_evmVersion.hasBaseFee())
2951+
m_errorReporter.typeError(
2952+
5921_error,
2953+
_memberAccess.location(),
2954+
"\"basefee\" is not supported by the VM version."
2955+
);
29502956
}
29512957

29522958
if (

libsolidity/ast/Types.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3892,7 +3892,8 @@ MemberList::MemberMap MagicType::nativeMembers(ASTNode const*) const
38923892
{"difficulty", TypeProvider::uint256()},
38933893
{"number", TypeProvider::uint256()},
38943894
{"gaslimit", TypeProvider::uint256()},
3895-
{"chainid", TypeProvider::uint256()}
3895+
{"chainid", TypeProvider::uint256()},
3896+
{"basefee", TypeProvider::uint256()}
38963897
});
38973898
case Kind::Message:
38983899
return MemberList::MemberMap({

libsolidity/codegen/ExpressionCompiler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,8 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
17311731
m_context << Instruction::GASPRICE;
17321732
else if (member == "chainid")
17331733
m_context << Instruction::CHAINID;
1734+
else if (member == "basefee")
1735+
m_context << Instruction::BASEFEE;
17341736
else if (member == "data")
17351737
m_context << u256(0) << Instruction::CALLDATASIZE;
17361738
else if (member == "sig")

libsolidity/codegen/ir/IRGeneratorForStatements.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,8 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
17331733
define(_memberAccess) << "gasprice()\n";
17341734
else if (member == "chainid")
17351735
define(_memberAccess) << "chainid()\n";
1736+
else if (member == "basefee")
1737+
define(_memberAccess) << "basefee()\n";
17361738
else if (member == "data")
17371739
{
17381740
IRVariable var(_memberAccess);

libyul/AsmAnalysis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
695695
errorForVM(1561_error, "only available for Istanbul-compatible");
696696
else if (_instr == evmasm::Instruction::SELFBALANCE && !m_evmVersion.hasSelfBalance())
697697
errorForVM(7721_error, "only available for Istanbul-compatible");
698+
else if (_instr == evmasm::Instruction::BASEFEE && !m_evmVersion.hasBaseFee())
699+
errorForVM(5430_error, "only available for London-compatible");
698700
else if (_instr == evmasm::Instruction::PC)
699701
m_errorReporter.error(
700702
2450_error,

0 commit comments

Comments
 (0)