Skip to content

Commit dbc7fae

Browse files
authored
Merge branch 'main' into security.md
2 parents bc76ea9 + 2650343 commit dbc7fae

24 files changed

+602
-265
lines changed

category/execution/ethereum/chain/chain.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ struct Chain
4545

4646
virtual Result<void> static_validate_header(BlockHeader const &) const;
4747

48-
virtual Result<void> validate_output_header(
49-
BlockHeader const &input, BlockHeader const &output) const = 0;
50-
5148
virtual GenesisState get_genesis_state() const = 0;
5249

5350
virtual Result<void> validate_transaction(

category/execution/ethereum/chain/ethereum_mainnet.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -101,52 +101,6 @@ EthereumMainnet::static_validate_header(BlockHeader const &header) const
101101
return success();
102102
}
103103

104-
Result<void> EthereumMainnet::validate_output_header(
105-
BlockHeader const &input, BlockHeader const &output) const
106-
{
107-
// First, validate execution inputs.
108-
if (MONAD_UNLIKELY(input.ommers_hash != output.ommers_hash)) {
109-
return BlockError::WrongOmmersHash;
110-
}
111-
if (MONAD_UNLIKELY(input.transactions_root != output.transactions_root)) {
112-
return BlockError::WrongMerkleRoot;
113-
}
114-
if (MONAD_UNLIKELY(input.withdrawals_root != output.withdrawals_root)) {
115-
return BlockError::WrongMerkleRoot;
116-
}
117-
118-
// Second, validate execution outputs known before commit.
119-
120-
// YP eq. 170
121-
if (MONAD_UNLIKELY(input.gas_used != output.gas_used)) {
122-
return BlockError::InvalidGasUsed;
123-
}
124-
125-
// YP eq. 56
126-
if (MONAD_UNLIKELY(output.gas_used > output.gas_limit)) {
127-
return BlockError::GasAboveLimit;
128-
}
129-
130-
// YP eq. 33
131-
if (MONAD_UNLIKELY(input.logs_bloom != output.logs_bloom)) {
132-
return BlockError::WrongLogsBloom;
133-
}
134-
135-
if (MONAD_UNLIKELY(input.parent_hash != output.parent_hash)) {
136-
return BlockError::WrongParentHash;
137-
}
138-
139-
// Lastly, validate execution outputs only known after commit.
140-
if (MONAD_UNLIKELY(input.state_root != output.state_root)) {
141-
return BlockError::WrongMerkleRoot;
142-
}
143-
if (MONAD_UNLIKELY(input.receipts_root != output.receipts_root)) {
144-
return BlockError::WrongMerkleRoot;
145-
}
146-
147-
return success();
148-
}
149-
150104
GenesisState EthereumMainnet::get_genesis_state() const
151105
{
152106
BlockHeader header;

category/execution/ethereum/chain/ethereum_mainnet.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ struct EthereumMainnet : Chain
4646
virtual Result<void>
4747
static_validate_header(BlockHeader const &) const override;
4848

49-
virtual Result<void> validate_output_header(
50-
BlockHeader const &input, BlockHeader const &output) const override;
51-
5249
virtual GenesisState get_genesis_state() const override;
5350

5451
virtual Result<void> validate_transaction(

category/execution/ethereum/state2/block_state.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ vm::SharedVarcode BlockState::read_code(bytes32_t const &code_hash)
151151
bool BlockState::can_merge(State &state) const
152152
{
153153
MONAD_ASSERT(state_);
154-
auto &original = state.original();
154+
auto const &original = state.original();
155155
for (auto &kv : original) {
156156
Address const &address = kv.first;
157-
OriginalAccountState &account_state = kv.second;
157+
OriginalAccountState const &account_state = kv.second;
158158
auto const &account = account_state.account_;
159159
auto const &storage = account_state.storage_;
160160
StateDeltas::const_accessor it{};
@@ -164,7 +164,7 @@ bool BlockState::can_merge(State &state) const
164164
// try to fix original and current in `state` to match the block
165165
// state up until this transaction
166166
if (!state.try_fix_account_mismatch(
167-
address, account_state, it->second.account.second)) {
167+
address, it->second.account.second)) {
168168
return false;
169169
}
170170
}

category/execution/ethereum/state3/state.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ State::Map<Address, OriginalAccountState> const &State::original() const
108108
return original_;
109109
}
110110

111-
State::Map<Address, OriginalAccountState> &State::original()
112-
{
113-
return original_;
114-
}
115-
116111
State::Map<Address, VersionStack<AccountState>> const &State::current() const
117112
{
118113
return current_;
@@ -622,9 +617,11 @@ void State::set_to_state_incarnation(Address const &address)
622617
// if original and current can be adjusted to satisfy min balance, adjust
623618
// both values for merge
624619
bool State::try_fix_account_mismatch(
625-
Address const &address, OriginalAccountState &original_state,
626-
std::optional<Account> const &actual)
620+
Address const &address, std::optional<Account> const &actual)
627621
{
622+
auto const original_it = original_.find(address);
623+
MONAD_ASSERT(original_it != original_.end());
624+
OriginalAccountState &original_state = original_it->second;
628625
auto &original = original_state.account_;
629626
// verify original used and original found are otherwise the same
630627
if (is_dead(original)) {
@@ -655,10 +652,10 @@ bool State::try_fix_account_mismatch(
655652
return false;
656653
}
657654
// adjust balances
658-
auto it = current_.find(address);
659-
if (it != current_.end()) {
660-
MONAD_ASSERT(it->second.size() == 1);
661-
auto &recent_state = it->second.recent();
655+
auto const current_it = current_.find(address);
656+
if (current_it != current_.end()) {
657+
MONAD_ASSERT(current_it->second.size() == 1);
658+
auto &recent_state = current_it->second.recent();
662659
auto &recent = recent_state.account_;
663660
if (!recent) {
664661
return false;

category/execution/ethereum/state3/state.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ class State
8989

9090
Map<Address, OriginalAccountState> const &original() const;
9191

92-
Map<Address, OriginalAccountState> &original();
93-
9492
Map<Address, VersionStack<AccountState>> const &current() const;
9593

9694
Map<bytes32_t, vm::SharedVarcode> const &code() const;
@@ -208,8 +206,7 @@ class State
208206
// if original and current can be adjusted to satisfy min balance, adjust
209207
// both values for merge
210208
bool try_fix_account_mismatch(
211-
Address const &, OriginalAccountState &,
212-
std::optional<Account> const &actual);
209+
Address const &, std::optional<Account> const &actual);
213210

214211
/**
215212
* Checks whether the account currently has enough balance to cover `debit`

category/execution/ethereum/validate_block.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,52 @@ Result<void> static_validate_block(evmc_revision const rev, Block const &block)
254254
MONAD_ASSERT(false);
255255
}
256256

257+
Result<void>
258+
validate_output_header(BlockHeader const &input, BlockHeader const &output)
259+
{
260+
// First, validate execution inputs.
261+
if (MONAD_UNLIKELY(input.ommers_hash != output.ommers_hash)) {
262+
return BlockError::WrongOmmersHash;
263+
}
264+
if (MONAD_UNLIKELY(input.transactions_root != output.transactions_root)) {
265+
return BlockError::WrongMerkleRoot;
266+
}
267+
if (MONAD_UNLIKELY(input.withdrawals_root != output.withdrawals_root)) {
268+
return BlockError::WrongMerkleRoot;
269+
}
270+
271+
// Second, validate execution outputs known before commit.
272+
273+
// YP eq. 170
274+
if (MONAD_UNLIKELY(input.gas_used != output.gas_used)) {
275+
return BlockError::InvalidGasUsed;
276+
}
277+
278+
// YP eq. 56
279+
if (MONAD_UNLIKELY(output.gas_used > output.gas_limit)) {
280+
return BlockError::GasAboveLimit;
281+
}
282+
283+
// YP eq. 33
284+
if (MONAD_UNLIKELY(input.logs_bloom != output.logs_bloom)) {
285+
return BlockError::WrongLogsBloom;
286+
}
287+
288+
if (MONAD_UNLIKELY(input.parent_hash != output.parent_hash)) {
289+
return BlockError::WrongParentHash;
290+
}
291+
292+
// Lastly, validate execution outputs only known after commit.
293+
if (MONAD_UNLIKELY(input.state_root != output.state_root)) {
294+
return BlockError::WrongMerkleRoot;
295+
}
296+
if (MONAD_UNLIKELY(input.receipts_root != output.receipts_root)) {
297+
return BlockError::WrongMerkleRoot;
298+
}
299+
300+
return success();
301+
}
302+
257303
MONAD_NAMESPACE_END
258304

259305
BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN

category/execution/ethereum/validate_block.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Result<void> static_validate_block(Block const &);
7373

7474
Result<void> static_validate_block(evmc_revision, Block const &);
7575

76+
Result<void>
77+
validate_output_header(BlockHeader const &input, BlockHeader const &output);
78+
7679
MONAD_NAMESPACE_END
7780

7881
BOOST_OUTCOME_SYSTEM_ERROR2_NAMESPACE_BEGIN

category/execution/monad/chain/monad_chain.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,6 @@ evmc_revision MonadChain::get_revision(
4949
return EVMC_CANCUN;
5050
}
5151

52-
Result<void> MonadChain::validate_output_header(
53-
BlockHeader const &input, BlockHeader const &output) const
54-
{
55-
if (MONAD_UNLIKELY(input.ommers_hash != output.ommers_hash)) {
56-
return BlockError::WrongOmmersHash;
57-
}
58-
if (MONAD_UNLIKELY(input.transactions_root != output.transactions_root)) {
59-
return BlockError::WrongMerkleRoot;
60-
}
61-
if (MONAD_UNLIKELY(input.withdrawals_root != output.withdrawals_root)) {
62-
return BlockError::WrongMerkleRoot;
63-
}
64-
65-
// YP eq. 56
66-
if (MONAD_UNLIKELY(output.gas_used > output.gas_limit)) {
67-
return BlockError::GasAboveLimit;
68-
}
69-
return success();
70-
}
71-
7252
Result<void> MonadChain::validate_transaction(
7353
uint64_t const block_number, uint64_t const timestamp,
7454
Transaction const &tx, Address const &sender, State &state,

category/execution/monad/chain/monad_chain.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ struct MonadChain : Chain
5555
virtual evmc_revision
5656
get_revision(uint64_t block_number, uint64_t timestamp) const override;
5757

58-
virtual Result<void> validate_output_header(
59-
BlockHeader const &input, BlockHeader const &output) const override;
60-
6158
virtual monad_revision get_monad_revision(uint64_t timestamp) const = 0;
6259

6360
virtual Result<void> validate_transaction(

0 commit comments

Comments
 (0)