Skip to content

Commit

Permalink
Strictly enforce the Commitments max size in CBOR (#835)
Browse files Browse the repository at this point in the history
The cbor-gen does not seem to implicitly enforce the length specified in
the underlying Golang array type. Instead, it uses the maximum number
of allowed bytes if no `maxlen` struct tag is specified (2MiB).

Strictly enforce the max allowed size to avoid potential attack vector.

Relates to:
 * whyrusleeping/cbor-gen#106
  • Loading branch information
masih authored Jan 20, 2025
1 parent 7e86edb commit 9c11ba3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions gpbft/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gpbft/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type TipSet struct {
// Blake2b256-32 CID of the CBOR-encoded power table.
PowerTable cid.Cid
// Keccak256 root hash of the commitments merkle tree.
Commitments [32]byte
Commitments [32]byte `cborgen:"maxlen=32"`
}

// Validates a tipset.
Expand Down
2 changes: 1 addition & 1 deletion gpbft/gpbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type Justification struct {
type SupplementalData struct {
// Merkle-tree of instance-specific commitments. Currently empty but this will eventually
// include things like snark-friendly power-table commitments.
Commitments [32]byte
Commitments [32]byte `cborgen:"maxlen=32"`
// The DagCBOR-blake2b256 CID of the power table used to validate the next instance, taking
// lookback into account.
PowerTable cid.Cid // []PowerEntry
Expand Down

0 comments on commit 9c11ba3

Please sign in to comment.