Skip to content

Commit 53da000

Browse files
committed
Introduce nonce namespace
1 parent b5854bb commit 53da000

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

scls-cardano/cddl-src/Cardano/SCLS/CDDL.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Cardano.SCLS.Namespace.GovCommittee qualified as GovCommittee
1515
import Cardano.SCLS.Namespace.GovConstitution qualified as GovConstitution
1616
import Cardano.SCLS.Namespace.GovPParams qualified as GovPParams
1717
import Cardano.SCLS.Namespace.GovProposals qualified as GovProposals
18+
import Cardano.SCLS.Namespace.Nonces qualified as Nonces
1819
import Cardano.SCLS.Namespace.PoolStake qualified as PoolStake
1920
import Cardano.SCLS.Namespace.Pots qualified as Pots
2021
import Cardano.SCLS.Namespace.Snapshots qualified as Snapshots
@@ -46,6 +47,7 @@ namespaces =
4647
, mkDefinition @"pots/v0" Pots.record_entry
4748
, mkDefinition @"pool_stake/v0" PoolStake.record_entry
4849
, mkDefinition @"snapshots/v0" Snapshots.record_entry
50+
, mkDefinition @"nonces/v0" Nonces.record_entry
4951
, mkDefinition @"gov/committee/v0" GovCommittee.record_entry
5052
, mkDefinition @"gov/constitution/v0" GovConstitution.record_entry
5153
, mkDefinition @"gov/pparams/v0" GovPParams.record_entry
@@ -64,6 +66,7 @@ mkDefinition r =
6466

6567
type instance Spec.NamespaceKeySize "utxo/v0" = 34
6668
type instance Spec.NamespaceKeySize "blocks/v0" = 36 -- 28 bytes for key, and 8 for epoch in BE
69+
type instance Spec.NamespaceKeySize "nonces/v0" = 1 -- Just zero
6770
type instance Spec.NamespaceKeySize "pots/v0" = 8 -- Key is epoch number
6871
type instance Spec.NamespaceKeySize "pool_stake/v0" = 28 -- 28 bytes for key
6972
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

scls-cardano/cddl-src/Cardano/SCLS/Common.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ big_nint = "big_nint" =:= tag 3 bounded_bytes
119119
int64 :: Rule
120120
int64 = "int64" =:= toInteger (minBound @Int64) ... toInteger (maxBound @Int64)
121121

122+
word64 :: Rule
123+
word64 = "word64" =:= VUInt `sized` (8 :: Word)
124+
122125
-------------------------------------------------------------------------------
123126
-- Utility
124127
--------------------------------------------------------------------------------
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{-# LANGUAGE ImportQualifiedPost #-}
2+
{-# LANGUAGE OverloadedLists #-}
3+
{-# LANGUAGE OverloadedStrings #-}
4+
{-# LANGUAGE QuasiQuotes #-}
5+
{-# LANGUAGE TypeApplications #-}
6+
{-# LANGUAGE NoImplicitPrelude #-}
7+
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
8+
9+
{-# HLINT ignore "Use camelCase" #-}
10+
module Cardano.SCLS.Namespace.Nonces where
11+
12+
import Cardano.SCLS.Common
13+
import Codec.CBOR.Cuddle.Huddle
14+
import Text.Heredoc (str)
15+
import Prelude (($))
16+
17+
record_entry :: Rule
18+
record_entry =
19+
comment
20+
[str| Key is just zero
21+
|
22+
| ```
23+
| meta:
24+
| endian: be
25+
|
26+
| seq:
27+
| - id: key
28+
| type: nonce
29+
|
30+
| types:
31+
| nonce:
32+
| doc: Nonce value
33+
| size: 1
34+
| type: u1
35+
| const: 0
36+
| ```
37+
|
38+
|]
39+
$ "record_entry" =:= nonces
40+
41+
nonces :: Rule
42+
nonces =
43+
comment
44+
[str| List of nonces used in the protocol state
45+
|
46+
|]
47+
$ "nonces"
48+
=:= mp
49+
[ "last_slot" ==> with_origin slot_no
50+
, "cert_counters" ==> mp [0 <+ asKey keyhash32 ==> word64]
51+
, "evolving_nonce" ==> nonce
52+
, "candidate_nonce" ==> nonce
53+
, "epoch_nonce" ==> nonce
54+
, "lab_nonce" ==> nonce
55+
, "last_epoch_block_nonce" ==> nonce
56+
]
57+
58+
nonce :: Rule
59+
nonce = "nonce" =:= neutral_nonce / just_nonce
60+
61+
neutral_nonce :: Rule
62+
neutral_nonce = "neutral_nonce" =:= arr [0]
63+
64+
just_nonce :: Rule
65+
just_nonce = "just_nonce" =:= arr [1, a hash32]
66+
67+
with_origin :: (IsType0 t0) => t0 -> GRuleCall
68+
with_origin = binding $ \x -> "with_origin" =:= arr [0] / arr [1, a x]

scls-cardano/scls-cardano.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ library
3333
Cardano.SCLS.Namespace.GovConstitution
3434
Cardano.SCLS.Namespace.GovPParams
3535
Cardano.SCLS.Namespace.GovProposals
36+
Cardano.SCLS.Namespace.Nonces
3637
Cardano.SCLS.Namespace.PoolStake
3738
Cardano.SCLS.Namespace.Pots
3839
Cardano.SCLS.Namespace.Snapshots

0 commit comments

Comments
 (0)