Skip to content

use go-dasl/drisl instead of go-ipld-cbor#35

Open
bnewbold wants to merge 2 commits intomainfrom
bnewbold/drisl
Open

use go-dasl/drisl instead of go-ipld-cbor#35
bnewbold wants to merge 2 commits intomainfrom
bnewbold/drisl

Conversation

@bnewbold
Copy link
Copy Markdown
Member

@bnewbold bnewbold commented Feb 19, 2026

This is an update of: #17

Ran go mod tidy and it is clear how much this cleans up the dependency tree!

I didn't update the CID() method helpers; instead I had them return the empty CID instead of panic-ing. I think it should be very rare (impossible?) to have problems there? Though it is possible we need to enforce size limits.

Edit: actually maybe we should be erroring harder on the failed CID generation. There would be a multi-stage attack where a corrupt op gets in the log, and then a successor op has prev set to the empty CID, and they would "match" (?).

Comment thread didplc/operation.go
return computeCID(op.SignedCBORBytes())
c, err := drisl.CidForValue(op)
if err != nil {
// NOTE: consider changing function signature to return err?
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - I wonder what kinds of things internal to CidForValue can actually fail?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should only be objects that fail to marshal as valid DRISL or CBOR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What could cause that though? I'm just wondering if we can prove it will never fail given the structure of our op object

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. It mostly boils down to failing on:

  • big.Int values that are too big/small (exceeds int64)
  • Tags other than tag 42 (CID)
  • Maps with keys that are not strings
  • Some banned floating point values: NaN, Inf, -Inf

From what I can see, your structs should be good to go. Regardless returning the error is a good idea.

Note CidForValue adheres to the default rules of the package, so things like floats are allowed, since they are allowed in DRISL. If you'd like to be even stricter you could write your own tiny implementation of CidForValue that using custom EncOptions instead of just calling Marshal. But it shouldn't matter given your structs look to be all strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants