Skip to content

Commit 650e023

Browse files
kkuehlzjhunsaker
authored andcommitted
[execution/ethereum]: Remove validate_output_header from chain
Having this method on the Chain object is holdover from a time when the replay ethereum and live execution had the same entrypoint. With the runloops, this is no longer necessary. Header validation on the chain is a bit of a footgun. Replaying monad from ethereum blocks uses the Monad chain with only live execution validation. Replay monad now checks the state root.
1 parent b778754 commit 650e023

File tree

11 files changed

+73
-81
lines changed

11 files changed

+73
-81
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/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(

cmd/monad/runloop_ethereum.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ Result<void> process_ethereum_block(
170170
}
171171
// Post-commit validation of header, with Merkle root fields filled in
172172
auto const output_header = db.read_eth_header();
173-
BOOST_OUTCOME_TRY(
174-
chain.validate_output_header(block.header, output_header));
173+
BOOST_OUTCOME_TRY(validate_output_header(block.header, output_header));
175174

176175
// Commit prologue: database finalization, computation of the Ethereum
177176
// block hash to append to the circular hash buffer

cmd/monad/runloop_monad.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,26 @@ bool validate_delayed_execution_results(
147147
return true;
148148
}
149149

150+
Result<void> validate_live_execution_outputs(
151+
BlockHeader const &input, BlockHeader const &output)
152+
{
153+
if (MONAD_UNLIKELY(input.ommers_hash != output.ommers_hash)) {
154+
return BlockError::WrongOmmersHash;
155+
}
156+
if (MONAD_UNLIKELY(input.transactions_root != output.transactions_root)) {
157+
return BlockError::WrongMerkleRoot;
158+
}
159+
if (MONAD_UNLIKELY(input.withdrawals_root != output.withdrawals_root)) {
160+
return BlockError::WrongMerkleRoot;
161+
}
162+
163+
// YP eq. 56
164+
if (MONAD_UNLIKELY(output.gas_used > output.gas_limit)) {
165+
return BlockError::GasAboveLimit;
166+
}
167+
return outcome::success();
168+
}
169+
150170
template <Traits traits, class MonadConsensusBlockHeader>
151171
Result<BlockExecOutput> propose_block(
152172
bytes32_t const &block_id,
@@ -315,7 +335,7 @@ Result<BlockExecOutput> propose_block(
315335
// Post-commit validation of header, with Merkle root fields filled in
316336
exec_output.eth_header = db.read_eth_header();
317337
BOOST_OUTCOME_TRY(
318-
chain.validate_output_header(block.header, exec_output.eth_header));
338+
validate_live_execution_outputs(block.header, exec_output.eth_header));
319339

320340
// Commit prologue: computation of the Ethereum block hash to append to
321341
// the circular hash buffer

cmd/monad/runloop_monad_ethblocks.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ Result<void> process_monad_block(
222222
}
223223
// Post-commit validation of header, with Merkle root fields filled in
224224
auto const output_header = db.read_eth_header();
225-
BOOST_OUTCOME_TRY(
226-
chain.validate_output_header(block.header, output_header));
225+
BOOST_OUTCOME_TRY(validate_output_header(block.header, output_header));
227226

228227
// Commit prologue: database finalization, computation of the Ethereum
229228
// block hash to append to the circular hash buffer

0 commit comments

Comments
 (0)