Skip to content

decodeVerKeyDSIGN: wrong length, expected 32 bytes but got 0 #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
robinboening opened this issue Oct 28, 2022 · 10 comments
Closed

decodeVerKeyDSIGN: wrong length, expected 32 bytes but got 0 #113

robinboening opened this issue Oct 28, 2022 · 10 comments
Labels
bug Something isn't working

Comments

@robinboening
Copy link

robinboening commented Oct 28, 2022

I am trying to make a simple transaction (lovelace only) using generated payment keys.

CHAIN_CONTEXT = BlockFrostChainContext(
  project_id=BLOCKFROST_PROJECT_ID,
  network=Network.TESTNET,
  base_url="https://cardano-preprod.blockfrost.io/api",
)

payment_key_pair = PaymentKeyPair.generate()
payment_signing_key = payment_key_pair.signing_key
payment_verification_key = payment_key_pair.verification_key

stake_key_pair = StakeKeyPair.generate()
stake_signing_key = stake_key_pair.signing_key
stake_verification_key = stake_key_pair.verification_key

address = Address(payment_part=payment_verification_key.hash(),
                         staking_part=stake_verification_key.hash(),
                         network=Network.TESTNET)

toAddress = "..."
...
builder = TransactionBuilder(CHAIN_CONTEXT)
builder.add_input_address(address)
builder.add_output(TransactionOutput.from_primitive([toAddress, 10000000]))
builder.build_and_sign([payment_signing_key], change_address=address)

The tx can be built, but submitting it to Blockfrost throws this error

blockfrost.utils.ApiError: {'error': 'Bad Request', 'message': '"transaction read error RawCborDecodeError [DecoderErrorDeserialiseFailure \\"Byron Tx\\" (DeserialiseFailure 1 \\"Size mismatch when decoding TxAux.\\\\nExpected 2, but found 4.\\"),DecoderErrorDeserialiseFailure \\"Shelley Tx\\" (DeserialiseFailure 1 \\"Size mismatch when decoding \\\\nRecord RecD.\\\\nExpected 4, but found 3.\\"),DecoderErrorDeserialiseFailure \\"Shelley Tx\\" (DeserialiseFailure 1 \\"Size mismatch when decoding \\\\nRecord RecD.\\\\nExpected 4, but found 3.\\"),DecoderErrorDeserialiseFailure \\"Shelley Tx\\" (DeserialiseFailure 1 \\"Size mismatch when decoding \\\\nRecord RecD.\\\\nExpected 4, but found 3.\\"),DecoderErrorDeserialiseFailure \\"Shelley Tx\\" (DeserialiseFailure 193 \\"decodeVerKeyDSIGN: wrong length, expected 32 bytes but got 0\\"),DecoderErrorDeserialiseFailure \\"Shelley Tx\\" (Deseria', 'status_code': 400}

I can see it hast to do with the verification key and I bet I am doing something wrong. Any idea what it is? 🙇

@cffls
Copy link
Collaborator

cffls commented Oct 29, 2022

Hi Robin, the code looks correct to me. Could you provide the CBOR, which can help debugging? It will be great if you can also provide the code that submits the transaction cbor.

@robinboening
Copy link
Author

Hey Jerry,

the cbor looks like this

84a400818258207c806478ff2de0c970523870cd57f508c0634c0dd0005ef835c16ef7a9c8001800018282583900b5b7e62899719388be48d412e1384311a68e44a01633d5185b203a643a746b909de8d2e7747ccb76125b25d98d198b9950f39fd70eb335611b0000000253bf98c082583900b56bb1f70feb383207c926af89ede6934f2faca85037f3d982801e5a4b1ab3fccc016ccdebd20006fe167d4e40bd1a12f934fdc4dd7574571a0049b9c3021a0002917d031a00acb03ca100818240584056be2bf9c7c3a6f8d429bfe31febb794b6ec4ccd64139dc179f15688330105c4cb8bb886da54f3fff3b7e342d856b688396c597d226ed6ff5d2a553ecb029408f5f6

and the submission is simple as this

tx = builder.build_and_sign([payment_signing_key], change_address=address)
CHAIN_CONTEXT.submit_tx(tx.to_cbor())

@cffls
Copy link
Collaborator

cffls commented Oct 29, 2022

Thanks, this is very helpful. What I found is that the verification key in the witness of cbor is empty.

