Skip to content

Duplicate signatures added to _signature_map due to missing deduplication check #2208

Description

@mohityadav8

Description

Currently, when adding signature pairs to self._signature_map, duplicate entries can be inserted for the same body_bytes and pubKeyPrefix.

This happens because the code directly appends sigPair without verifying whether a signature from the same public key already exists.

Expected behavior:
Each (body_bytes, pubKeyPrefix) combination should have only one corresponding SignaturePair.

Actual behavior:
Duplicate signatures are appended, leading to redundant entries and potential inconsistencies.

Steps to reproduce

  1. Create a transaction and sign it multiple times using the same private key
  2. Inspect self._signature_map[body_bytes].sigPair
  3. Observe duplicate SignaturePair entries with the same pubKeyPrefix

Additional context

  • This issue can lead to unnecessary payload size increase
  • May cause inefficiencies or unexpected behavior in downstream processing

Proposed Fix

Add a deduplication check before appending:

self._signature_map.setdefault(body_bytes, basic_types_pb2.SignatureMap())

already_signed = any(
    sp.pubKeyPrefix == public_key_bytes
    for sp in self._signature_map[body_bytes].sigPair
)

if not already_signed:
    self._signature_map[body_bytes].sigPair.append(sig_pair)

Hedera network

No response

Version

v0.2.5

Operating system

Windows

Metadata

Metadata

Assignees

Labels

skill: beginnerAchievable by a fairly new comer that has already completed a couple of good first issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions