Skip to content

Commit ffcacc5

Browse files
kkuehlzjhunsaker
authored andcommitted
[execution/ethereum]: Set block history code hash
Use to_byte_string_view helper. Default constructor treats the 0x00 byte as a null terminator string, causing the code to be truncated.
1 parent 378b0dc commit ffcacc5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

category/execution/ethereum/block_hash_history.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <cstdint>
2828

29-
MONAD_NAMESPACE_BEGIN
29+
MONAD_ANONYMOUS_NAMESPACE_BEGIN
3030

3131
constexpr uint8_t BLOCK_HISTORY_CODE[] = {
3232
0x33, 0x73, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -37,17 +37,24 @@ constexpr uint8_t BLOCK_HISTORY_CODE[] = {
3737
0x5f, 0x52, 0x60, 0x20, 0x5f, 0xf3, 0x5b, 0x5f, 0x5f, 0xfd, 0x5b, 0x5f,
3838
0x35, 0x61, 0x1f, 0xff, 0x60, 0x01, 0x43, 0x03, 0x06, 0x55, 0x00};
3939

40+
constexpr auto BLOCK_HISTORY_CODE_HASH{
41+
0x6e49e66782037c0555897870e29fa5e552daf4719552131a0abce779daec0a5d_bytes32};
42+
43+
MONAD_ANONYMOUS_NAMESPACE_END
44+
45+
MONAD_NAMESPACE_BEGIN
46+
4047
void deploy_block_hash_history_contract(State &state)
4148
{
4249
if (MONAD_LIKELY(state.account_exists(BLOCK_HISTORY_ADDRESS))) {
4350
return;
4451
}
4552

46-
bytes32_t const code_hash = to_bytes(keccak256(BLOCK_HISTORY_CODE));
47-
4853
state.create_contract(BLOCK_HISTORY_ADDRESS);
49-
state.set_code_hash(BLOCK_HISTORY_ADDRESS, code_hash);
50-
state.set_code(BLOCK_HISTORY_ADDRESS, BLOCK_HISTORY_CODE);
54+
state.set_code(
55+
BLOCK_HISTORY_ADDRESS, to_byte_string_view(BLOCK_HISTORY_CODE));
56+
MONAD_ASSERT(
57+
state.get_code_hash(BLOCK_HISTORY_ADDRESS) == BLOCK_HISTORY_CODE_HASH);
5158
state.set_nonce(BLOCK_HISTORY_ADDRESS, 1);
5259
}
5360

0 commit comments

Comments
 (0)