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

Huddle for Alonzo #4778

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions eras/allegra/impl/cardano-ledger-allegra.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ library testlib
containers,
cuddle,
generic-random,
heredoc,
microlens,
mtl,
small-steps,
Expand Down
227 changes: 143 additions & 84 deletions eras/allegra/impl/cddl-files/allegra.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,33 @@ address = h'00100000000000000000000000000000000000000000000000000000001100000000
/ h'7080000000000000000000000000000000000000000000000000000000'

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 @@ -96,17 +100,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 @@ -118,18 +122,37 @@ major_protocol_version = 1 .. 3

metadata_hash = $hash32

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]

multisig_script = [multisig_pubkey
// multisig_all
// multisig_any
// multisig_n_of_k]

; 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])

Expand All @@ -143,47 +166,71 @@ 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]

; Allegra transaction body adds the validity interval start at index 8
transaction_body = {0 : set<transaction_input>,
1 : [* transaction_output],
2 : coin,
3 : uint,
? 4 : [* certificate],
? 5 : withdrawals,
? 6 : update,
? 7 : metadata_hash,
? 8 : uint}
;
transaction_body = {0 : set<transaction_input>
, 1 : [* transaction_output]
, 2 : coin
, 3 : uint
, ? 4 : [* certificate]
, ? 5 : withdrawals
, ? 6 : update
, ? 7 : metadata_hash
, ? 8 : uint}

transaction_index = uint .size 2

Expand All @@ -199,9 +246,9 @@ transaction_metadatum_label = uint

transaction_output = [address, amount : coin]

transaction_witness_set = {? 0 : [* vkeywitness],
? 1 : [* native_script],
? 2 : [* bootstrap_witness]}
transaction_witness_set = {? 0 : [* vkeywitness]
, ? 1 : [* multisig_script]
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 wrong. Needs fixing. Should be a native_script.

, ? 2 : [* bootstrap_witness]}

unit_interval = #6.30([1, 2])

Expand All @@ -223,19 +270,29 @@ invalid_hereafter = (5, uint)

move_instantaneous_rewards_cert = (6, move_instantaneous_reward)

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

multisig_all = (1, [* multisig_script])

multisig_any = (2, [* multisig_script])

multisig_n_of_k = (3, uint, [* multisig_script])

multisig_pubkey = (0, addr_keyhash)

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 @@ -253,6 +310,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/allegra/impl/huddle-cddl/Main.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
module Main where

import Paths_cardano_ledger_allegra
import qualified Test.Cardano.Ledger.Allegra.CDDL as Allegra
import Test.Cardano.Ledger.Allegra.CDDL (allegra)
import Test.Cardano.Ledger.Binary.Cuddle (writeSpec)

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