|
6 | 6 | "fmt" |
7 | 7 |
|
8 | 8 | "github.com/cometbft/cometbft/abci/types" |
| 9 | + cmttypes "github.com/cometbft/cometbft/types" |
9 | 10 |
|
10 | 11 | "github.com/oasisprotocol/oasis-core/go/common/cbor" |
11 | 12 | consensus "github.com/oasisprotocol/oasis-core/go/consensus/api" |
@@ -33,10 +34,12 @@ func (mux *abciMux) prepareSystemTxs() ([][]byte, []*types.ResponseDeliverTx, er |
33 | 34 | if err != nil { |
34 | 35 | return nil, nil, fmt.Errorf("failed to compute events root: %w", err) |
35 | 36 | } |
| 37 | + resultsHash := mux.computeResultsHash() |
36 | 38 |
|
37 | 39 | blockMeta := consensus.NewBlockMetadataTx(&consensus.BlockMetadata{ |
38 | | - StateRoot: stateRoot, |
39 | | - EventsRoot: eventsRoot, |
| 40 | + StateRoot: stateRoot, |
| 41 | + EventsRoot: eventsRoot, |
| 42 | + ResultsHash: resultsHash, |
40 | 43 | }) |
41 | 44 | sigBlockMeta, err := transaction.Sign(mux.state.identity.ConsensusSigner, blockMeta) |
42 | 45 | if err != nil { |
@@ -97,7 +100,7 @@ func (mux *abciMux) validateSystemTxs() error { |
97 | 100 | for _, tx := range mux.state.blockCtx.SystemTransactions { |
98 | 101 | switch tx.Method { |
99 | 102 | case consensus.MethodMeta: |
100 | | - // Block metadata, verify state root. |
| 103 | + // Decode block metadata. |
101 | 104 | if hasBlockMetadata { |
102 | 105 | return fmt.Errorf("duplicate block metadata in block") |
103 | 106 | } |
@@ -129,9 +132,16 @@ func (mux *abciMux) validateSystemTxs() error { |
129 | 132 | return fmt.Errorf("invalid events root in block metadata (expected: %x got: %x)", eventsRoot, meta.EventsRoot) |
130 | 133 | } |
131 | 134 |
|
| 135 | + // Verify results hash. |
| 136 | + resultsHash := mux.computeResultsHash() |
| 137 | + if !bytes.Equal(resultsHash, meta.ResultsHash) { |
| 138 | + return fmt.Errorf("invalid results hash in block metadata (expected: %x got: %x)", resultsHash, meta.ResultsHash) |
| 139 | + } |
| 140 | + |
132 | 141 | mux.logger.Debug("validated block metadata", |
133 | 142 | "state_root", meta.StateRoot, |
134 | 143 | "events_root", hex.EncodeToString(eventsRoot), |
| 144 | + "results_hash", hex.EncodeToString(resultsHash), |
135 | 145 | ) |
136 | 146 | default: |
137 | 147 | return fmt.Errorf("unknown system method: %s", tx.Method) |
@@ -171,3 +181,10 @@ func (mux *abciMux) computeEventsRoot() ([]byte, error) { |
171 | 181 |
|
172 | 182 | return merkle.RootHash(events), nil |
173 | 183 | } |
| 184 | + |
| 185 | +func (mux *abciMux) computeResultsHash() []byte { |
| 186 | + if !mux.state.ConsensusParameters().IsFeatureVersion(migrations.Version256) { |
| 187 | + return nil |
| 188 | + } |
| 189 | + return cmttypes.NewResults(mux.state.proposal.resultsDeliverTx).Hash() |
| 190 | +} |
0 commit comments