Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove panics in StemFromBytes and FromLEBytes #366

Merged
merged 4 commits into from
Jun 29, 2023

Conversation

gballet
Copy link
Member

@gballet gballet commented Jun 16, 2023

This is part (but not all) of the fix for #351, stopping here because the diff is already quite large.

@gballet gballet requested a review from jsign June 16, 2023 10:56
Copy link
Collaborator

@jsign jsign left a comment

Choose a reason for hiding this comment

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

LGTM, left some comments for your consideration since I think we require some nit extra changes.

Comment on lines +88 to +90
if _, err := fillSuffixTreePoly(c1poly[:], values[:NodeWidth/2]); err != nil {
panic(err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Asking just in case: deferring GetConfig() to return an error?

Copy link
Member Author

Choose a reason for hiding this comment

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

nah, because if you get an error at this stage, there's no point in continuing (and also it would make a huge diff as it's called everywhere)

conversion.go Outdated
var wg sync.WaitGroup
var (
wg sync.WaitGroup
err error
Copy link
Collaborator

@jsign jsign Jun 16, 2023

Choose a reason for hiding this comment

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

This err is accessed by parallel goroutines so it will be a race condition.

I've created a fix for this using errgroup in this PR, you might want to take a look. It's targeting this PR.

Edit: I see that test failed for this reason.

conversion.go Outdated Show resolved Hide resolved
tree.go Outdated
Comment on lines 1027 to 1034
err := leafToComms(old[:], n.values[index])
if err != nil {
return err
}
err = leafToComms(newH[:], value)
if err != nil {
return err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: maybe if err := ...; err != nil { ?

tree.go Outdated
Comment on lines 1270 to 1271
err := leafToComms(poly[(idx<<1)&0xFF:], val)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: same as prev comm.

tree.go Outdated
if len(val) >= 16 {
FromLEBytes(&poly[1], val[16:])
err = FromLEBytes(&poly[1], val[16:])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: despite this is correct, my paranoid side forces me to warn about: "if tomorrow somebody adds some extra code between lines 1301 and 1303, this can become a bug".

So maybe simply do:

  ...
  if err := FromLEBytes(..., ...); err != nil { 
      return fmt.Errorf("converting to bytes: %s", err)
  }

   return nil
}

tree.go Outdated
Comment on lines 1324 to 1325
err := StemFromBytes(&poly[1], n.stem)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: inline err-if?

Comment on lines -861 to +866
if r := recover(); r == nil {
t.Fatal("didn't catch length error")
}
}()
var value [33]byte
leafToComms([]Fr{}, value[:])
err := leafToComms([]Fr{}, value[:])
if err == nil {
t.Fatal("didn't catch length error")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool :)

@gballet gballet merged commit 0974bf3 into master Jun 29, 2023
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.

2 participants