diff --git a/Changelog.md b/Changelog.md index 916dbfde5..3939681b0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,8 @@ ### 0.8.7 (unreleased) Language Features: + * Introduce global ``block.basefee`` for retrieving the base fee of the current block. + * Yul: Introduce builtin ``basefee()`` for retrieving the base fee of the current block. Compiler Features: diff --git a/test/libsolidity/semanticTests/state/block_basefee.sol b/test/libsolidity/semanticTests/state/block_basefee.sol new file mode 100644 index 000000000..0b54008b0 --- /dev/null +++ b/test/libsolidity/semanticTests/state/block_basefee.sol @@ -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 diff --git a/test/libsolidity/syntaxTests/types/magic_block_basefee_error.sol b/test/libsolidity/syntaxTests/types/magic_block_basefee_error.sol new file mode 100644 index 000000000..706fa3183 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/magic_block_basefee_error.sol @@ -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"). diff --git a/test/libsolidity/syntaxTests/types/magic_block_london.sol b/test/libsolidity/syntaxTests/types/magic_block_london.sol new file mode 100644 index 000000000..0d65672ca --- /dev/null +++ b/test/libsolidity/syntaxTests/types/magic_block_london.sol @@ -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 +// ---- diff --git a/test/libsolidity/syntaxTests/viewPureChecker/basefee_not_pure.sol b/test/libsolidity/syntaxTests/viewPureChecker/basefee_not_pure.sol new file mode 100644 index 000000000..0d7c19086 --- /dev/null +++ b/test/libsolidity/syntaxTests/viewPureChecker/basefee_not_pure.sol @@ -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". diff --git a/test/libyul/objectCompiler/dataoffset_data.yul b/test/libyul/objectCompiler/dataoffset_data.yul index 2a029785b..bc066c802 100644 --- a/test/libyul/objectCompiler/dataoffset_data.yul +++ b/test/libyul/objectCompiler/dataoffset_data.yul @@ -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