mirror of
https://github.com/luxfi/coreth.git
synced 2026-10-30 17:00:51 +00:00
This module would not build against the warp it resolves. warp v1.24 removed the
UnsignedMessage / Message split, and the rename is a rotation, not a substitution
— every name shifted one place along:
UnsignedMessage -> Message (the signed subject)
NewUnsignedMessage -> NewMessage
ParseUnsignedMessage -> ParseMessage
Message -> Envelope (subject + lanes)
NewMessage -> NewEnvelope
ParseMessage -> ParseEnvelope
VerifyMessage -> VerifyEnvelope
.UnsignedMessage -> .Message
.Signature -> .Beam
Applying it in the obvious order silently conflates the two Message meanings, so
the rewrite goes through placeholders.
The fold is a security fix upstream, not cosmetic: Message now carries the Pulsar
lineage (SourceNebulaRoot, SourceKeyEraID, SourceGeneration, HashSuiteID) inside
the signed subject. Under the old split the BLS Beam signed only the unsigned
body and that lineage was Beam-unauthenticated.
VerifyEnvelope takes the same five arguments VerifyMessage did and is documented
as the canonical classical path, so verification semantics are unchanged here.
VerifyWithOptions is the opt-in door to the Corona and ML-DSA lanes; nothing in
this module opts in, so no PQ policy is decided by this commit.
Two shape changes fall out of Envelope holding concrete lanes:
- Beam is a BitSetSignature value, not an interface, so the signer-count
type-assertion in the gas path is unreachable and its unknown-signature-type
branch is gone. A parsed envelope always has a Beam to count.
- Envelope.Bytes reports c14n failures instead of panicking, so the RPC path
surfaces that error rather than returning a truncated message.
NewEnvelope also takes the Corona and ML-DSA cert-set lanes; the test aggregator
is Beam-only and passes nil for both.
Builds clean, go vet clean, warp + precompile + aggregator suites pass.
Co-authored-by: Hanzo Dev <[email protected]>
79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package warp
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/luxfi/database"
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/p2p"
|
|
"github.com/luxfi/warp"
|
|
"github.com/luxfi/warp/payload"
|
|
)
|
|
|
|
const (
|
|
ParseErrCode = iota + 1
|
|
VerifyErrCode
|
|
)
|
|
|
|
// Verify verifies the signature of the message
|
|
// It also implements the warp.Verifier interface
|
|
func (b *backend) Verify(ctx context.Context, unsignedMessage *warp.Message, _ []byte) error {
|
|
messageID := unsignedMessage.ID()
|
|
// Known on-chain messages should be signed
|
|
if _, err := b.GetMessage(messageID); err == nil {
|
|
return nil
|
|
} else if err != database.ErrNotFound {
|
|
return &p2p.Error{
|
|
Code: ParseErrCode,
|
|
Message: fmt.Sprintf("failed to get message %s: %s", messageID, err.Error()),
|
|
}
|
|
}
|
|
|
|
parsed, err := payload.ParsePayload(unsignedMessage.Payload)
|
|
if err != nil {
|
|
b.stats.IncMessageParseFail()
|
|
return &p2p.Error{
|
|
Code: ParseErrCode,
|
|
Message: "failed to parse payload: " + err.Error(),
|
|
}
|
|
}
|
|
|
|
switch p := parsed.(type) {
|
|
case *payload.Hash:
|
|
return b.verifyBlockMessage(ctx, p)
|
|
default:
|
|
b.stats.IncMessageParseFail()
|
|
return &p2p.Error{
|
|
Code: ParseErrCode,
|
|
Message: fmt.Sprintf("unknown payload type: %T", p),
|
|
}
|
|
}
|
|
}
|
|
|
|
// verifyBlockMessage returns nil if blockHashPayload contains the ID
|
|
// of an accepted block indicating it should be signed by the VM.
|
|
func (b *backend) verifyBlockMessage(ctx context.Context, blockHashPayload *payload.Hash) error {
|
|
blockID, err := ids.ToID(blockHashPayload.Hash)
|
|
if err != nil {
|
|
b.stats.IncBlockValidationFail()
|
|
return &p2p.Error{
|
|
Code: ParseErrCode,
|
|
Message: fmt.Sprintf("failed to parse block ID: %s", err.Error()),
|
|
}
|
|
}
|
|
_, err = b.blockClient.GetAcceptedBlock(ctx, blockID)
|
|
if err != nil {
|
|
b.stats.IncBlockValidationFail()
|
|
return &p2p.Error{
|
|
Code: VerifyErrCode,
|
|
Message: fmt.Sprintf("failed to get block %s: %s", blockID, err.Error()),
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|