Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
resolver="2"

members = [
"protocol",
"consensus",
"p2p",
"locks",
"database",
Expand Down
2 changes: 1 addition & 1 deletion composer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "Apache-2.0"
repository = "https://github.com/Nyksnet/nyksnode/"

[dependencies]
nyks-protocol = { version = "0.8.0", path = "../protocol" }
nyks-consensus = { version = "0.8.0", path = "../consensus" }
nyks-standards = { version = "0.8.0", path = "../standards" }
nyks-rpc-client = { version = "0.8.0", path = "../rpc/client" }
nyks-wallet-core = { version = "0.8.0", path = "../wallet/core" }
Expand Down
2 changes: 1 addition & 1 deletion composer/src/composer/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use nyks_protocol::consensus::block::Block;
use nyks_consensus::block::Block;
use nyks_prover::{JobCancelReceiver, JobCancelSender, ProverJobSettings};
use thiserror::Error;
use tokio::sync::watch;
Expand Down
26 changes: 13 additions & 13 deletions composer/src/composer/prover/block.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use nyks_protocol::consensus::block::Block;
use nyks_protocol::consensus::block::BlockProof;
use nyks_protocol::consensus::block::block_appendix::BlockAppendix;
use nyks_protocol::consensus::block::block_transaction::BlockTransaction;
use nyks_protocol::consensus::block::validity::block_primitive_witness::BlockPrimitiveWitness;
use nyks_protocol::consensus::block::validity::block_program::BlockProgram;
use nyks_protocol::consensus::block::validity::block_proof_witness::BlockProofWitness;
use nyks_protocol::consensus::consensus_rule_set::ConsensusRuleSet;
use nyks_protocol::proof_abstractions::SecretWitness;
use nyks_protocol::proof_abstractions::mast_hash::MastHash;
use nyks_protocol::proof_abstractions::tasm::program::TritonProgram;
use nyks_protocol::proof_abstractions::timestamp::Timestamp;
use nyks_protocol::proof_abstractions::verifier::verify;
use nyks_consensus::block::Block;
use nyks_consensus::block::BlockProof;
use nyks_consensus::block::block_appendix::BlockAppendix;
use nyks_consensus::block::block_transaction::BlockTransaction;
use nyks_consensus::block::validity::block_primitive_witness::BlockPrimitiveWitness;
use nyks_consensus::block::validity::block_program::BlockProgram;
use nyks_consensus::block::validity::block_proof_witness::BlockProofWitness;
use nyks_consensus::consensus_rule_set::ConsensusRuleSet;
use nyks_consensus::proof_abstractions::SecretWitness;
use nyks_consensus::proof_abstractions::mast_hash::MastHash;
use nyks_consensus::proof_abstractions::tasm::program::TritonProgram;
use nyks_consensus::proof_abstractions::timestamp::Timestamp;
use nyks_consensus::proof_abstractions::verifier::verify;
use nyks_prover::JobCancelReceiver;
use nyks_prover::ProverJob;
use nyks_prover::ProverJobSettings;
Expand Down
32 changes: 16 additions & 16 deletions composer/src/composer/prover/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use num_traits::CheckedSub;
use num_traits::Zero;
use nyks_protocol::consensus::block::Block;
use nyks_protocol::consensus::block::block_transaction::BlockOrRegularTransaction;
use nyks_protocol::consensus::block::block_transaction::BlockTransaction;
use nyks_protocol::consensus::consensus_rule_set::ConsensusRuleSet;
use nyks_protocol::consensus::transaction::Transaction;
use nyks_protocol::consensus::transaction::TransactionProof;
use nyks_protocol::consensus::transaction::validity::neptune_proof::Proof;
use nyks_protocol::consensus::transaction::validity::single_proof::SingleProof;
use nyks_protocol::consensus::transaction::validity::single_proof::SingleProofWitness;
use nyks_protocol::consensus::type_scripts::native_currency_amount::NativeCurrencyAmount;
use nyks_protocol::proof_abstractions::SecretWitness;
use nyks_protocol::proof_abstractions::tasm::program::TritonProgram;
use nyks_protocol::proof_abstractions::timestamp::Timestamp;
use nyks_consensus::block::Block;
use nyks_consensus::block::block_transaction::BlockOrRegularTransaction;
use nyks_consensus::block::block_transaction::BlockTransaction;
use nyks_consensus::consensus_rule_set::ConsensusRuleSet;
use nyks_consensus::proof_abstractions::SecretWitness;
use nyks_consensus::proof_abstractions::tasm::program::TritonProgram;
use nyks_consensus::proof_abstractions::timestamp::Timestamp;
use nyks_consensus::transaction::Transaction;
use nyks_consensus::transaction::TransactionProof;
use nyks_consensus::transaction::validity::nyks_proof::NyksProof;
use nyks_consensus::transaction::validity::single_proof::SingleProof;
use nyks_consensus::transaction::validity::single_proof::SingleProofWitness;
use nyks_consensus::type_scripts::native_currency_amount::NativeCurrencyAmount;
use nyks_prover::JobCancelReceiver;
use nyks_prover::ProverJob;
use nyks_prover::ProverJobSettings;
Expand Down Expand Up @@ -239,10 +239,10 @@ impl TransactionProver {
/// kills the worker process rather than just stopping our wait on it.
async fn prove_single(
&self,
claim: nyks_protocol::triton_vm::proof::Claim,
nondeterminism: nyks_protocol::triton_vm::vm::NonDeterminism,
claim: nyks_consensus::triton_vm::proof::Claim,
nondeterminism: nyks_consensus::triton_vm::vm::NonDeterminism,
rx: JobCancelReceiver,
) -> Result<Proof, TransactionProverError> {
) -> Result<NyksProof, TransactionProverError> {
let job = ProverJob::new(
SingleProof.program(),
claim,
Expand Down
10 changes: 5 additions & 5 deletions composer/src/core/args.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use clap::Parser;
use num_traits::CheckedSub;
use num_traits::Zero;
use nyks_protocol::consensus::block::MINING_REWARD_TIME_LOCK_PERIOD;
use nyks_protocol::consensus::network::Network;
use nyks_protocol::consensus::type_scripts::native_currency_amount::NativeCurrencyAmount;
use nyks_protocol::proof_abstractions::timestamp::Timestamp;
use nyks_protocol::tasm_lib::prelude::Digest;
use nyks_consensus::block::MINING_REWARD_TIME_LOCK_PERIOD;
use nyks_consensus::network::Network;
use nyks_consensus::proof_abstractions::timestamp::Timestamp;
use nyks_consensus::tasm_lib::prelude::Digest;
use nyks_consensus::type_scripts::native_currency_amount::NativeCurrencyAmount;
use nyks_standards::wallet::keys::address::Address;
use nyks_standards::wallet::keys::address::Recipient;
use nyks_wallet_core::transaction::builder::output::TxOutput;
Expand Down
4 changes: 2 additions & 2 deletions protocol/Cargo.toml → consensus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nyks-protocol"
description = "protocol types of nyks"
name = "nyks-consensus"
description = "consensus types of nyks"
authors = ["Triton Software"]
version = "0.8.0"
edition = "2024"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use tasm_lib::triton_vm::prelude::BFieldElement;
use tasm_lib::twenty_first::math::bfield_codec::BFieldCodec;

use super::block_body::BlockBody;
use crate::consensus::block::Claim;
use crate::consensus::block::Tip5;
use crate::consensus::consensus_rule_set::ConsensusRuleSet;
use crate::consensus::transaction::validity::single_proof::single_proof_claim;
use crate::block::Claim;
use crate::block::Tip5;
use crate::consensus_rule_set::ConsensusRuleSet;
use crate::proof_abstractions::mast_hash::MastHash;
use crate::transaction::validity::single_proof::single_proof_claim;

pub const MAX_NUM_CLAIMS: usize = 500;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use tasm_lib::twenty_first::math::bfield_codec::BFieldCodec;
use tasm_lib::twenty_first::prelude::MerkleTree;
use tasm_lib::twenty_first::util_types::mmr::mmr_accumulator::MmrAccumulator;

use crate::consensus::block::block_validation_error::BlockValidationError;
use crate::consensus::block::mutator_set_update::MutatorSetUpdate;
use crate::consensus::mutator_set::addition_record::AdditionRecord;
use crate::consensus::mutator_set::mutator_set_accumulator::MutatorSetAccumulator;
use crate::consensus::transaction::transaction_kernel::TransactionKernel;
use crate::consensus::type_scripts::native_currency_amount::NativeCurrencyAmount;
use crate::block::block_validation_error::BlockValidationError;
use crate::block::mutator_set_update::MutatorSetUpdate;
use crate::mutator_set::addition_record::AdditionRecord;
use crate::mutator_set::mutator_set_accumulator::MutatorSetAccumulator;
use crate::prelude::twenty_first;
use crate::proof_abstractions::mast_hash::HasDiscriminant;
use crate::proof_abstractions::mast_hash::MastHash;
use crate::transaction::transaction_kernel::TransactionKernel;
use crate::type_scripts::native_currency_amount::NativeCurrencyAmount;

#[derive(Debug, Copy, Clone, EnumCount)]
pub enum BlockBodyField {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ use super::block_height::BlockHeight;
use super::difficulty_control::Difficulty;
use super::difficulty_control::ProofOfWork;
use super::difficulty_control::difficulty_control;
use crate::consensus::block::guesser_receiver_data::GuesserReceiverData;
use crate::consensus::block::pow::Pow;
use crate::consensus::network::Network;
use crate::block::guesser_receiver_data::GuesserReceiverData;
use crate::block::pow::Pow;
use crate::network::Network;
use crate::proof_abstractions::mast_hash::HasDiscriminant;
use crate::proof_abstractions::mast_hash::MastHash;
use crate::proof_abstractions::timestamp::Timestamp;

pub const BLOCK_HEADER_VERSION: BFieldElement = BFieldElement::new(0);

pub type BlockPow = Pow<{ crate::consensus::block::pow::POW_MEMORY_TREE_HEIGHT }>;
pub type BlockPow = Pow<{ crate::block::pow::POW_MEMORY_TREE_HEIGHT }>;

#[derive(
Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, BFieldCodec, TasmObject, GetSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use tasm_lib::twenty_first::math::bfield_codec::BFieldCodec;
use super::block_appendix::BlockAppendix;
use super::block_body::BlockBody;
use super::block_header::BlockHeader;
use crate::consensus::block::block_validation_error::BlockValidationError;
use crate::consensus::block::mutator_set_update::MutatorSetUpdate;
use crate::consensus::mutator_set::addition_record::AdditionRecord;
use crate::consensus::mutator_set::commit;
use crate::consensus::mutator_set::removal_record::removal_record_list::RemovalRecordList;
use crate::consensus::transaction::utxo::Utxo;
use crate::block::block_validation_error::BlockValidationError;
use crate::block::mutator_set_update::MutatorSetUpdate;
use crate::mutator_set::addition_record::AdditionRecord;
use crate::mutator_set::commit;
use crate::mutator_set::removal_record::removal_record_list::RemovalRecordList;
use crate::proof_abstractions::mast_hash::HasDiscriminant;
use crate::proof_abstractions::mast_hash::MastHash;
use crate::transaction::utxo::Utxo;

/// The kernel of a block contains all data that is not proof data
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, BFieldCodec, GetSize)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::ops::Deref;

use crate::consensus::consensus_rule_set::ConsensusRuleSet;
use crate::consensus::transaction::Transaction;
use crate::consensus::transaction::TransactionProof;
use crate::consensus::transaction::transaction_kernel::TransactionKernel;
use crate::consensus::transaction::validity::tasm::single_proof::merge_branch::MergeWitness;
use crate::consensus_rule_set::ConsensusRuleSet;
use crate::transaction::Transaction;
use crate::transaction::TransactionProof;
use crate::transaction::transaction_kernel::TransactionKernel;
use crate::transaction::validity::tasm::single_proof::merge_branch::MergeWitness;

/// Newtype for [`TransactionKernel`] where removal records are packed. For use
/// in the context of [`BlockTransaction`]s. See [`BlockTransaction`] for more
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::consensus::mutator_set::removal_record::removal_record_list::RemovalRecordListUnpackError;
use crate::mutator_set::removal_record::removal_record_list::RemovalRecordListUnpackError;

/// The reasons why a [`Block`](crate::consensus::block::Block) can be
/// The reasons why a [`Block`](crate::block::Block) can be
/// invalid.
///
/// Conversely, defines what it means for a block to be "valid".
Expand Down
49 changes: 24 additions & 25 deletions protocol/src/consensus/block/mod.rs → consensus/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ use validity::block_program::BlockProgram;

use super::transaction::transaction_kernel::TransactionKernelProxy;
use super::type_scripts::native_currency_amount::NativeCurrencyAmount;
use crate::consensus::block::block_header::BlockHeaderField;
use crate::consensus::block::block_header::BlockPow;
use crate::consensus::block::block_kernel::BlockKernelField;
use crate::consensus::block::difficulty_control::difficulty_control;
use crate::consensus::block::pow::PowMastPaths;
use crate::consensus::consensus_rule_set::ConsensusRuleSet;
use crate::consensus::mutator_set::addition_record::AdditionRecord;
use crate::consensus::mutator_set::mutator_set_accumulator::MutatorSetAccumulator;
use crate::consensus::mutator_set::removal_record::removal_record_list::RemovalRecordList;
use crate::consensus::network::Network;
use crate::consensus::transaction::validity::neptune_proof::Proof;
use crate::block::block_header::BlockHeaderField;
use crate::block::block_header::BlockPow;
use crate::block::block_kernel::BlockKernelField;
use crate::block::difficulty_control::difficulty_control;
use crate::block::pow::PowMastPaths;
use crate::consensus_rule_set::ConsensusRuleSet;
use crate::mutator_set::addition_record::AdditionRecord;
use crate::mutator_set::mutator_set_accumulator::MutatorSetAccumulator;
use crate::mutator_set::removal_record::removal_record_list::RemovalRecordList;
use crate::network::Network;
use crate::proof_abstractions::mast_hash::HasDiscriminant;
use crate::proof_abstractions::mast_hash::MastHash;
use crate::proof_abstractions::timestamp::Timestamp;
use crate::transaction::validity::nyks_proof::NyksProof;

/// With removal records only represented by their absolute index set, the block
/// size limit of 1.000.000 `BFieldElement`s allows for a "balanced" block
Expand Down Expand Up @@ -187,7 +187,7 @@ pub enum BlockProof {
Genesis,
#[default]
Invalid,
SingleProof(Proof),
SingleProof(NyksProof),
}

/// Public fields of `Block` are read-only, enforced by #[readonly::make].
Expand All @@ -199,7 +199,7 @@ pub enum BlockProof {
/// internals directly (bypassing encapsulation)
///
/// ```compile_fail,E0594
/// use nyks_node::protocol::consensus::block::Block;
/// use nyks_node::protocol::block::Block;
/// use nyks_node::application::config::network::Network;
/// use nyks_node::prelude::twenty_first::math::b_field_element::BFieldElement;
/// use tasm_lib::prelude::Digest;
Expand Down Expand Up @@ -731,14 +731,18 @@ impl Block {
return true;
}

let threshold = self.header().difficulty.target();
if network.allows_mock_pow() && self.is_valid_mock_pow(threshold) {
// Reject values that the difficulty control mechanism can never
// produce, rather than dividing by zero.
if self.header().difficulty < Difficulty::MINIMUM {
return false;
}

let target = self.header().difficulty.target();
if network.allows_mock_pow() && self.is_valid_mock_pow(target) {
return true;
}

let consensus_rule_set =
ConsensusRuleSet::infer_from(network, previous_block_header.height.next());
self.pow_verify(threshold, consensus_rule_set)
self.pow_verify(target)
}

/// Produce the MAST authentication paths for the `pow` field on
Expand Down Expand Up @@ -783,16 +787,11 @@ impl Block {
}

/// Verify that block digest is less than threshold and integral.
pub fn pow_verify(&self, target: Digest, consensus_rule_set: ConsensusRuleSet) -> bool {
pub fn pow_verify(&self, target: Digest) -> bool {
let auth_paths = self.pow_mast_paths();
self.header()
.pow
.validate(
auth_paths,
target,
consensus_rule_set,
self.header().prev_block_digest,
)
.validate(auth_paths, target, self.header().prev_block_digest)
.is_ok()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use anyhow::Result;
use serde::Deserialize;
use serde::Serialize;

use crate::consensus::mutator_set::addition_record::AdditionRecord;
use crate::consensus::mutator_set::authenticated_item::AuthenticatedItem;
use crate::consensus::mutator_set::mutator_set_accumulator::MutatorSetAccumulator;
use crate::consensus::mutator_set::removal_record::RemovalRecord;
use crate::mutator_set::addition_record::AdditionRecord;
use crate::mutator_set::authenticated_item::AuthenticatedItem;
use crate::mutator_set::mutator_set_accumulator::MutatorSetAccumulator;
use crate::mutator_set::removal_record::RemovalRecord;

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct MutatorSetUpdate {
Expand Down
16 changes: 6 additions & 10 deletions protocol/src/consensus/block/pow.rs → consensus/src/block/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use tasm_lib::triton_vm::prelude::BFieldCodec;
use tasm_lib::twenty_first::bfe_array;

use crate::BFieldElement;
use crate::consensus::block::Block;
use crate::consensus::block::block_header::BlockHeader;
use crate::consensus::block::block_kernel::BlockKernel;
use crate::consensus::consensus_rule_set::ConsensusRuleSet;
use crate::block::Block;
use crate::block::block_header::BlockHeader;
use crate::block::block_kernel::BlockKernel;
use crate::consensus_rule_set::ConsensusRuleSet;
use crate::proof_abstractions::mast_hash::MastHash;

/// Determines the number of leafs in the Merkle tree in the guesser buffer.
Expand Down Expand Up @@ -444,12 +444,8 @@ impl<const MERKLE_TREE_HEIGHT: usize> Pow<MERKLE_TREE_HEIGHT> {
self,
auth_paths: PowMastPaths,
target: Digest,
consensus_rule_set: ConsensusRuleSet,
parent_digest: Digest,
) -> Result<(), PowValidationError> {
let leaf_prefix = match consensus_rule_set {
ConsensusRuleSet::Launch => parent_digest,
};
let index_picker_preimage = Tip5::hash_pair(self.root, auth_paths.commit());
let (index_a, index_b) = Self::indices(index_picker_preimage, self.nonce);

Expand All @@ -463,8 +459,8 @@ impl<const MERKLE_TREE_HEIGHT: usize> Pow<MERKLE_TREE_HEIGHT> {
Self::MERKLE_TREE_HEIGHT as u32,
));
(
Self::leaf(leaf_prefix, index_a),
Self::leaf(leaf_prefix, index_b),
Self::leaf(parent_digest, index_a),
Self::leaf(parent_digest, index_b),
)
};

Expand Down
Loading
Loading