echo 84a400818258207c806478ff2de0c970523870cd57f508c0634c0dd0005ef835c16ef7a9c8001800018282583900b5b7e62899719388be48d412e1384311a68e44a01633d5185b203a643a746b909de8d2e7747ccb76125b25d98d198b9950f39fd70eb335611b0000000253bf98c082583900b56bb1f70feb383207c926af89ede6934f2faca85037f3d982801e5a4b1ab3fccc016ccdebd20006fe167d4e40bd1a12f934fdc4dd7574571a0049b9c3021a0002917d031a00acb03ca100818240584056be2bf9c7c3a6f8d429bfe31febb794b6ec4ccd64139dc179f15688330105c4cb8bb886da54f3fff3b7e342d856b688396c597d226ed6ff5d2a553ecb029408f5f6 | xxd -r -p | base64 | python3 -m cbor2.tool -d | jq
[
  {
    "0": [
      [
        "|\\x80dx\\xff-\\xe0\\xc9pR8p\\xcdW\\xf5\b\\xc0cL\r\\xd0\u0000^\\xf85\\xc1n\\xf7\\xa9\\xc8\u0000\u0018",
        0
      ]
    ],
    "1": [
      [
        "\u0000\\xb5\\xb7\\xe6(\\x99q\\x93\\x88\\xbeH\\xd4\u0012\\xe18C\u0011\\xa6\\x8eD\\xa0\u00163\\xd5\u0018[ :d:tk\\x90\\x9d\\xe8\\xd2\\xe7t|\\xcbv\u0012[%ٍ\u0019\\x8b\\x99P\\xf3\\x9f\\xd7\u000e\\xb35a",
        9995000000
      ],
      [
        "\u0000\\xb5k\\xb1\\xf7\u000f\\xeb82\u0007\\xc9&\\xaf\\x89\\xed\\xe6\\x93O/\\xac\\xa8P7\\xf3ق\\x80\u001eZK\u001a\\xb3\\xfc\\xcc\u0001l\\xcd\\xeb\\xd2\u0000\u0006\\xfe\u0016}N@\\xbd\u001a\u0012\\xf94\\xfd\\xc4\\xddutW",
        4831683
      ]
    ],
    "2": 168317,
    "3": 11317308
  },
  {
    "0": [
      [
        "",    <-------- This is the problem
        "V\\xbe+\\xf9\\xc7æ\\xf8\\xd4)\\xbf\\xe3\u001f뷔\\xb6\\xecL\\xcdd\u0013\\x9d\\xc1y\\xf1V\\x883\u0001\u0005\\xc4ˋ\\xb8\\x86\\xdaT\\xf3\\xff\\xf3\\xb7\\xe3B\\xd8V\\xb6\\x889lY}\"n\\xd6\\xff]*U>\\xcb\u0002\\x94\b"
      ]
    ]
  },
  true,
  null
]

The verification key was created and added to witness set by this line, which calls to_verification_key that yielded an empty vkey. Could you call to_verification_key from signing key directly and check if it is empty?

@robinboening
Copy link
Author

robinboening commented Oct 29, 2022

Calling to_verification_key on the signing_key returns a proper key

{"type": "PaymentVerificationKeyShelley_ed25519", "description": "PaymentVerificationKeyShelley_ed25519", "cborHex": "5820ae60924a2a814453c0fc57a9a3e685643ed5a6f5af227298cb5105a12f25092e"}

@robinboening
Copy link
Author

I tried using v0.6.3 and 0.7.0 by the way

@cffls
Copy link
Collaborator

cffls commented Oct 29, 2022

Thanks Robin. Could you try constructing the signed transaction manually like this and share the output? This will help us understand which step went wrong.

...
tx_body = builder.build(change_address=address)
signature = payment_signing_key.sign(tx_body.hash())
vk = payment_signing_key.to_verification_key()
print(vk)
vk_witnesses = [VerificationKeyWitness(vk, signature)]
print(vk_witnesses)
tx = Transaction(tx_body, TransactionWitnessSet(vkey_witnesses=vk_witnesses))
print(tx)
tx_cbor = tx.to_cbor()
print(tx_cbor)

@robinboening
Copy link
Author

Thanks for your support Jerry!

This is the entire printed output.

