Skip to content

Commit 1643a6d

Browse files
committed
Add blobhash opcode
1 parent 3445313 commit 1643a6d

File tree

14 files changed

+79
-0
lines changed

14 files changed

+79
-0
lines changed

libevmasm/Instruction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ std::map<std::string, Instruction> const solidity::evmasm::c_instructions =
8181
{ "CHAINID", Instruction::CHAINID },
8282
{ "SELFBALANCE", Instruction::SELFBALANCE },
8383
{ "BASEFEE", Instruction::BASEFEE },
84+
{ "BLOBHASH", Instruction::BLOBHASH },
8485
{ "POP", Instruction::POP },
8586
{ "MLOAD", Instruction::MLOAD },
8687
{ "MSTORE", Instruction::MSTORE },
@@ -230,6 +231,7 @@ static std::map<Instruction, InstructionInfo> const c_instructionInfo =
230231
{ Instruction::CHAINID, { "CHAINID", 0, 0, 1, false, Tier::Base } },
231232
{ Instruction::SELFBALANCE, { "SELFBALANCE", 0, 0, 1, false, Tier::Low } },
232233
{ Instruction::BASEFEE, { "BASEFEE", 0, 0, 1, false, Tier::Base } },
234+
{ Instruction::BLOBHASH, { "BLOBHASH", 0, 1, 1, false, Tier::VeryLow } },
233235
{ Instruction::POP, { "POP", 0, 1, 0, false, Tier::Base } },
234236
{ Instruction::MLOAD, { "MLOAD", 0, 1, 1, true, Tier::VeryLow } },
235237
{ Instruction::MSTORE, { "MSTORE", 0, 2, 0, true, Tier::VeryLow } },

libevmasm/Instruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ enum class Instruction: uint8_t
8989
CHAINID, ///< get the config's chainid param
9090
SELFBALANCE, ///< get balance of the current account
9191
BASEFEE, ///< get the block's basefee
92+
BLOBHASH, ///< get the blob versioned hash
9293

9394
POP = 0x50, ///< remove item from stack
9495
MLOAD, ///< load word from memory

libevmasm/SemanticInformation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ bool SemanticInformation::invalidInPureFunctions(Instruction _instruction)
473473
case Instruction::CALLVALUE:
474474
case Instruction::CHAINID:
475475
case Instruction::BASEFEE:
476+
case Instruction::BLOBHASH:
476477
case Instruction::GAS:
477478
case Instruction::GASPRICE:
478479
case Instruction::EXTCODESIZE:

libevmasm/SimplificationRule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct EVMBuiltins
127127
static auto constexpr CHAINID = PatternGenerator<Instruction::CHAINID>{};
128128
static auto constexpr SELFBALANCE = PatternGenerator<Instruction::SELFBALANCE>{};
129129
static auto constexpr BASEFEE = PatternGenerator<Instruction::BASEFEE>{};
130+
static auto constexpr BLOBHASH = PatternGenerator<Instruction::BLOBHASH>{};
130131
static auto constexpr POP = PatternGenerator<Instruction::POP>{};
131132
static auto constexpr MLOAD = PatternGenerator<Instruction::MLOAD>{};
132133
static auto constexpr MSTORE = PatternGenerator<Instruction::MSTORE>{};

liblangutil/EVMVersion.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ bool EVMVersion::hasOpcode(Instruction _opcode) const
4949
return hasSelfBalance();
5050
case Instruction::BASEFEE:
5151
return hasBaseFee();
52+
case Instruction::BLOBHASH:
53+
return hasBlobhash();
5254
default:
5355
return true;
5456
}

liblangutil/EVMVersion.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class EVMVersion:
103103
bool hasBaseFee() const { return *this >= london(); }
104104
bool hasPrevRandao() const { return *this >= paris(); }
105105
bool hasPush0() const { return *this >= shanghai(); }
106+
bool hasBlobhash() const { return *this >= cancun(); }
106107

107108
bool hasOpcode(evmasm::Instruction _opcode) const;
108109

test/EVMHost.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ using namespace solidity::util;
3737
using namespace solidity::test;
3838
using namespace evmc::literals;
3939

40+
const std::array<evmc::bytes32, 2> EVMHost::m_blob_hashes =
41+
{
42+
0x0100000000000000000000000000000000000000000000000000000000000001_bytes32,
43+
0x0100000000000000000000000000000000000000000000000000000000000002_bytes32
44+
};
45+
4046
evmc::VM& EVMHost::getVM(string const& _path)
4147
{
4248
static evmc::VM NullVM{nullptr};
@@ -137,6 +143,9 @@ EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm):
137143
// The minimum value of basefee
138144
tx_context.block_base_fee = evmc::bytes32{7};
139145

146+
tx_context.blob_hashes = m_blob_hashes.data();
147+
tx_context.blob_hashes_count = m_blob_hashes.size();
148+
140149
// Reserve space for recording calls.
141150
if (!recorded_calls.capacity())
142151
recorded_calls.reserve(max_recorded_calls);

test/EVMHost.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ class EVMHost: public evmc::MockedHost
127127
static evmc::Result resultWithGas(int64_t gas_limit, int64_t gas_required, bytes const& _data) noexcept;
128128
static evmc::Result resultWithFailure() noexcept;
129129

130+
static const std::array<evmc::bytes32, 2> m_blob_hashes;
131+
130132
evmc::VM& m_vm;
131133
/// EVM version requested by the testing tool
132134
langutil::EVMVersion m_evmVersion;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
contract C {
2+
function f() public view returns (bytes32 ret) {
3+
assembly {
4+
ret := blobhash(0)
5+
}
6+
}
7+
}
8+
// ====
9+
// EVMVersion: >=cancun
10+
// ----
11+
// f() -> 0x0100000000000000000000000000000000000000000000000000000000000001
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
contract C {
2+
function f() public view returns (bytes32 ret) {
3+
assembly {
4+
ret := blobhash(3)
5+
}
6+
}
7+
}
8+
// ====
9+
// EVMVersion: >=cancun
10+
// ----
11+
// f() -> 0x00

0 commit comments

Comments
 (0)