Skip to content

Commit ad029cd

Browse files
authored
SubmitTx: prevent multiple OP_RETURN outputs (#654)
* SubmitOffchainTx: prevent multiple opreturn outputs * use bytes.HasPrefix instead of bytes.Contains
1 parent a354d76 commit ad029cd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

internal/core/application/service.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ func (s *service) SubmitOffchainTx(
617617

618618
outputs := make([]*wire.TxOut, 0) // outputs excluding the anchor
619619
foundAnchor := false
620+
foundOpReturn := false
621+
620622
for outIndex, out := range ptx.UnsignedTx.TxOut {
621623
if bytes.Equal(out.PkScript, txutils.ANCHOR_PKSCRIPT) {
622624
if foundAnchor {
@@ -626,6 +628,14 @@ func (s *service) SubmitOffchainTx(
626628
continue
627629
}
628630

631+
// verify we don't have multiple OP_RETURN outputs
632+
if bytes.HasPrefix(out.PkScript, []byte{txscript.OP_RETURN}) {
633+
if foundOpReturn {
634+
return nil, "", "", fmt.Errorf("invalid tx, multiple op return outputs")
635+
}
636+
foundOpReturn = true
637+
}
638+
629639
if s.vtxoMaxAmount >= 0 {
630640
if out.Value > s.vtxoMaxAmount {
631641
return nil, "", "", fmt.Errorf(

0 commit comments

Comments
 (0)