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

Audit changes #445

Merged
merged 62 commits into from
Sep 10, 2024
Merged

Audit changes #445

merged 62 commits into from
Sep 10, 2024

Conversation

mmontin
Copy link
Collaborator

@mmontin mmontin commented Jul 31, 2024

This PR contains a variety of changes/bugfixes that were needed during recent work relying on cooked-validators:

  • Hash computation for script of various Plutus version was wrong, and is now fixed.
  • Some helpers and qol changes where added (see changelog for more details)
  • MockChainSt has been extended and given its own module
  • Hashed datums can now be used in reference inputs. The corresponding datum is properly fed to the transaction. This is done through somewhat a hack, see this issue for more details.
  • Rewarding scripts are now supported. The reward mechanism is not at all identical to the one on-chain, due to likely limitation in the emulator, but the scripts are properly called and the skeleton accounts for the withdrawals properly.
  • A bug in balancing has been fixed, where the balancing would wrongfully fail in some corner cases with excess inputs but not enough to ensure min ada in the created output.

@florentc
Copy link
Member

florentc commented Aug 1, 2024

I think we should keep this branch as a reference but when we decide to apply the changes to main after our audit obligations, we should open one PR per feature these commits cover, then review, merge, and iterate like this.

There is really a lot here and each subject would likely benefit from a dedicated PR (whether it is tiny or large), with discussion and review (whether it is trivial or turns into debates), and maybe small tweaks. Furthermore, it would be easier to search through the PR tracker rather than commit messages if in the future we want to remember what we changed, when, and why.

@mmontin mmontin marked this pull request as ready for review September 5, 2024 12:11
Copy link
Member

@florentc florentc left a comment

Choose a reason for hiding this comment

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

This is a review of only commit db84394 "Support for hashed datums in reference inputs".

This is only extreme nitpicking stuff which may be ignored altogether.

Since this is a per commit review, the suggestion GUI was not available.

src/Cooked/MockChain/Balancing.hs Show resolved Hide resolved
src/Cooked/MockChain/BlockChain.hs Show resolved Hide resolved
Comment on lines 348 to 350
let outputToDatumHashM output = case output ^. outputDatumL of
Api.OutputDatumHash dHash -> Just dHash
_ -> Nothing
Copy link
Member

Choose a reason for hiding this comment

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

Is it something useful elsewhere that we should put on top level?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Something that could be reused was already existing indeed and I now used it: isOutputWithDatumHash. Thanks!

src/Cooked/MockChain/BlockChain.hs Outdated Show resolved Hide resolved
-- | Looks us the data on UTxOs the transaction consumes. This corresponds to
-- the keys of what should be removed from the stored datums in our mockchain.
-- There can be duplicates, which is expected.
txSkelConsumedData :: (MonadBlockChainBalancing m) => TxSkel -> m [Api.DatumHash]
Copy link
Member

Choose a reason for hiding this comment

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

I find the names confusing. This ends with Data and returns a list of hashes, the previous one ends with HashedData and returns a map that resolve to the actual data.

Also I find "consumed" a bit misleading. This is the same as "spent"? This means the datum hashes of every piece of datum found in the inputs, doesn't it? Not a subset.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed the name to txSkelInputDataAsHashes

src/Cooked/MockChain/GenerateTx/Body.hs Outdated Show resolved Hide resolved
Comment on lines +361 to +363
<+> "("
<> prettyHash (pcOptHashes opts) (toHash dHash)
<> "):"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should have a flag in the prettyprinting options to enable this on demand and hide it by default. The default printing might be starting to get a bit crowded (this is not the reason, this is just a drop, it just makes me think about it). In general, we don't really track datum hashes and this would be lighter by default.

For instance pcOptPrintDatumHashes like there already is a pcOptPrintTxHashes, false by default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will leave these changes to later changes in the pretty printer.

src/Cooked/Pretty/Cooked.hs Show resolved Hide resolved
src/Cooked/Pretty/Cooked.hs Show resolved Hide resolved
src/Cooked/Skeleton.hs Show resolved Hide resolved
Copy link
Member

@florentc florentc left a comment

Choose a reason for hiding this comment

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

This is about commit 72e2820 "withdrawal support"

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@@ -59,6 +60,11 @@ instance Transform TxContext Input.InputContext where
instance Transform TxContext Collateral.CollateralContext where
transform TxContext {..} = Collateral.CollateralContext {..}

instance Transform TxContext Withdrawals.WithdrawalsContext where
Copy link
Member

Choose a reason for hiding this comment

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

I am a bit skeptical about this Transform typeclass. This is a whole topic on its own, not related to this here specifically, so I won't comment on this here anymore. We may discuss it between maintainers or open the discussion in an issue.

src/Cooked/MockChain/GenerateTx/Withdrawals.hs Outdated Show resolved Hide resolved
cooked-validators.cabal Outdated Show resolved Hide resolved
@mmontin mmontin merged commit 41852fa into main Sep 10, 2024
7 checks passed
@mmontin mmontin deleted the mm/djed-audit branch September 10, 2024 12:53
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