{"type": "PaymentVerificationKeyShelley_ed25519", "description": "PaymentVerificationKeyShelley_ed25519", "cborHex": "5820ae60924a2a814453c0fc57a9a3e685643ed5a6f5af227298cb5105a12f25092e"}
[{
  'signature': b'\xfbwE\xfd\xa1Y\xf2YUN\xd3)\x1d\xfd\x80\xdaA\xbf\x8aY\x9d\xbdG\x8eml\xc1\x06;\xc8N\xfb\x88\x17L\xf3\xb2\xe6\xa0\x11\xbb>\x84\x99\x92\xc7\xa9r\xa6\x03\x03W~\n\xa5q\xb6*l\xc8\x01.v\r',
  'vkey': {"type": "PaymentVerificationKeyShelley_ed25519", "description": "PaymentVerificationKeyShelley_ed25519", "cborHex": "5820ae60924a2a814453c0fc57a9a3e685643ed5a6f5af227298cb5105a12f25092e"},
}]
{
  'auxiliary_data': None,
  'transaction_body': {
    'auxiliary_data_hash': None,
    'certificates': None,
    'collateral': None,
    'collateral_return': None,
    'fee': 168317,
    'inputs': [
      {
        'index': 0,
        'transaction_id': TransactionId(hex='7c806478ff2de0c970523870cd57f508c0634c0dd0005ef835c16ef7a9c80018'),
      },
    ],
    'mint': None,
    'network_id': None,
    'outputs': [
      {
        'address': addr_test1qz6m0e3gn9ce8z97fr2p9cfcgvg6drjy5qtr84gctvsr5ep6w34ep80g6tnhglxtwcf9kfwe35vchx2s7w0awr4nx4sstap56q,
        'amount': {'coin': 10000000, 'multi_asset': {}},
        'datum': None,
        'datum_hash': None,
        'post_alonzo': False,
        'script': None,
      },
      {
        'address': addr_test1qz6khv0hpl4nsvs8eyn2lz0du6f57tav4pgr0u7es2qpukjtr2elenqpdnx7h5sqqmlpvl2wgz735yhexn7ufht4w3tsqx0vgv,
        'amount': {'coin': 9989831683, 'multi_asset': {}},
        'datum': None,
        'datum_hash': None,
        'post_alonzo': False,
        'script': None,
      },
    ],
    'reference_inputs': None,
    'required_signers': None,
    'script_data_hash': None,
    'total_collateral': None,
    'ttl': 11392138,
    'update': None,
    'validity_start': None,
    'withdraws': None,
  },
  'transaction_witness_set': {
    'bootstrap_witness': None,
    'native_scripts': None,
    'plutus_data': None,
    'plutus_v1_script': None,
    'plutus_v2_script': None,
    'redeemer': None,
    'vkey_witnesses': [
      {
        'signature': b'\xfbwE\xfd\xa1Y\xf2YUN\xd3)\x1d\xfd\x80\xdaA\xbf\x8aY\x9d\xbdG\x8eml\xc1\x06;\xc8N\xfb\x88\x17L\xf3\xb2\xe6\xa0\x11\xbb>\x84\x99\x92\xc7\xa9r\xa6\x03\x03W~\n\xa5q\xb6*l\xc8\x01.v\r',
        'vkey': {"type": "PaymentVerificationKeyShelley_ed25519", "description": "PaymentVerificationKeyShelley_ed25519", "cborHex": "5820ae60924a2a814453c0fc57a9a3e685643ed5a6f5af227298cb5105a12f25092e"},
      },
    ],
  },
  'valid': True,
}
84a400818258207c806478ff2de0c970523870cd57f508c0634c0dd0005ef835c16ef7a9c8001800018282583900b5b7e62899719388be48d412e1384311a68e44a01633d5185b203a643a746b909de8d2e7747ccb76125b25d98d198b9950f39fd70eb335611a0098968082583900b56bb1f70feb383207c926af89ede6934f2faca85037f3d982801e5a4b1ab3fccc016ccdebd20006fe167d4e40bd1a12f934fdc4dd7574571b000000025370bc03021a0002917d031a00add48aa10081825820ae60924a2a814453c0fc57a9a3e685643ed5a6f5af227298cb5105a12f25092e5840fb7745fda159f259554ed3291dfd80da41bf8a599dbd478e6d6cc1063bc84efb88174cf3b2e6a011bb3e849992c7a972a60303577e0aa571b62a6cc8012e760df5f6

@cffls
Copy link
Collaborator

cffls commented Oct 29, 2022

Thanks Robin! This cbor looks correct. If you submit this transaction, it will go through. It is still a mystery to me why build_and_sign resulted in an empty verification key. Is this issue consistently reproducible?

@robinboening
Copy link
Author

Yeah, the tx went through.
Correct, I was consistently getting this error. I've tried about 5-6 times yesterday.

I just put build_and_sign back in, so it is now as it was when I got the error. I tried another transaction and it succeeded! To be honest, now I am completely lost.

@cffls cffls added the bug Something isn't working label Oct 29, 2022
@cffls
Copy link
Collaborator

cffls commented Oct 31, 2022

Closing this issue as it is not reproducible now. @robinboening If you encounter this problem again, please feel free to reopen this issue.

@cffls cffls closed this as completed Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants