Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3019,6 +3019,7 @@ func (bc *Blockchain) CalculateAttributesFee(tx *transaction.Transaction) int64
}

func (bc *Blockchain) verifyTxAttributes(d *dao.Simple, tx *transaction.Transaction, isPartialTx bool) error {
var conflictsAttrs []transaction.Attribute
for i := range tx.Attributes {
switch attrType := tx.Attributes[i].Type; attrType {
case transaction.HighPriority:
Expand Down Expand Up @@ -3078,6 +3079,18 @@ func (bc *Blockchain) verifyTxAttributes(d *dao.Simple, tx *transaction.Transact
}
case transaction.ConflictsT:
conflicts := tx.Attributes[i].Value.(*transaction.Conflicts)
if conflictsAttrs == nil {
conflictsAttrs = tx.GetAttributes(transaction.ConflictsT)
}
var dup bool
for _, c := range conflictsAttrs {
if c.Value.(*transaction.Conflicts).Hash.Equals(conflicts.Hash) {
if dup {
return fmt.Errorf("%w: duplicate Conflicts attribute %s", ErrInvalidAttribute, conflicts.Hash.StringLE())
}
dup = true
}
}
// Only fully-qualified dao.ErrAlreadyExists error bothers us here, thus, we
// can safely omit the signers, current index and MTB arguments to HasTransaction call to improve performance a bit.
if err := bc.dao.HasTransaction(conflicts.Hash, nil, 0, 0); errors.Is(err, dao.ErrAlreadyExists) {
Expand Down
8 changes: 8 additions & 0 deletions pkg/core/blockchain_neotest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,14 @@ func TestBlockchain_VerifyTx(t *testing.T) {
require.NoError(t, err)
})
t.Run("enabled", func(t *testing.T) {
t.Run("duplicate", func(t *testing.T) {
conflict := random.Uint256()
tx := getConflictsTx(e, conflict, conflict)

err := bc.VerifyTx(tx)
require.ErrorIs(t, err, core.ErrInvalidAttribute)
require.ErrorContains(t, err, fmt.Sprintf("duplicate Conflicts attribute %s", conflict.StringLE()))
})
t.Run("dummy on-chain conflict", func(t *testing.T) {
t.Run("on-chain conflict signed by malicious party", func(t *testing.T) {
tx := newTestTx(t, h, testScript)
Expand Down
Loading