-
Notifications
You must be signed in to change notification settings - Fork 66
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
Conversation
There was a problem hiding this 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.
if _, err := fillSuffixTreePoly(c1poly[:], values[:NodeWidth/2]); err != nil { | ||
panic(err) | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
tree.go
Outdated
err := leafToComms(old[:], n.values[index]) | ||
if err != nil { | ||
return err | ||
} | ||
err = leafToComms(newH[:], value) | ||
if err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
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
err := leafToComms(poly[(idx<<1)&0xFF:], val) | ||
if err != nil { |
There was a problem hiding this comment.
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:]) |
There was a problem hiding this comment.
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
err := StemFromBytes(&poly[1], n.stem) | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: inline err-if?
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") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool :)
Co-authored-by: Ignacio Hagopian <[email protected]>
Signed-off-by: Ignacio Hagopian <[email protected]>
This is part (but not all) of the fix for #351, stopping here because the diff is already quite large.