Skip to content
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

Fix signing of a transaction in compatible shelley transaction signed-transaction command by not using an incomplete body for signing #1057

Merged

Conversation

carbolymer
Copy link
Contributor

@carbolymer carbolymer commented Feb 6, 2025

Changelog

- description: |
    Update [cardano-api-10.10.0.0](https://github.com/IntersectMBO/cardano-api/blob/master/cardano-api/CHANGELOG.md#101000)
    Fix signing of a transaction in `compatible shelley transaction signed-transaction` command. Previously two different transaction bodies were used for the resulting transaction and the signature - now it's used the same for both purposes.
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  # - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  # - refactoring    # QoL changes
   - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

This PR contains two commits:

  • the actual fix
  • the split of Cardano.CLI.Compatible.Transaction into separate modules aligning with cardano-cli design.

Fixes:

Requires:

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

@carbolymer carbolymer self-assigned this Feb 6, 2025
@carbolymer carbolymer force-pushed the mgalazyn/test/compatible-tx-sign-different-witnesses branch 6 times, most recently from 1897e91 to efd2bed Compare February 11, 2025 20:13
@carbolymer carbolymer changed the title Add test: compatible shelley transaction signed-transaction results in different witnesses than legacy command Fix signing of a transaction in compatible shelley transaction signed-transaction command. Feb 12, 2025
@carbolymer carbolymer force-pushed the mgalazyn/test/compatible-tx-sign-different-witnesses branch from 5de3eba to 754d7db Compare February 12, 2025 14:09
@carbolymer carbolymer marked this pull request as ready for review February 12, 2025 14:11
@carbolymer carbolymer marked this pull request as draft February 13, 2025 17:08
@carbolymer carbolymer force-pushed the mgalazyn/test/compatible-tx-sign-different-witnesses branch 3 times, most recently from b92af75 to 64e7f9e Compare February 17, 2025 20:50
@carbolymer carbolymer marked this pull request as ready for review February 17, 2025 20:52
@@ -325,7 +325,7 @@ test-suite cardano-cli-test
base16-bytestring,
bech32 >=1.1.0,
bytestring,
cardano-api:{cardano-api, gen, internal},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I have a few questions

:: ()
=> ShelleyBasedEra era
-> Maybe NetworkId
-> A.TxBody era
Copy link
Contributor

@Jimbo4350 Jimbo4350 Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ It confused me at first but I'm just noticing this type. What do we gain by wrapping the ledger type here? Why not directly use the ledger type?

Copy link
Contributor Author

@carbolymer carbolymer Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That we don't have to use ShelleyLedgerEra type family and we can hide some calls to shelleyBasedEraConstraints behind our lens. A little convenience for some boilerplate.

If we decide to not use this TxBody type, we should deprecate the module Cardano.Api.Ledger.Lens then to avoid confusion.

@@ -279,69 +277,29 @@ runCompatibleTransactionCmd
)
sbe

let certsRefInputs =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we don't need reference inputs because QA does not use them?

Copy link
Contributor Author

@carbolymer carbolymer Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do - but removed code was only used to build a body only for creating signatures. But it's problematic: it's a slightly different body than the one we're using in building compatible transaction. So the transaction building logic is duplicated in two places, and we had the bug with incorrect body hash used for the signatures.

let txCerts = mkTxCertificates sbe certsAndMaybeScriptWits

-- this body is only for witnesses
apiTxBody <-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

firstExceptT CompatiblePParamsConversionError . hoistEither $
createCompatibleTx sbe ins allOuts fee protocolUpdates votes txCerts

let txBody = ledgerTx ^. A.txToTxBodyL sbe
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to directly use the ledger tx body type instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carbolymer carbolymer force-pushed the mgalazyn/test/compatible-tx-sign-different-witnesses branch from 64e7f9e to fa52c7d Compare February 20, 2025 15:38
@carbolymer carbolymer force-pushed the mgalazyn/test/compatible-tx-sign-different-witnesses branch 2 times, most recently from 64e7f9e to b27c0c0 Compare February 20, 2025 15:50
@carbolymer carbolymer force-pushed the mgalazyn/test/compatible-tx-sign-different-witnesses branch 2 times, most recently from 24a3f28 to c62048c Compare February 20, 2025 16:25
Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix signing how? Again, break this up in to sensible commits to make it easy for the reviewer to understand what has changed as there are lots of style related changes.

@carbolymer carbolymer force-pushed the mgalazyn/test/compatible-tx-sign-different-witnesses branch 3 times, most recently from 99bc559 to d4c8068 Compare February 27, 2025 11:53
@carbolymer carbolymer requested a review from Jimbo4350 February 27, 2025 11:54
@carbolymer carbolymer changed the title Fix signing of a transaction in compatible shelley transaction signed-transaction command. Fix signing of a transaction in compatible shelley transaction signed-transaction command by not using an incomplete body for signing Feb 27, 2025
@carbolymer carbolymer force-pushed the mgalazyn/test/compatible-tx-sign-different-witnesses branch from d4c8068 to d12f2e1 Compare February 28, 2025 13:21
This avoids of implementation drift between cardano-api and cardano-cli.
We were building two transaction bodies - one for just signatures and
one is the resulting transaction. Thos bodies over time became different
and resulted in a bug producing invalid transaction signatures.

Now it's only one body used for both purposes.
@carbolymer carbolymer force-pushed the mgalazyn/test/compatible-tx-sign-different-witnesses branch 2 times, most recently from bddf201 to e3bdb30 Compare February 28, 2025 13:37
@carbolymer carbolymer requested review from a team as code owners February 28, 2025 13:37
@carbolymer carbolymer enabled auto-merge February 28, 2025 13:37
@carbolymer carbolymer force-pushed the mgalazyn/test/compatible-tx-sign-different-witnesses branch from e3bdb30 to 5e20af4 Compare February 28, 2025 13:40
@carbolymer carbolymer added this pull request to the merge queue Feb 28, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 28, 2025
@carbolymer carbolymer added this pull request to the merge queue Feb 28, 2025
Merged via the queue into master with commit c1b0f43 Feb 28, 2025
25 of 26 checks passed
@carbolymer carbolymer deleted the mgalazyn/test/compatible-tx-sign-different-witnesses branch February 28, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants