Skip to content

Commit

Permalink
Pass signature and signable to Verify
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Jul 9, 2024
1 parent ba68bda commit 6186aa3
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 180 deletions.
6 changes: 2 additions & 4 deletions cmd/accumulated/cmd_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ func initNodeFromSeedProxy(cmd *cobra.Command, args []string) (int, *cfg.Config,
return 0, nil, nil, fmt.Errorf("invalid seed list, %v", err)
}

txHash := sha256.Sum256(b)
if !resp.Signature.Verify(nil, txHash[:], nil) {
if !resp.Signature.Verify(nil, protocol.SignableHash(sha256.Sum256(b))) {
return 0, nil, nil, fmt.Errorf("invalid signature from proxy")
}

Expand Down Expand Up @@ -358,8 +357,7 @@ func initNodeFromSeedProxy(cmd *cobra.Command, args []string) (int, *cfg.Config,
return 0, nil, nil, err
}

h := sha256.Sum256(d)
if !nc.Signature.Verify(nil, h[:], nil) {
if !nc.Signature.Verify(nil, protocol.SignableHash(sha256.Sum256(d))) {
return 0, nil, nil, fmt.Errorf("cannot verify network configuration from proxy")
}
_, _, found = kp.EntryByKeyHash(nc.Signature.GetPublicKeyHash())
Expand Down
3 changes: 1 addition & 2 deletions internal/bsn/msg_anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ func (x BlockAnchor) check(batch *ChangeSet, ctx *MessageContext) (*messaging.Bl
return nil, nil, errors.BadRequest.WithFormat("invalid anchor: expected %v, got %v", messaging.MessageTypeBlockSummary, ctx.message.Type())
}

h := msg.Anchor.Hash()
if !msg.Signature.Verify(nil, h[:], nil) {
if !msg.Signature.Verify(nil, msg.Anchor) {
return nil, nil, errors.Unauthenticated.WithFormat("invalid signature")
}

Expand Down
6 changes: 3 additions & 3 deletions internal/core/execute/v1/block/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (x *Executor) processSignature(batch *database.Batch, delivery *chain.Deliv
if err != nil {
return nil, errors.UnknownError.WithFormat("process delegated signature: %w", err)
}
if !md.Nested() && !signature.Verify(signature.Metadata().Hash(), delivery.Transaction.GetHash(), delivery.Transaction) {
if !md.Nested() && !signature.Verify(nil, delivery.Transaction) {
return nil, errors.BadRequest.WithFormat("invalid signature")
}

Expand Down Expand Up @@ -137,7 +137,7 @@ func (x *Executor) processSignature(batch *database.Batch, delivery *chain.Deliv
}

// Basic validation
if !md.Nested() && !signature.Verify(nil, delivery.Transaction.GetHash(), delivery.Transaction) {
if !md.Nested() && !signature.Verify(nil, delivery.Transaction) {
return nil, errors.BadRequest.WithFormat("invalid signature")
}

Expand All @@ -153,7 +153,7 @@ func (x *Executor) processSignature(batch *database.Batch, delivery *chain.Deliv
}

// Basic validation
if !md.Nested() && !signature.Verify(nil, delivery.Transaction.GetHash(), delivery.Transaction) {
if !md.Nested() && !signature.Verify(nil, delivery.Transaction) {
return nil, errors.BadRequest.WithFormat("invalid signature")
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/core/execute/v1/block/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (x *Executor) validateSignature(batch *database.Batch, delivery *chain.Deli
if err != nil {
return nil, errors.UnknownError.WithFormat("validate delegated signature: %w", err)
}
if !md.Nested() && !signature.Verify(signature.Metadata().Hash(), delivery.Transaction.GetHash(), delivery.Transaction) {
if !md.Nested() && !signature.Verify(nil, delivery.Transaction) {
return nil, errors.BadRequest.WithFormat("invalid signature")
}
if !signature.Delegator.LocalTo(md.Location) {
Expand Down Expand Up @@ -273,7 +273,7 @@ func (x *Executor) validateSignature(batch *database.Batch, delivery *chain.Deli
}

// Basic validation
if !md.Nested() && !signature.Verify(nil, delivery.Transaction.GetHash(), delivery.Transaction) {
if !md.Nested() && !signature.Verify(nil, delivery.Transaction) {
return nil, errors.BadRequest.With("invalid")
}

Expand Down
4 changes: 2 additions & 2 deletions internal/core/execute/v2/block/msg_block_anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (x BlockAnchor) checkSignature(ctx *blockAnchorContext) error {
txn := &messaging.TransactionMessage{Transaction: ctx.transaction}
seq := *ctx.sequenced
seq.Message = txn
if hash := seq.Hash(); ctx.blockAnchor.Signature.Verify(nil, hash[:], nil) {
if ctx.blockAnchor.Signature.Verify(nil, &seq) {
return nil
}

Expand All @@ -217,7 +217,7 @@ func (x BlockAnchor) checkSignature(ctx *blockAnchorContext) error {
seq.Destination = protocol.DnUrl()
txn.Transaction = txn.Transaction.Copy()
txn.Transaction.Header.Principal = protocol.DnUrl().JoinPath(ctx.transaction.Header.Principal.Path)
if hash := seq.Hash(); ctx.blockAnchor.Signature.Verify(nil, hash[:], nil) {
if ctx.blockAnchor.Signature.Verify(nil, &seq) {
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/core/execute/v2/block/msg_synthetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (SyntheticMessage) check(batch *database.Batch, ctx *MessageContext) (*mess

// Verify the signature
h := syn.Message.Hash()
if !syn.Signature.Verify(nil, h[:], nil) {
if !syn.Signature.Verify(nil, syn.Message) {
return nil, errors.BadRequest.With("invalid signature")
}

Expand Down
15 changes: 2 additions & 13 deletions internal/core/execute/v2/block/sig_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,11 @@ func init() {
protocol.SignatureTypeETH,
)

// Vandenberg: RSA and ECDSA signatures
// Vandenberg: RSA, ECDSA, and EIP-712 signatures
registerConditionalExec[UserSignature](&signatureExecutors,
func(ctx *SignatureContext) bool { return ctx.GetActiveGlobals().ExecutorVersion.V2VandenbergEnabled() },
protocol.SignatureTypeRsaSha256,
protocol.SignatureTypeEcdsaSha256,
)

// PKI signatures (enabled with Vandenberg)
registerConditionalExec[UserSignature](&signatureExecutors,
func(ctx *SignatureContext) bool { return ctx.GetActiveGlobals().ExecutorVersion.V2VandenbergEnabled() },
protocol.SignatureTypeEcdsaSha256,
)

// Eip712 signatures (enabled with Vandenberg)
registerConditionalExec[UserSignature](&signatureExecutors,
func(ctx *SignatureContext) bool { return ctx.GetActiveGlobals().ExecutorVersion.V2VandenbergEnabled() },
protocol.SignatureTypeEip712TypedData,
)
}
Expand Down Expand Up @@ -123,7 +112,7 @@ func (x UserSignature) check(batch *database.Batch, ctx *userSigContext) error {
}

// Verify the signature signs the transaction
if !verifySignature(sig, ctx.transaction.GetHash(), ctx.transaction) {
if !verifySignature(sig, ctx.transaction) {
return errors.Unauthenticated.WithFormat("invalid signature")
}

Expand Down
5 changes: 2 additions & 3 deletions internal/core/healing/anchors.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ func HealAnchor(ctx context.Context, args HealAnchorArgs, si SequencedInfo) erro
}

// Filter out bad signatures
h := seq.Hash()
if !sig.Verify(nil, h[:], nil) {
if !sig.Verify(nil, seq) {
slog.ErrorContext(ctx, "Node gave us an invalid signature", "id", info)
continue
}
Expand All @@ -209,7 +208,7 @@ func HealAnchor(ctx context.Context, args HealAnchorArgs, si SequencedInfo) erro

case protocol.UserSignature:
// Filter out bad signatures
if !sig.Verify(nil, theAnchorTxn.GetHash(), nil) {
if !sig.Verify(nil, theAnchorTxn) {
slog.ErrorContext(ctx, "Node gave us an invalid signature", "id", info)
continue
}
Expand Down
3 changes: 1 addition & 2 deletions internal/core/healing/synthetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func (h *Healer) HealSynthetic(ctx context.Context, args HealSyntheticArgs, si S
return fmt.Errorf("synthetic message is not signed")
}

hash := msg.Message.Hash()
if !msg.Signature.Verify(nil, hash[:], nil) {
if !msg.Signature.Verify(nil, msg.Message) {
return fmt.Errorf("signature is not valid")
}

Expand Down
Loading

0 comments on commit 6186aa3

Please sign in to comment.