diff --git a/scls-cardano/cddl-src/Cardano/SCLS/CDDL.hs b/scls-cardano/cddl-src/Cardano/SCLS/CDDL.hs index 2047a8e0..57d474c7 100644 --- a/scls-cardano/cddl-src/Cardano/SCLS/CDDL.hs +++ b/scls-cardano/cddl-src/Cardano/SCLS/CDDL.hs @@ -15,6 +15,7 @@ import Cardano.SCLS.Namespace.GovCommittee qualified as GovCommittee import Cardano.SCLS.Namespace.GovConstitution qualified as GovConstitution import Cardano.SCLS.Namespace.GovPParams qualified as GovPParams import Cardano.SCLS.Namespace.GovProposals qualified as GovProposals +import Cardano.SCLS.Namespace.Nonces qualified as Nonces import Cardano.SCLS.Namespace.PoolStake qualified as PoolStake import Cardano.SCLS.Namespace.Pots qualified as Pots import Cardano.SCLS.Namespace.Snapshots qualified as Snapshots @@ -46,6 +47,7 @@ namespaces = , mkDefinition @"pots/v0" Pots.record_entry , mkDefinition @"pool_stake/v0" PoolStake.record_entry , mkDefinition @"snapshots/v0" Snapshots.record_entry + , mkDefinition @"nonces/v0" Nonces.record_entry , mkDefinition @"gov/committee/v0" GovCommittee.record_entry , mkDefinition @"gov/constitution/v0" GovConstitution.record_entry , mkDefinition @"gov/pparams/v0" GovPParams.record_entry @@ -64,6 +66,7 @@ mkDefinition r = type instance Spec.NamespaceKeySize "utxo/v0" = 34 type instance Spec.NamespaceKeySize "blocks/v0" = 36 -- 28 bytes for key, and 8 for epoch in BE +type instance Spec.NamespaceKeySize "nonces/v0" = 1 -- Just zero type instance Spec.NamespaceKeySize "pots/v0" = 8 -- Key is epoch number type instance Spec.NamespaceKeySize "pool_stake/v0" = 28 -- 28 bytes for key type instance Spec.NamespaceKeySize "snapshots/v0" = 32 -- 1 byte for hash type, 1 byte for stage, 29 bytes for hash (cred 29, key 28+1), 1 for value type diff --git a/scls-cardano/cddl-src/Cardano/SCLS/Common.hs b/scls-cardano/cddl-src/Cardano/SCLS/Common.hs index e2dcfb6c..ae49ee89 100644 --- a/scls-cardano/cddl-src/Cardano/SCLS/Common.hs +++ b/scls-cardano/cddl-src/Cardano/SCLS/Common.hs @@ -68,10 +68,10 @@ address = "address" =:= VBytes -------------------------------------------------------------------------------- keyhash32 :: Rule -keyhash32 = "keyhash28" =:= hash32 +keyhash32 = "keyhash32" =:= hash32 keyhash28 :: Rule -keyhash28 = "keyhash32" =:= hash28 -- Important: seems on the current chain it's 32 +keyhash28 = "keyhash28" =:= hash28 -- Important: seems on the current chain it's 32 hash28 :: Rule hash28 = "hash28" =:= VBytes `sized` (28 :: Word64) @@ -119,6 +119,9 @@ big_nint = "big_nint" =:= tag 3 bounded_bytes int64 :: Rule int64 = "int64" =:= toInteger (minBound @Int64) ... toInteger (maxBound @Int64) +word64 :: Rule +word64 = "word64" =:= VUInt `sized` (8 :: Word) + ------------------------------------------------------------------------------- -- Utility -------------------------------------------------------------------------------- diff --git a/scls-cardano/cddl-src/Cardano/SCLS/Namespace/Nonces.hs b/scls-cardano/cddl-src/Cardano/SCLS/Namespace/Nonces.hs new file mode 100644 index 00000000..0b782250 --- /dev/null +++ b/scls-cardano/cddl-src/Cardano/SCLS/Namespace/Nonces.hs @@ -0,0 +1,68 @@ +{-# LANGUAGE ImportQualifiedPost #-} +{-# LANGUAGE OverloadedLists #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE NoImplicitPrelude #-} +{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} + +{-# HLINT ignore "Use camelCase" #-} +module Cardano.SCLS.Namespace.Nonces where + +import Cardano.SCLS.Common +import Codec.CBOR.Cuddle.Huddle +import Text.Heredoc (str) +import Prelude (($)) + +record_entry :: Rule +record_entry = + comment + [str| Key is just zero + | + | ``` + | meta: + | endian: be + | + | seq: + | - id: key + | type: nonce + | + | types: + | nonce: + | doc: Nonce value + | size: 1 + | type: u1 + | const: 0 + | ``` + | + |] + $ "record_entry" =:= nonces + +nonces :: Rule +nonces = + comment + [str| List of nonces used in the protocol state + | + |] + $ "nonces" + =:= mp + [ "last_slot" ==> with_origin slot_no + , "cert_counters" ==> mp [0 <+ asKey keyhash32 ==> word64] + , "evolving_nonce" ==> nonce + , "candidate_nonce" ==> nonce + , "epoch_nonce" ==> nonce + , "lab_nonce" ==> nonce + , "last_epoch_block_nonce" ==> nonce + ] + +nonce :: Rule +nonce = "nonce" =:= neutral_nonce / just_nonce + +neutral_nonce :: Rule +neutral_nonce = "neutral_nonce" =:= arr [0] + +just_nonce :: Rule +just_nonce = "just_nonce" =:= arr [1, a hash32] + +with_origin :: (IsType0 t0) => t0 -> GRuleCall +with_origin = binding $ \x -> "with_origin" =:= arr [0] / arr [1, a x] diff --git a/scls-cardano/scls-cardano.cabal b/scls-cardano/scls-cardano.cabal index b92256f0..93788d75 100644 --- a/scls-cardano/scls-cardano.cabal +++ b/scls-cardano/scls-cardano.cabal @@ -33,6 +33,7 @@ library Cardano.SCLS.Namespace.GovConstitution Cardano.SCLS.Namespace.GovPParams Cardano.SCLS.Namespace.GovProposals + Cardano.SCLS.Namespace.Nonces Cardano.SCLS.Namespace.PoolStake Cardano.SCLS.Namespace.Pots Cardano.SCLS.Namespace.Snapshots