Skip to content

Commit

Permalink
Finalise Mary
Browse files Browse the repository at this point in the history
  • Loading branch information
aniketd committed Nov 29, 2024
1 parent 0bbacc5 commit d4fb77d
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
{-# HLINT ignore "Use camelCase" #-}
{-# HLINT ignore "Evaluate" #-}

module Test.Cardano.Ledger.Allegra.CDDL where
module Test.Cardano.Ledger.Allegra.CDDL (
module Test.Cardano.Ledger.Shelley.CDDL,
module Test.Cardano.Ledger.Allegra.CDDL,
) where

import Codec.CBOR.Cuddle.Huddle
import Data.Function (($))
Expand Down
272 changes: 159 additions & 113 deletions eras/mary/impl/cddl-files/mary.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,39 @@ $vrf_vkey = bytes .size 32
addr_keyhash = $hash28

; address = bytes
; reward_account = bytes
; reward_account = bytes
;
; address format:
; [ 8 bit header | payload ];
; address format:
; [ 8 bit header | payload ];
;
; shelley payment addresses:
; bit 7: 0
; bit 6: base/other
; bit 5: pointer/enterprise [for base: stake cred is keyhash/scripthash]
; bit 4: payment cred is keyhash/scripthash
; bits 3-0: network id
; shelley payment addresses:
; bit 7: 0
; bit 6: base/other
; bit 5: pointer/enterprise [for base: stake cred is keyhash/scripthash]
; bit 4: payment cred is keyhash/scripthash
; bits 3-0: network id
;
; reward addresses:
; bits 7-5: 111
; bit 4: credential is keyhash/scripthash
; bits 3-0: network id
; reward addresses:
; bits 7-5: 111
; bit 4: credential is keyhash/scripthash
; bits 3-0: network id
;
; byron addresses:
; bits 7-4: 1000
; byron addresses:
; bits 7-4: 1000
;
; 0000: base address: keyhash28,keyhash28
; 0001: base address: scripthash28,keyhash28
; 0010: base address: keyhash28,scripthash28
; 0011: base address: scripthash28,scripthash28
; 0100: pointer address: keyhash28, 3 variable length uint
; 0101: pointer address: scripthash28, 3 variable length uint
; 0110: enterprise address: keyhash28
; 0111: enterprise address: scripthash28
; 1000: byron address
; 1110: reward account: keyhash28
; 1111: reward account: scripthash28
; 1001-1101: future formats
;
; 0000: base address: keyhash28,keyhash28
; 0001: base address: scripthash28,keyhash28
; 0010: base address: keyhash28,scripthash28
; 0011: base address: scripthash28,scripthash28
; 0100: pointer address: keyhash28, 3 variable length uint
; 0101: pointer address: scripthash28, 3 variable length uint
; 0110: enterprise address: keyhash28
; 0111: enterprise address: scripthash28
; 1000: byron address
; 1110: reward account: keyhash28
; 1111: reward account: scripthash28
; 1001 - 1101: future formats
address = h'001000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000'
/ h'102000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000'
/ h'203000000000000000000000000000000000000000000000000000000033000000000000000000000000000000000000000000000000000000'
Expand All @@ -65,29 +66,33 @@ address = h'00100000000000000000000000000000000000000000000000000000001100000000
asset_name = bytes .size (0 .. 32)

auxiliary_data = {* transaction_metadatum_label => transaction_metadatum}
/ [transaction_metadata : {* transaction_metadatum_label => transaction_metadatum},
auxiliary_scripts : [* native_script]]

block = [header,
transaction_bodies : [* transaction_body],
transaction_witness_sets : [* transaction_witness_set],
auxiliary_data_set : {* transaction_index => auxiliary_data}]

bootstrap_witness = [public_key : $vkey,
signature : $signature,
chain_code : bytes .size 32,
attributes : bytes]

certificate = [stake_registration //
stake_deregistration //
stake_delegation //
pool_registration //
pool_retirement //
genesis_key_delegation //
move_instantaneous_rewards_cert]
/ [transaction_metadata : {* transaction_metadatum_label => transaction_metadatum}
, auxiliary_scripts : [* native_script]]

block = [header
, transaction_bodies : [* transaction_body]
, transaction_witness_sets : [* transaction_witness_set]
, auxiliary_data_set : {* transaction_index => auxiliary_data}]

bootstrap_witness = [public_key : $vkey
, signature : $signature
, chain_code : bytes .size 32
, attributes : bytes]

certificate = [stake_registration
// stake_deregistration
// stake_delegation
// pool_registration
// pool_retirement
// genesis_key_delegation
// move_instantaneous_rewards_cert]

coin = uint

credential = [0, addr_keyhash // 1, script_hash]

delta_coin = int

dns_name = text .size (0 .. 64)

epoch = uint
Expand All @@ -98,17 +103,17 @@ genesishash = $hash28

header = [header_body, body_signature : $kes_signature]

header_body = [block_number : uint,
slot : uint,
prev_hash : $hash32 / nil,
issuer_vkey : $vkey,
vrf_vkey : $vrf_vkey,
nonce_vrf : $vrf_cert,
leader_vrf : $vrf_cert,
block_body_size : uint .size 4,
block_body_hash : $hash32,
operational_cert,
protocol_version]
header_body = [block_number : uint
, slot : uint
, prev_hash : $hash32 / nil
, issuer_vkey : $vkey
, vrf_vkey : $vrf_vkey
, nonce_vrf : $vrf_cert
, leader_vrf : $vrf_cert
, block_body_size : uint .size 4
, block_body_hash : $hash32
, operational_cert
, protocol_version]

int64 = -9223372036854775808 .. 9223372036854775807

Expand All @@ -122,22 +127,36 @@ metadata_hash = $hash32

mint = multiasset<int64>

move_instantaneous_reward = [0 / 1, {* stake_credential => coin}]
; The first field determines where the funds are drawn from.
; 0 denotes the reserves,
; 1 denotes the treasury.
; If the second field is a map, funds are moved to stake credentials.
; Otherwise, the funds are given to the other accounting pot.
; NOTE:
; This has been safely backported from Alonzo.
;
move_instantaneous_reward = [0 / 1, {* stake_credential => delta_coin} / coin]

; Timelock validity intervals are half-open intervals [a, b).
native_script = [script_pubkey //
script_all //
script_any //
script_n_of_k //
invalid_before //
invalid_hereafter]
;
; invalid_before:
; specifies the left (included) endpoint a.
;
; invalid_hereafter:
; specifies the right (excluded) endpoint b.
;
native_script = [script_pubkey
// script_all
// script_any
// script_n_of_k
// invalid_before
// invalid_hereafter]

nonce = [0 //
1, bytes .size 32]
nonce = [0 // 1, bytes .size 32]

nonnegative_interval = #6.30([uint, positive_int])

policy_id = scripthash
policy_id = script_hash

pool_keyhash = $hash28

Expand All @@ -149,47 +168,70 @@ positive_int = 1 .. 18446744073709551615

proposed_protocol_parameter_updates = {* genesishash => protocol_param_update}

protocol_param_update = {? 0 : uint,
? 1 : uint,
? 2 : uint,
? 3 : uint,
? 4 : uint .size 2,
? 5 : coin,
? 6 : coin,
? 7 : epoch,
? 8 : uint,
? 9 : nonnegative_interval,
? 10 : unit_interval,
? 11 : unit_interval,
? 12 : unit_interval,
? 13 : nonce,
? 14 : [protocol_version],
? 15 : coin}

relay = [single_host_addr //
single_host_name //
multi_host_name]
; 0: minfee A
; 1: minfee B
; 2: max block body size
; 3: max transaction size
; 4: max block header size
; 5: key deposit
; 6: pool deposit
; 7: maximum epoch
; 8: n_opt: desired number of stake pools
; 9: pool pledge influence
; 10: expansion rate
; 11: treasury growth rate
; 12: d. decentralization constant
; 13: extra entropy
; 14: protocol version
; 15: min utxo value
;
protocol_param_update = {? 0 : uint
, ? 1 : uint
, ? 2 : uint
, ? 3 : uint
, ? 4 : uint .size 2
, ? 5 : coin
, ? 6 : coin
, ? 7 : epoch
, ? 8 : uint
, ? 9 : nonnegative_interval
, ? 10 : unit_interval
, ? 11 : unit_interval
, ? 12 : unit_interval
, ? 13 : nonce
, ? 14 : [protocol_version]
, ? 15 : coin}

relay = [single_host_addr // single_host_name // multi_host_name]

reward_account = h'E090000000000000000000000000000000000000000000000000000000'
/ h'F0A0000000000000000000000000000000000000000000000000000000'

scripthash = $hash28
; To compute a script hash, note that you must prepend
; a tag to the bytes of the script before hashing.
; The tag is determined by the language.
; The tags in the Conway era are:
; "\\x00\" for multisig scripts
; "\\x01\" for Plutus V1 scripts
; "\\x02\" for Plutus V2 scripts
; "\\x03\" for Plutus V3 scripts
;
script_hash = $hash28

stake_credential = [0, addr_keyhash //
1, scripthash]
stake_credential = credential

transaction = [transaction_body, transaction_witness_set, auxiliary_data / nil]

transaction_body = {0 : set<transaction_input>,
1 : [* transaction_output],
2 : coin,
3 : uint,
? 4 : [* certificate],
? 5 : withdrawals,
? 6 : update,
? 7 : metadata_hash,
? 8 : uint,
? 9 : mint}
transaction_body = {0 : set<transaction_input>
, 1 : [* transaction_output]
, 2 : coin
, 3 : uint
, ? 4 : [* certificate]
, ? 5 : withdrawals
, ? 6 : update
, ? 7 : metadata_hash
, ? 8 : uint
, ? 9 : mint}

transaction_index = uint .size 2

Expand All @@ -205,9 +247,9 @@ transaction_metadatum_label = uint

transaction_output = [address, amount : value]

transaction_witness_set = {? 0 : [* vkeywitness],
? 1 : [* native_script],
? 2 : [* bootstrap_witness]}
transaction_witness_set = {? 0 : [* vkeywitness]
, ? 1 : [* native_script]
, ? 2 : [* bootstrap_witness]}

unit_interval = #6.30([1, 2])

Expand All @@ -231,19 +273,21 @@ invalid_hereafter = (5, uint)

move_instantaneous_rewards_cert = (6, move_instantaneous_reward)

; dns_name: An SRV DNS record
;
multi_host_name = (2, dns_name)

operational_cert = ($kes_vkey, uint, uint, $signature)

pool_params = (pool_keyhash,
vrf_keyhash,
coin,
coin,
unit_interval,
reward_account,
set<addr_keyhash>,
[* relay],
pool_metadata / nil)
pool_params = (pool_keyhash
, vrf_keyhash
, coin
, coin
, unit_interval
, reward_account
, set<addr_keyhash>
, [* relay]
, pool_metadata / nil)

pool_registration = (3, pool_params)

Expand All @@ -261,6 +305,8 @@ script_pubkey = (0, addr_keyhash)

single_host_addr = (0, port / nil, ipv4 / nil, ipv6 / nil)

; dns_name: An A or AAAA DNS record
;
single_host_name = (1, port / nil, dns_name)

stake_delegation = (2, stake_credential, pool_keyhash)
Expand Down
7 changes: 2 additions & 5 deletions eras/mary/impl/huddle-cddl/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ module Main where

import Paths_cardano_ledger_mary
import Test.Cardano.Ledger.Binary.Cuddle (writeSpec)
import qualified Test.Cardano.Ledger.Mary.CDDL as Mary
import Test.Cardano.Ledger.Mary.CDDL (mary)

-- Generate cddl files for all relevant specifications
main :: IO ()
main = do
specFile <- getDataFileName "cddl-files/mary.cddl"
writeSpec Mary.cddl specFile
main = writeSpec mary =<< getDataFileName "cddl-files/mary.cddl"
Loading

0 comments on commit d4fb77d

Please sign in to comment.