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

Adding support for a generalized Utxow rule #2176

Merged
merged 7 commits into from
Mar 16, 2021
Merged

Adding support for a generalized Utxow rule #2176

merged 7 commits into from
Mar 16, 2021

Conversation

TimSheard
Copy link
Contributor

First steps in writing a generalized Utxow rule that can be applied to the Alonzo Era.

Generalized wisFromWitnessSet (now witsFromTxWitnesses), scriptsNeeded, validateAuxiliaryData, validateScript, verifiedWits. Made a new WellFormed constraint
HasField "adHash" (Core.TxBody era) (StrictMaybe (AuxiliaryDataHash (Crypto era)))"

Copy link
Contributor

@JaredCorduan JaredCorduan left a comment

Choose a reason for hiding this comment

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

Thank you @TimSheard , this is a ton of great work! There are a few comments that can be removed, but besides that this looks really good!

wrote a generic version. Replaced Shelley, Allegra, and Mary
with this generic version. Next step write an Alonzo version that
calls the generice version, and then does Alonzo stuff.
Still to do: Add a new type for errors in the Utxow rule. Make some Hasfield instances
The Alonzo Script datatype had a stub for Plutus scripts. Imported the right type
and completed Show, Eq, PrettyA, ToCBOR and FromCBOR instances.

The Uxtow rule is now complete. Introduced AlonzoPredFail the UtxoW PredicateFailure type
for the Alonzo era. It embeds the PredicateFaliure type from the Shelley and ShelleyMa Eras.
Wrote Show, Eq, ToCBOR and FromCBOR instances. The Utxow rule now uses this type for Failures.

Generalized the ShelleyStyleWitness to lift from one PredicateFailure type to another so it
could be reused in any ERa that uses this style of PredicateFailure Embedding.
The missing HasField instances needed for the Uxtow rule were added.
Generalized the ValidateScript class to have the method 'scriptPrefixTag'
and made a default method for 'hashScript' Had to move a few things in
the Shelley Era to make the dependencies work out.
The ValidateScript class was moved from Shelley.Tx(..) to Cardano.Ledger.Era(..).
The field had it type changed to scriptPrefixTag :: Core.Script era -> BS.ByteString
this way the tag written can be chosen dynamically by looking at the script.

Filled in the mising CBOR instances fo the PredicateFailure for Utxos rule.
Wrote roundtrip serilaization tests for all of the new PredicateFailure type.
BIG TODO, some Alonzo era PredicateFailure type encode Scripts, and Scripts
do not have FromCBOR instances (they have FromCBOR(Annotator Script) instance.)
We will have to address this.
Copy link
Contributor

@nc6 nc6 left a comment

Choose a reason for hiding this comment

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

Bunch of spurious commented lines that should go, but otherwise looks great.

alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxow.hs Outdated Show resolved Hide resolved
alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxow.hs Outdated Show resolved Hide resolved
) =>
AlonzoPredFail era ->
Encode 'Open (AlonzoPredFail era)
encodePredFail (Embed x) = Sum Embed 0 !> E toCBOR x
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be better to flatten the encoding here, since we'd like the implementation detail (that we're wrapping) to be hidden. Shouldn't need any extra boilerplate, I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit involved, since the CBOR instances for (UtxowPredicateFailure era) in the Shelley era (ie. the type of x in (Embed x)) is written by hand, so making it inline would require going back and changing that. For a future time? Even if we flattened in CBOR, it remains unflattened (and visible) in the type AlonzoPredFail.

alonzo/impl/src/Cardano/Ledger/Alonzo/Tx.hs Show resolved Hide resolved
@TimSheard TimSheard merged commit 2f701b4 into master Mar 16, 2021
@iohk-bors iohk-bors bot deleted the ts-utxow2 branch March 16, 2021 15:28
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.

None yet

3 participants