Skip to content

Commit f4a7992

Browse files
committed
go/consensus/cometbft/abci/system: Add results hash to system tx
The results hash was added to the system transaction so that stateless clients can partially verify the latest block’s results.
1 parent 7b10903 commit f4a7992

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

.changelog/6289.breaking.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
go/consensus/cometbft/abci/system: Add results hash to system tx
2+
3+
The results hash was added to the system transaction so that stateless
4+
clients can partially verify the latest block’s results.

go/consensus/api/meta.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ type BlockMetadata struct {
2525
StateRoot hash.Hash `json:"state_root"`
2626
// EventsRoot is the root hash of all events emitted in the block.
2727
EventsRoot []byte `json:"events_root"`
28+
// ResultsHash is the hash of transaction results in the block.
29+
ResultsHash []byte `json:"results_hash"`
2830
}
2931

3032
// ValidateBasic performs basic block metadata structure validation.
3133
func (bm *BlockMetadata) ValidateBasic() error {
3234
if len(bm.EventsRoot) != 32 {
3335
return fmt.Errorf("malformed events root")
3436
}
37+
if bm.ResultsHash != nil && len(bm.ResultsHash) != 32 {
38+
return fmt.Errorf("malformed results hash")
39+
}
3540
return nil
3641
}
3742

go/consensus/cometbft/abci/system.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77

88
"github.com/cometbft/cometbft/abci/types"
9+
cmttypes "github.com/cometbft/cometbft/types"
910

1011
"github.com/oasisprotocol/oasis-core/go/common/cbor"
1112
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
@@ -33,10 +34,12 @@ func (mux *abciMux) prepareSystemTxs() ([][]byte, []*types.ResponseDeliverTx, er
3334
if err != nil {
3435
return nil, nil, fmt.Errorf("failed to compute events root: %w", err)
3536
}
37+
resultsHash := mux.computeResultsHash()
3638

3739
blockMeta := consensus.NewBlockMetadataTx(&consensus.BlockMetadata{
38-
StateRoot: stateRoot,
39-
EventsRoot: eventsRoot,
40+
StateRoot: stateRoot,
41+
EventsRoot: eventsRoot,
42+
ResultsHash: resultsHash,
4043
})
4144
sigBlockMeta, err := transaction.Sign(mux.state.identity.ConsensusSigner, blockMeta)
4245
if err != nil {
@@ -97,7 +100,7 @@ func (mux *abciMux) validateSystemTxs() error {
97100
for _, tx := range mux.state.blockCtx.SystemTransactions {
98101
switch tx.Method {
99102
case consensus.MethodMeta:
100-
// Block metadata, verify state root.
103+
// Decode block metadata.
101104
if hasBlockMetadata {
102105
return fmt.Errorf("duplicate block metadata in block")
103106
}
@@ -129,9 +132,16 @@ func (mux *abciMux) validateSystemTxs() error {
129132
return fmt.Errorf("invalid events root in block metadata (expected: %x got: %x)", eventsRoot, meta.EventsRoot)
130133
}
131134

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+
132141
mux.logger.Debug("validated block metadata",
133142
"state_root", meta.StateRoot,
134143
"events_root", hex.EncodeToString(eventsRoot),
144+
"results_hash", hex.EncodeToString(resultsHash),
135145
)
136146
default:
137147
return fmt.Errorf("unknown system method: %s", tx.Method)
@@ -171,3 +181,10 @@ func (mux *abciMux) computeEventsRoot() ([]byte, error) {
171181

172182
return merkle.RootHash(events), nil
173183
}
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+
}

go/upgrade/migrations/consensus_256.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
// are allowed to query runtime key shares.
1717
// - An updated events root in the block metadata system transaction to capture all events
1818
// emitted in the block.
19+
// - A results hash in the block metadata system transaction.
1920
const Consensus256 = "consensus256"
2021

2122
// Version256 is the Oasis Core 25.6 version.

0 commit comments

Comments
 (0)