Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scls-cardano/cddl-src/Cardano/SCLS/CDDL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions scls-cardano/cddl-src/Cardano/SCLS/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
--------------------------------------------------------------------------------
Expand Down
68 changes: 68 additions & 0 deletions scls-cardano/cddl-src/Cardano/SCLS/Namespace/Nonces.hs
Original file line number Diff line number Diff line change
@@ -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]
1 change: 1 addition & 0 deletions scls-cardano/scls-cardano.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading