mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11647 from ethereum/basefee
Implement London EVMVersion and the BASEFEE opcode
This commit is contained in:
@@ -122,6 +122,8 @@ EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm):
|
||||
m_evmRevision = EVMC_ISTANBUL;
|
||||
else if (_evmVersion == langutil::EVMVersion::berlin())
|
||||
m_evmRevision = EVMC_BERLIN;
|
||||
else if (_evmVersion == langutil::EVMVersion::london())
|
||||
m_evmRevision = EVMC_LONDON;
|
||||
else
|
||||
assertThrow(false, Exception, "Unsupported EVM version");
|
||||
|
||||
@@ -132,6 +134,8 @@ EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm):
|
||||
tx_context.tx_origin = 0x9292929292929292929292929292929292929292_address;
|
||||
// Mainnet according to EIP-155
|
||||
tx_context.chain_id = evmc::uint256be{1};
|
||||
// The minimum value of basefee
|
||||
tx_context.block_base_fee = evmc::bytes32{7};
|
||||
|
||||
// Reserve space for recording calls.
|
||||
if (!recorded_calls.capacity())
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
contract C {
|
||||
function f() public view returns (uint) {
|
||||
return block.basefee;
|
||||
}
|
||||
function g() public view returns (uint ret) {
|
||||
assembly {
|
||||
ret := basefee()
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=london
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 7
|
||||
// g() -> 7
|
||||
// f() -> 7
|
||||
// g() -> 7
|
||||
@@ -0,0 +1,15 @@
|
||||
contract C {
|
||||
function f() public view returns (uint) {
|
||||
return block.basefee;
|
||||
}
|
||||
function g() public view returns (uint ret) {
|
||||
assembly {
|
||||
ret := basefee()
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: =berlin
|
||||
// ----
|
||||
// TypeError 5921: (74-87): "basefee" is not supported by the VM version.
|
||||
// TypeError 5430: (183-190): The "basefee" instruction is only available for London-compatible VMs (you are currently compiling for "berlin").
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public view returns (uint) {
|
||||
return block.basefee;
|
||||
}
|
||||
function g() public view returns (uint ret) {
|
||||
assembly {
|
||||
ret := basefee()
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=london
|
||||
// ----
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
assembly { pop(basefee()) }
|
||||
}
|
||||
function g() public pure returns (uint) {
|
||||
return block.basefee;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=london
|
||||
// ----
|
||||
// TypeError 2527: (67-76): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
|
||||
// TypeError 2527: (147-160): Function declared as pure, but this expression (potentially) reads from the environment or state and thus requires "view".
|
||||
@@ -13,5 +13,5 @@ object "a" {
|
||||
// stop
|
||||
// data_acaf3289d7b601cbd114fb36c4d29c85bbfd5e133f14cb355c3fd8d99367964f 48656c6c6f2c20576f726c6421
|
||||
// Bytecode: 6006600055fe48656c6c6f2c20576f726c6421
|
||||
// Opcodes: PUSH1 0x6 PUSH1 0x0 SSTORE INVALID 0x48 PUSH6 0x6C6C6F2C2057 PUSH16 0x726C6421000000000000000000000000
|
||||
// Opcodes: PUSH1 0x6 PUSH1 0x0 SSTORE INVALID BASEFEE PUSH6 0x6C6C6F2C2057 PUSH16 0x726C6421000000000000000000000000
|
||||
// SourceMappings: 32:19:0:-:0;29:1;22:30
|
||||
|
||||
@@ -220,6 +220,8 @@ u256 EVMInstructionInterpreter::eval(
|
||||
return m_state.gasprice;
|
||||
case Instruction::CHAINID:
|
||||
return m_state.chainid;
|
||||
case Instruction::BASEFEE:
|
||||
return m_state.basefee;
|
||||
case Instruction::EXTCODESIZE:
|
||||
return u256(keccak256(h256(arg[0]))) & 0xffffff;
|
||||
case Instruction::EXTCODEHASH:
|
||||
|
||||
@@ -90,6 +90,8 @@ struct InterpreterState
|
||||
u256 difficulty = 0x9999999;
|
||||
u256 gaslimit = 4000000;
|
||||
u256 chainid = 0x01;
|
||||
/// The minimum value of basefee: 7 wei.
|
||||
u256 basefee = 0x07;
|
||||
/// Log of changes / effects. Sholud be structured data in the future.
|
||||
std::vector<std::string> trace;
|
||||
/// This is actually an input parameter that more or less limits the runtime.
|
||||
@@ -227,4 +229,3 @@ private:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user