node/pkg/vaa: remove error return value from SigningMsg
serializeBody always returns a nil error. Remove the error return value. commit-id:5e150f69
This commit is contained in:
parent
5fad3baa9f
commit
8546ee6e14
|
@ -179,7 +179,7 @@ func (s *nodePrivilegedService) InjectGovernanceVAA(ctx context.Context, req *no
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate digest of the unsigned VAA.
|
// Generate digest of the unsigned VAA.
|
||||||
digest, err := v.SigningMsg()
|
digest := v.SigningMsg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ func runGovernanceVAAVerify(cmd *cobra.Command, args []string) {
|
||||||
log.Fatalf("invalid update: %v", err)
|
log.Fatalf("invalid update: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
digest, err := v.SigningMsg()
|
digest := v.SigningMsg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *Processor) broadcastSignature(v *vaa.VAA, signature []byte, txhash []byte) {
|
func (p *Processor) broadcastSignature(v *vaa.VAA, signature []byte, txhash []byte) {
|
||||||
digest, err := v.SigningMsg()
|
digest := v.SigningMsg()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
obsv := gossipv1.SignedObservation{
|
obsv := gossipv1.SignedObservation{
|
||||||
Addr: crypto.PubkeyToAddress(p.gk.PublicKey).Bytes(),
|
Addr: crypto.PubkeyToAddress(p.gk.PublicKey).Bytes(),
|
||||||
|
|
|
@ -24,10 +24,7 @@ var (
|
||||||
// handleInjection processes a pre-populated VAA injected locally.
|
// handleInjection processes a pre-populated VAA injected locally.
|
||||||
func (p *Processor) handleInjection(ctx context.Context, v *vaa.VAA) {
|
func (p *Processor) handleInjection(ctx context.Context, v *vaa.VAA) {
|
||||||
// Generate digest of the unsigned VAA.
|
// Generate digest of the unsigned VAA.
|
||||||
digest, err := v.SigningMsg()
|
digest := v.SigningMsg()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The internal originator is responsible for logging the full VAA, just log the digest here.
|
// The internal originator is responsible for logging the full VAA, just log the digest here.
|
||||||
supervisor.Logger(ctx).Info("signing injected VAA",
|
supervisor.Logger(ctx).Info("signing injected VAA",
|
||||||
|
|
|
@ -118,10 +118,7 @@ func (p *Processor) handleMessage(ctx context.Context, k *common.MessagePublicat
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate digest of the unsigned VAA.
|
// Generate digest of the unsigned VAA.
|
||||||
digest, err := v.SigningMsg()
|
digest := v.SigningMsg()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sign the digest using our node's guardian key.
|
// Sign the digest using our node's guardian key.
|
||||||
s, err := crypto.Sign(digest.Bytes(), p.gk)
|
s, err := crypto.Sign(digest.Bytes(), p.gk)
|
||||||
|
|
|
@ -258,7 +258,7 @@ func (p *Processor) handleInboundSignedVAAWithQuorum(ctx context.Context, m *gos
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate digest for logging
|
// Calculate digest for logging
|
||||||
digest, err := v.SigningMsg()
|
digest := v.SigningMsg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,22 +228,16 @@ func Unmarshal(data []byte) (*VAA, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// signingBody returns the binary representation of the data that is relevant for signing and verifying the VAA
|
// signingBody returns the binary representation of the data that is relevant for signing and verifying the VAA
|
||||||
func (v *VAA) signingBody() ([]byte, error) {
|
func (v *VAA) signingBody() []byte {
|
||||||
return v.serializeBody()
|
return v.serializeBody()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SigningMsg returns the hash of the signing body. This is used for signature generation and verification
|
// SigningMsg returns the hash of the signing body. This is used for signature generation and verification
|
||||||
func (v *VAA) SigningMsg() (common.Hash, error) {
|
func (v *VAA) SigningMsg() common.Hash {
|
||||||
body, err := v.signingBody()
|
|
||||||
if err != nil {
|
|
||||||
// Should never happen on a successfully parsed VAA
|
|
||||||
return common.Hash{}, fmt.Errorf("failed to serialize signing body: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// In order to save space in the solana signature verification instruction, we hash twice so we only need to pass in
|
// In order to save space in the solana signature verification instruction, we hash twice so we only need to pass in
|
||||||
// the first hash (32 bytes) vs the full body data.
|
// the first hash (32 bytes) vs the full body data.
|
||||||
hash := crypto.Keccak256Hash(crypto.Keccak256Hash(body).Bytes())
|
hash := crypto.Keccak256Hash(crypto.Keccak256Hash(v.signingBody()).Bytes())
|
||||||
return hash, nil
|
return hash
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerifySignatures verifies the signature of the VAA given the signer addresses.
|
// VerifySignatures verifies the signature of the VAA given the signer addresses.
|
||||||
|
@ -253,10 +247,7 @@ func (v *VAA) VerifySignatures(addresses []common.Address) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
h, err := v.SigningMsg()
|
h := v.SigningMsg()
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, sig := range v.Signatures {
|
for _, sig := range v.Signatures {
|
||||||
if int(sig.Index) >= len(addresses) {
|
if int(sig.Index) >= len(addresses) {
|
||||||
|
@ -291,11 +282,7 @@ func (v *VAA) Marshal() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write Body
|
// Write Body
|
||||||
body, err := v.serializeBody()
|
buf.Write(v.serializeBody())
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to serialize body: %w", err)
|
|
||||||
}
|
|
||||||
buf.Write(body)
|
|
||||||
|
|
||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
@ -307,14 +294,10 @@ func (v *VAA) MessageID() string {
|
||||||
|
|
||||||
// HexDigest returns the hex-encoded digest.
|
// HexDigest returns the hex-encoded digest.
|
||||||
func (v *VAA) HexDigest() string {
|
func (v *VAA) HexDigest() string {
|
||||||
b, err := v.SigningMsg()
|
return hex.EncodeToString(v.SigningMsg().Bytes())
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return hex.EncodeToString(b.Bytes())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *VAA) serializeBody() ([]byte, error) {
|
func (v *VAA) serializeBody() []byte {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
MustWrite(buf, binary.BigEndian, uint32(v.Timestamp.Unix()))
|
MustWrite(buf, binary.BigEndian, uint32(v.Timestamp.Unix()))
|
||||||
MustWrite(buf, binary.BigEndian, v.Nonce)
|
MustWrite(buf, binary.BigEndian, v.Nonce)
|
||||||
|
@ -324,15 +307,11 @@ func (v *VAA) serializeBody() ([]byte, error) {
|
||||||
MustWrite(buf, binary.BigEndian, v.ConsistencyLevel)
|
MustWrite(buf, binary.BigEndian, v.ConsistencyLevel)
|
||||||
buf.Write(v.Payload)
|
buf.Write(v.Payload)
|
||||||
|
|
||||||
return buf.Bytes(), nil
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *VAA) AddSignature(key *ecdsa.PrivateKey, index uint8) {
|
func (v *VAA) AddSignature(key *ecdsa.PrivateKey, index uint8) {
|
||||||
data, err := v.SigningMsg()
|
sig, err := crypto.Sign(v.SigningMsg().Bytes(), key)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
sig, err := crypto.Sign(data.Bytes(), key)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,7 @@ func TestVerifySignature(t *testing.T) {
|
||||||
Payload: []byte("abcd"),
|
Payload: []byte("abcd"),
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := v.SigningMsg()
|
data := v.SigningMsg()
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
key, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader)
|
key, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
Loading…
Reference in New Issue