Skip to content

fix(drive-abci): duplicate identity key bypasses pre-validation, returns internal error instead of ConsensusError #3396

Open

Description

@lklimek

User Story

As a Dash Platform user, I want duplicate identity key errors to be caught during validation (returning a proper ConsensusError) rather than during execution (returning a raw internal error), so that my wallet application can display a clear, structured error message.

Problem

validate_unique_identity_public_key_hashes_not_in_state() only checks the unique key hash set via has_any_of_unique_public_key_hashes(). However, the insertion code in insert_unique_public_key_hash_reference_to_identity_operations_v0() checks both unique AND non-unique sets before inserting.

This asymmetry creates a bypass:

  1. Identity with key K is registered → K goes into the non-unique set
  2. Another identity tries to register with the same key K
  3. Pre-validation checks unique set only → K not there → validation passes ✅
  4. Insertion checks non-unique set → K exists → execution fails 💥
  5. Error surfaces as StateTransitionExecutionResult::InternalError(string) instead of a ConsensusError

The SDK client receives a gRPC Internal error with a raw string message instead of a structured ConsensusError::BasicError(DuplicatedIdentityPublicKeyIdBasicError).

Suggested Fix

In packages/rs-drive-abci/src/execution/validation/state_transition/common/validate_unique_identity_public_key_hashes_in_state/v0/mod.rs, extend the validation to also call has_any_of_non_unique_public_key_hashes() (or equivalent) and return a DuplicatedIdentityPublicKeyIdBasicError if the key exists in either set.

Files

File Current behavior
.../validate_unique_identity_public_key_hashes_in_state/v0/mod.rs Only checks unique set
.../insert_unique_public_key_hash_reference_to_identity/v0/mod.rs Checks both unique + non-unique

Related

🤖 Co-authored by Claudius the Magnificent AI Agent

Activity

  1. added
    bug
    on Mar 20, 2026
  2. changed the title [-]fix(drive-abci): pre-validation should check non-unique key hash set for duplicates[/-] [+]fix(drive-abci): duplicate identity key bypasses pre-validation, returns internal error instead of ConsensusError[/+] on Mar 20, 2026
  3. self-assigned this
    on Apr 13, 2026
  4. lklimek commented on Apr 13, 2026

    @lklimek
    ContributorAuthor

    Reproduce with more precise reproduction scenario (actual data).

  5. lklimek commented on Apr 13, 2026

    @lklimek
    ContributorAuthor

    Detailed Reproduction Scenario & Test Vectors

    Extracted from the original discovery session (DET session 37f94bec, 2026-03-20).

    Reproduction Steps

    1. Start a local devnet (dashmate) or connect to testnet
    2. Register Identity A with public key K — K goes into the non-unique key hash set in GroveDB
    3. Attempt to register Identity B using the same public key K
    4. Pre-validation (validate_unique_identity_public_key_hashes_not_in_state) checks only the unique set → K not found → validation passes ✅
    5. Insertion (insert_unique_public_key_hash_reference_to_identity_operations_v0) checks both unique AND non-unique sets → finds K → execution fails 💥
    6. Error hits .to_string() at process_raw_state_transitions/v0/mod.rs:502, destroying type information
    7. SDK client receives gRPC Internal (code 13) with base64-encoded CBOR instead of a structured ConsensusError

    Test Vectors

    Duplicate public key hash ([u8; 20]):

    [70, 101, 149, 157, 72, 129, 155, 242, 168, 48, 11, 145, 180, 252, 122, 134, 152, 55, 135, 242]
    

    Hex: 46659d48819bf2a8300b91b4fc7a86983887f2

    Raw gRPC error received by SDK:

    Status {
      code: Internal,
      message: "oWdtZXNzYWdleMtzdG9yYWdlOiBpZGVudGl0eTogYSB1bmlxdWUga2V5IHdpdGgg
                dGhhdCBoYXNoIGFscmVhZHkgZXhpc3RzOiB0aGUga2V5IGFscmVhZHkgZXhpc3Rz
                IGluIHRoZSBub24gdW5pcXVlIHNldCBbNzAsIDEwMSwgMTQ5LCAxNTcsIDcyLCAx
                MjksIDE1NSwgMjQyLCAxNjgsIDQ4LCAxMSwgMTQ1LCAxODAsIDI1MiwgMTIyLCAx
                MzQsIDE1MiwgNTUsIDEzNSwgMjQyXQ==",
      metadata: MetadataMap { headers: {
        "drive-error-data-bin": "o2Rjb2RlDWdtZXNzYWdl...b2NvbnNlbnN1c19lcnJvcvY",
        "code": "13"
      }}
    }
    

    Decoded drive-error-data-bin metadata (CBOR → JSON):

    {
      "code": 13,
      "message": "<base64 of CBOR containing the error text below>",
      "consensus_error": null
    }

    ⚠️ consensus_error: null is the smoking gun — Drive never created a ConsensusError, so the SDK cannot decode a structured error.

    Decoded human-readable message:

    storage: identity: a unique key with that hash already exists:
    the key already exists in the non unique set
    [70, 101, 149, 157, 72, 129, 155, 242, 168, 48, 11, 145, 180, 252, 122, 134, 152, 55, 135, 242]
    

    Validation Asymmetry (Root Cause)

    Check Unique set Non-unique set
    Pre-validation (validate_unique_identity_public_key_hashes_not_in_state) ✅ Checked ❌ Not checked
    Insertion (insert_unique_public_key_hash_reference_to_identity) ✅ Checked ✅ Checked

    Error Propagation Chain

    IdentityError::UniqueKeyAlreadyExists(String)
      → #[from] conversions up to drive_abci::Error::Drive(DriveError)
      → .to_string() at process_raw_state_transitions/v0/mod.rs:502  ← type info destroyed here
      → StateTransitionExecutionResult::InternalError(error_string)
      → gRPC Internal (code 13) with drive-error-data-bin metadata
      → SDK: DriveInternalError(String) instead of ConsensusError
    

    Key Files

    File Role
    .../validate_unique_identity_public_key_hashes_in_state/v0/mod.rs Pre-validation — only calls has_any_of_unique_public_key_hashes()
    .../insert_unique_public_key_hash_reference_to_identity/v0/mod.rs Insertion — checks both unique AND non-unique sets
    .../process_raw_state_transitions/v0/mod.rs:502 Where .to_string() destroys type information
    .../fetch_by_public_key_hashes/has_any_of_unique_public_key_hashes/v0/mod.rs Only queries unique_key_hashes_tree_path

    🤖 Co-authored by Claudius the Magnificent AI Agent

  6. lklimek commented on Apr 13, 2026

    @lklimek
    ContributorAuthor

    Key from identity A

    Image

    Adding to identity B

    Image

    Drive log

    {"timestamp":"2026-04-13T11:00:54.927655Z","level":"ERROR","fields":{"message":"Failed to check state transition (1c5018c9a005b8871c6bdc8b52b19dba7d347eb6739584f1b11ae9b76631a064): storage: identity: a unique key with that hash already exists: the key already exists in the unique set [66, 48, 159, 17, 2, 114, 204, 66, 154, 152, 194, 178, 215, 139, 234, 175, 223, 242, 59, 158]","error":"Drive(Identity(UniqueKeyAlreadyExists(\"the key already exists in the unique set [66, 48, 159, 17, 2, 114, 204, 66, 154, 152, 194, 178, 215, 139, 234, 175, 223, 242, 59, 158]\")))","st":"06005e25e52ff14747bf5b0ff61e8ca23b20438071db76bac167a5fe076685e450a1010101000600000200002102eb44fbf9bf50f9872afdf07399b2980fe3060af367cd13396b7baa02cbe3be1641205074572f4d138d29f9b8b3b03b94c080464ec05a7c5986185f5654d063914f946e789d4f5843f49e691ac9c64f531e9ba3f0892ddcc9750a937186803bd52d01000000411f0874fc8d0eabd17412997b0524410074e3ec6178d9923c6f6ba55df187317b0369f79a1b1644a330298c6ed0f5f3b6b327bd124f6218edb3149a9eccd3d69d63","st_hash":"1c5018c9a005b8871c6bdc8b52b19dba7d347eb6739584f1b11ae9b76631a064","check_tx_mode":0},"target":"drive_abci::abci::handler::check_tx","threadName":"tokio-runtime-worker","threadId":"ThreadId(10348)"}
    

    DET log

    2026-04-13T11:00:55.021505Z DEBUG request routine: rs_dapi_client::dapi_client: received error: grpc error: code: 'Internal error', message: "oWdtZXNzYWdleMVzdG9yYWdlOiBpZGVudGl0eTogYSB1bmlxdWUga2V5IHdpdGggdGhhdCBoYXNoIGFscmVhZHkgZXhpc3RzOiB0aGUga2V5IGFscmVhZHkgZXhpc3RzIGluIHRoZSB1bmlxdWUgc2V0IFs2NiwgNDgsIDE1OSwgMTcsIDIsIDExNCwgMjA0LCA2NiwgMTU0LCAxNTIsIDE5NCwgMTc4LCAyMTUsIDEzOSwgMjM0LCAxNzUsIDIyMywgMjQyLCA1OSwgMTU4XQ==" error=Grpc(Status { code: Internal, message: "oWdtZXNzYWdleMVzdG9yYWdlOiBpZGVudGl0eTogYSB1bmlxdWUga2V5IHdpdGggdGhhdCBoYXNoIGFscmVhZHkgZXhpc3RzOiB0aGUga2V5IGFscmVhZHkgZXhpc3RzIGluIHRoZSB1bmlxdWUgc2V0IFs2NiwgNDgsIDE1OSwgMTcsIDIsIDExNCwgMjA0LCA2NiwgMTU0LCAxNTIsIDE5NCwgMTc4LCAyMTUsIDEzOSwgMjM0LCAxNzUsIDIyMywgMjQyLCA1OSwgMTU4XQ==", metadata: MetadataMap { headers: {"content-type": "application/grpc", "drive-error-data-bin": "o2Rjb2RlDWdtZXNzYWdleQEYb1dkdFpYTnpZV2RsZU1WemRHOXlZV2RsT2lCcFpHVnVkR2wwZVRvZ1lTQjFibWx4ZFdVZ2EyVjVJSGRwZEdnZ2RHaGhkQ0JvWVhOb0lHRnNjbVZoWkhrZ1pYaHBjM1J6T2lCMGFHVWdhMlY1SUdGc2NtVmhaSGtnWlhocGMzUnpJR2x1SUhSb1pTQjFibWx4ZFdVZ2MyVjBJRnMyTml3Z05EZ3NJREUxT1N3Z01UY3NJRElzSURFeE5Dd2dNakEwTENBMk5pd2dNVFUwTENBeE5USXNJREU1TkN3Z01UYzRMQ0F5TVRVc0lERXpPU3dnTWpNMExDQXhOelVzSURJeU15d2dNalF5TENBMU9Td2dNVFU0WFE9PW9jb25zZW5zdXNfZXJyb3L2", "code": "13", "server": "envoy", "x-envoy-upstream-service-time": "8", "date": "Mon, 13 Apr 2026 11:00:54 GMT"} }, source: None })
    
  7. removed their assignment
    on Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions