1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! The types for conditions that must apply in order for an update to be applied.

use crate::primitives::*;
use crate::token_id;

/// The `OrIgnore<T>` type is an enum type parameterised by a type `T`.
pub enum OrIgnore<T> {
    /// The value of the field must match the given condition in order to apply the transaction.
    Check(T),
    /// The value of the field is not considered when applying the transaction.
    Ignore,
}

/// A condition that is true for any value `x` that satisfies `lower <= x <= upper`, parameterised
/// by a type `T`.
pub struct ClosedInterval<T> {
    /// The (inclusive) lower bound of the condition. A value `x` must satisfy `lower <= x` in
    /// order to satisfy this condition.
    pub lower: T,
    /// The (inclusive) upper bound of the condition. A value `x` must satisfy `upper <= x` in
    /// order to satisfy this condition.
    pub upper: T,
}

/// Condition on an epoch's staking ledger.
pub struct EpochLedgerCondition {
    /// Condition on the hash of the epoch's staking ledger.
    pub hash: OrIgnore<Hash>,
    /// Condition on the total currency of the epoch's staking ledger.
    pub total_currency: OrIgnore<ClosedInterval<u64>>,
}

/// Condition on the data for an epoch.
pub struct EpochDataCondition {
    /// Condition on the staking ledger for an epoch.
    pub ledger: EpochLedgerCondition,
    /// Condition on the cryptographic seed for the epoch.
    pub seed: OrIgnore<Fp>,
    /// Condition on the protocol state hash at the start of the epoch.
    pub start_checkpoint: OrIgnore<StateHash>,
    /// Condition on the protocol state hash, which is updated for the first 2/3 of the epoch.
    pub lock_checkpoint: OrIgnore<StateHash>,
    /// The number of slots in the epoch that the seed has been updated for so far.
    pub epoch_length: OrIgnore<ClosedInterval<u32>>,
}

/// Condition on the Mina protocol state.
pub struct ProtocolStateCondition {
    /// Condition on the most-recently-proved ledger hash.
    pub snarked_ledger_hash: OrIgnore<Hash>,
    /// Condition on the most-recently-proved unused token ID.
    pub snarked_next_available_token: OrIgnore<ClosedInterval<token_id::TokenID>>,
    /// Condition on the timestamp of the block producer's best known block.
    pub timestamp: OrIgnore<ClosedInterval<u64>>,
    /// Condition on the number of blocks in the block producer's current chain.
    pub blockchain_length: OrIgnore<ClosedInterval<u32>>,
    /// Condition on the 'minimum window density'. This parameter is used to quantify chain health,
    /// and a more detailed description of its behavior can be found in the specification of the
    /// consensus mechanism.
    pub min_window_density: OrIgnore<ClosedInterval<u32>>,
    /// Condition in the total available currency in the ledger.
    pub total_currency: OrIgnore<ClosedInterval<u64>>,
    /// The number of 'slots' after the most recent hard-fork at which the block producer's best
    /// known block was produced.
    pub global_slot_since_hard_fork: OrIgnore<ClosedInterval<u32>>,
    /// The number of 'slots' after genesis at which the block producer's best known block was
    /// produced.
    pub global_slot_since_genesis: OrIgnore<ClosedInterval<u32>>,
    /// Condition on the current epoch's data, used for staking.
    pub staking_epoch_data: EpochDataCondition,
    /// Condition on the data for the next epoch, which will be used for staking, but which may not
    /// yet be finalized.
    pub next_epoch_data: EpochDataCondition,
}

pub struct AccountCondition {
    pub balance: OrIgnore<ClosedInterval<u64>>,
    pub nonce: OrIgnore<ClosedInterval<u32>>,
    pub receipt_chain_hash: OrIgnore<Hash>,
    pub public_key: OrIgnore<CompressedPublicKey>,
    pub delegate: OrIgnore<CompressedPublicKey>,
    pub state: [OrIgnore<Fp>; 8],
}

pub enum Account {
    Full(AccountCondition),
    Nonce(u32),
    Accept,
}