Skip to content

Conversation

@lukechampine
Copy link
Member

Previously, we used the policy itself to figure out how many signatures and preimages to expect. This saved two length prefixes (16 bytes), but it was annoying to implement, and also led to a vulnerability: EncodeTo panicked when called with the wrong number of signatures or preimages, but UnmarshalJSON did not validate these, so you could trigger a panic by causing a node to decode an invalid SpendPolicy as JSON and then encode it as binary.

The modal satisfied policy is 1 pubkey + 1 signature, so ~100 bytes, making this a ~16% size increase. Not insignificant, but tolerable.

Note that we don't need any additional validation: (SpendPolicy).Verify already checks for superfluous signatures and preimages.

@lukechampine
Copy link
Member Author

(this will break existing consensus.dbs, btw... rip)

@n8mgr
Copy link
Member

n8mgr commented Nov 18, 2024

(this will break existing consensus.dbs, btw... rip)

Only ones that have the hard fork activated, no?

@lukechampine
Copy link
Member Author

oh, true. phew

@lukechampine lukechampine merged commit 88d9985 into master Nov 18, 2024
10 checks passed
@lukechampine lukechampine deleted the encoding branch November 18, 2024 23:57
Alrighttt added a commit to GLEECBTC/sia-rust that referenced this pull request Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants