iuna

iuna

iuna - experimental mainnet-candidate protocol
git clone https://getiuna.org/git/iuna.git
Log | Files | Refs | README | LICENSE

domain.rs (5466B)


      1 use std::collections::BTreeSet;
      2 
      3 mod address;
      4 #[cfg(test)]
      5 mod adversarial_tests;
      6 mod block;
      7 #[cfg(test)]
      8 mod consolidation_tests;
      9 mod error;
     10 mod fork;
     11 mod genesis;
     12 mod hex;
     13 mod ledger_apply;
     14 mod ledger_builders;
     15 mod ledger_chain;
     16 mod ledger_consensus;
     17 mod ledger_lineage;
     18 mod ledger_mempool;
     19 mod ledger_ops;
     20 mod ledger_pending;
     21 mod ledger_prepare;
     22 mod ledger_queries;
     23 mod ledger_reveal;
     24 mod ledger_state;
     25 mod ledger_v2;
     26 mod mine_policy;
     27 mod mining;
     28 mod profile;
     29 mod protocol;
     30 mod reveal;
     31 mod selection;
     32 mod signature;
     33 mod stratum;
     34 mod ticket;
     35 mod transaction;
     36 mod transaction_v2;
     37 mod validation;
     38 mod vdf;
     39 mod wallet;
     40 pub use address::{
     41     AddressNetwork, AddressVersion, VersionedAddress, decode_address, decode_versioned_address,
     42     encode_address, encode_versioned_address, migrate_legacy_address,
     43 };
     44 use block::LeaderProofPayload;
     45 pub use block::{
     46     Block, BurnLeaderRank, ChainSnapshot, ChainStatus, FinalizerMode, LeaderProof, PreparedBlock,
     47 };
     48 pub(crate) use error::{ValidationError, error_has_validation};
     49 use fork::{FinalityCheckpoint, LeaderScore};
     50 pub(crate) use genesis::genesis_allocation_outpoint;
     51 pub use hex::hex_hash;
     52 pub(crate) use hex::{decode_hex, decode_hex_array, hex_encode};
     53 pub use ledger_builders::HYBRID_EXTERNAL_ADDRESS_GAP_LIMIT;
     54 use ledger_lineage::{
     55     LineageOwnerValues, UtxoLineageRoot, attach_existing_output_lineage,
     56     insert_output_with_lineage, newest_lineage_root, output_lineage_root_for_transaction,
     57     remove_spent_output_lineage, spend_inputs_with_lineage,
     58 };
     59 pub use ledger_ops::reward_outputs_for_block;
     60 use ledger_ops::{
     61     apply_transaction, credit_reward_output, ensure_block_has_burn, ensure_block_has_burn_from,
     62     recovery_vdf_seed_for_child, validate_genesis_burn_transaction, vdf_content_commitment,
     63     vdf_seed_for_child,
     64 };
     65 pub use ledger_state::Ledger;
     66 use ledger_state::unix_now_ms;
     67 pub(crate) use mine_policy::{MINE_RETARGET_WINDOW_BLOCKS, retarget_mine_difficulty_bits};
     68 use mining::{mine_payload, mine_signature};
     69 pub use profile::{GenesisBurn, LaunchProfile};
     70 pub use protocol::{
     71     Amount, BLOCK_REWARD, BURN_COMMITTEE_SIZE, BURN_LINEAGE_MATURITY_HEIGHTS, DEFAULT_FEE_PER_BYTE,
     72     DEFAULT_MINE_FEE, DEFAULT_TRANSACTION_FEE, GRINDING_RESISTANCE_ACTIVATION_HEIGHT,
     73     HYBRID_REWARD_ACTIVATION_HEIGHT, MAX_BLOCK_BYTES, MAX_BURN_BUNDLE_BYTES,
     74     MAX_PENDING_TRANSACTIONS, MAX_VDF_ROUNDS, MICRO_IUNA, MINE_ACTIONS_PER_ANCHOR_LIMIT,
     75     MINE_DIFFICULTY_BITS, MINE_FINALIZER_FEE, MINE_REWARD, OBJECTIVE_FINALITY_ACTIVATION_HEIGHT,
     76     RECOVERY_BLOCK_DELAY_MS, TIP_BOUND_BURN_ACTIVATION_HEIGHT,
     77     TRANSACTION_REPLAY_PROTECTION_ACTIVATION_HEIGHT, TRANSACTION_SIGNING_V1_ACTIVATION_HEIGHT,
     78     TransactionSubmitOutcome, VDF_TARGET_BLOCK_MS,
     79 };
     80 use protocol::{
     81     BLOCK_MEDIAN_TIME_PAST_WINDOW, DEFAULT_TICKET_EXPIRY_WINDOW, DEFAULT_TICKET_MATURITY_DELAY,
     82     FORK_FINALITY_DEPTH, HASH_BYTES, MAX_BLOCK_TIMESTAMP_FUTURE_DRIFT_MS, MAX_BLOCK_TRANSACTIONS,
     83     MAX_ORPHAN_TRANSACTIONS, MAX_PENDING_POOL_BYTES, PUBLIC_KEY_BYTES, SIGNATURE_BYTES,
     84 };
     85 use reveal::BurnBundlePayload;
     86 pub use reveal::{
     87     BurnBundle, BurnBundleSection, BurnBundleSignature, BurnCommitteeMember, MaskedBurn,
     88     MaskedBurnV2, default_burn_bundle_hash,
     89 };
     90 use selection::BlockSelection;
     91 pub use signature::{ProtocolPublicKey, ProtocolSignature, SignatureScheme};
     92 pub(crate) use signature::{
     93     ed25519_public_key, ml_dsa44_public_key, sign_ed25519, sign_ml_dsa44,
     94     validate_ed25519_public_key, verify_ed25519, verify_ml_dsa44,
     95 };
     96 
     97 #[cfg(feature = "fuzzing")]
     98 pub fn fuzz_verify_ml_dsa44(public_key: &[u8], payload: &[u8], signature: &[u8]) {
     99     let Ok(public_key) = <&[u8; 1_312]>::try_from(public_key) else {
    100         return;
    101     };
    102     let Ok(signature) = <&[u8; 2_420]>::try_from(signature) else {
    103         return;
    104     };
    105     let _ = verify_ml_dsa44(public_key, payload, signature, "fuzz input");
    106 }
    107 pub use stratum::{
    108     STRATUM_EXTRANONCE1_HEX, STRATUM_EXTRANONCE2_SIZE, StratumMineShare, StratumMineTemplate,
    109     pack_stratum_nonce,
    110 };
    111 use stratum::{hash_meets_difficulty, stratum_mine_header_bytes, stratum_mine_signature};
    112 use ticket::{BurnTicket, ticket_block_min_timestamp};
    113 pub use transaction::{
    114     MineSearchOutcome, OutPoint, TRANSACTION_SIGNING_FORMAT_VERSION, Transaction, TxInput, TxOutput,
    115 };
    116 use transaction::{TransactionSigningDomain, mine_signing_bytes};
    117 pub use transaction_v2::{
    118     LegacyTransactionId, TRANSACTION_V2_ACTIVATION_HEIGHT, TRANSACTION_V2_WIRE_VERSION,
    119     TransactionV2, TransactionV2Domain, TransactionV2Input, TransactionV2LegacyInput,
    120     TransactionV2Output, V2SpendingAuthorization, ensure_transaction_v2_active,
    121     hybrid_key_commitment_address, transaction_v2_is_active,
    122 };
    123 pub(crate) use validation::minimum_transfer_economic_size_bytes;
    124 pub use validation::validate_address;
    125 use validation::{
    126     canonical_transaction_size_bytes, validate_hash, validate_protocol_id, validate_signature,
    127 };
    128 #[cfg(feature = "e2e")]
    129 pub use vdf::configure_e2e_vdf_round_divisor_for_tests;
    130 pub use vdf::{
    131     VdfProgress, VdfProgressPhase, run_vdf, run_vdf_cancellable_with_progress,
    132     run_vdf_with_progress, verify_vdf,
    133 };
    134 pub use wallet::{HybridAddressBranch, Wallet};
    135 
    136 pub fn burn_committee_slot_count(eligible_rank_count: usize) -> usize {
    137     eligible_rank_count.min(BURN_COMMITTEE_SIZE)
    138 }
    139 
    140 pub fn burn_committee_slot_count_for_owners<'a>(
    141     owners: impl IntoIterator<Item = &'a str>,
    142 ) -> usize {
    143     burn_committee_slot_count(owners.into_iter().collect::<BTreeSet<_>>().len())
    144 }