-
Notifications
You must be signed in to change notification settings - Fork 124
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
[crypto]: add bls #675
[crypto]: add bls #675
Conversation
Related: #613 |
examples/morpheusvm/auth/bls.go
Outdated
var d BLS | ||
|
||
signer := bls.SerializePublicKey(&d.Signer) | ||
p.UnpackFixedBytes(bls.PublicKeyLen*2, &signer) |
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.
why is this *2?
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.
bls.PublicKeyLen
is defined to be BLST_P1_COMPRESS_BYTES
which is 48 bytes. When we serialize the public key this has a length of BLST_P1_SERIALIZE_BYTES
which is twice of PublicKeyLen
.
When just unpacking the bytes after the first 48 are all 0-filled. This led to an invalid signature
error when calling AsyncVerify
.
I'll also make a note of this in the code
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.
I think we should make a new const of the actual bytes it take to serialize (that's the value we care about)...we need to align BLSSize
with the actual marshal/unmarshal size or else it won't be big enough.
You are packing bls.PublicKeyLen + bls.SignatureLen
but unpacking bls.PublicKeyLen*2 + bls.SignatureLen
examples/morpheusvm/auth/bls.go
Outdated
) | ||
|
||
type BLS struct { | ||
Signer bls.PublicKey `json:"signer"` |
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.
If the AvalancheGo/our library operates over pointers, I would recommend using them here instead of dereferencing things.
examples/morpheusvm/auth/bls.go
Outdated
func UnmarshalBLS(p *codec.Packer, _ *warp.Message) (chain.Auth, error) { | ||
var d BLS | ||
|
||
signer := bls.SerializePublicKey(&d.Signer) |
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.
You can just create a byte array of the size you are expecting and pass that into Deserialize*
instead of doing this (which is going to be much less efficient because it will try to create a compressed version of empty bytes that we then just rewrite later)
examples/morpheusvm/auth/bls.go
Outdated
@@ -148,22 +148,22 @@ func (d *BLS) Refund( | |||
var _ chain.AuthFactory = (*BLSFactory)(nil) | |||
|
|||
type BLSFactory struct { | |||
priv bls.PrivateKey | |||
priv *bls.PrivateKey `json:"priv,omitempty"` |
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.
private fields aren't marshaled in json
, so I think this is unnecessary?
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.
Nice work!
Closes #676 and #677
Add support for BLS by using the BLS library that exists in AvalancheGo. This would let developers integrate BLS, if they choose to, into their VM.
Overview:
crypto
packageTest Plan:
go test
withinbls
package./scripts/tests.integration.sh
withinexamples/morpheusvm
./scripts/build.sh
Future TODOs:
avalanchego/utils/crypto
throughout the repo with this internal package