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

feat: enable revealed-value proofs #5983

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion applications/minotari_app_grpc/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ enum RangeProofType {
REVEALED_VALUE = 1;
}

message PermittedRangeProofs {
OutputType output_type = 1;
repeated RangeProofType range_proof_types = 2;
}

/// Range proof
message RangeProof {
bytes proof_bytes = 1;
Expand Down Expand Up @@ -135,5 +140,5 @@ message ConsensusConstants {
uint64 validator_node_registration_min_deposit_amount = 31;
uint64 validator_node_registration_min_lock_height = 32;
uint64 validator_node_registration_shuffle_interval_epoch = 33;
repeated RangeProofType permitted_range_proof_types = 34;
repeated PermittedRangeProofs permitted_range_proof_types = 34;
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ impl From<ConsensusConstants> for grpc::ConsensusConstants {
.map(|ot| i32::from(ot.as_byte()))
.collect::<Vec<i32>>();

let permitted_range_proof_types = cc.permitted_range_proof_types();
let permitted_range_proof_types = permitted_range_proof_types
.iter()
.map(|rpt| i32::from(rpt.as_byte()))
.collect::<Vec<i32>>();
let mut permitted_range_proof_types = Vec::with_capacity(cc.permitted_range_proof_types().len());
for (output_type, range_proof_types) in cc.permitted_range_proof_types() {
permitted_range_proof_types.push(grpc::PermittedRangeProofs {
output_type: i32::from(output_type.as_byte()),
range_proof_types: range_proof_types
.iter()
.map(|rpt| i32::from(rpt.as_byte()))
.collect::<Vec<i32>>(),
});
}

let randomx_pow = grpc::PowAlgorithmConstants {
max_difficulty: cc.max_pow_difficulty(PowAlgorithm::RandomX).as_u64(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl BlockTemplateProtocol<'_> {
&self.wallet_payment_address,
self.config.stealth_payment,
self.consensus_manager.consensus_constants(tari_height),
self.config.range_proof_type,
)
.await?;
Ok((coinbase_output, coinbase_kernel))
Expand Down
4 changes: 4 additions & 0 deletions applications/minotari_merge_mining_proxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use tari_common::{
};
use tari_common_types::tari_address::TariAddress;
use tari_comms::multiaddr::Multiaddr;
use tari_core::transactions::transaction_components::RangeProofType;

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -72,6 +73,8 @@ pub struct MergeMiningProxyConfig {
pub wallet_payment_address: String,
/// Stealth payment yes or no
pub stealth_payment: bool,
/// Range proof type - revealed_value or bullet_proof_plus: (default = bullet_proof_plus)
pub range_proof_type: RangeProofType,
}

impl Default for MergeMiningProxyConfig {
Expand All @@ -93,6 +96,7 @@ impl Default for MergeMiningProxyConfig {
network: Default::default(),
wallet_payment_address: TariAddress::default().to_hex(),
stealth_payment: true,
range_proof_type: RangeProofType::BulletProofPlus,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions applications/minotari_miner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use serde::{Deserialize, Serialize};
use tari_common::{configuration::Network, SubConfigPath};
use tari_common_types::{grpc_authentication::GrpcAuthentication, tari_address::TariAddress};
use tari_comms::multiaddr::Multiaddr;
use tari_core::transactions::transaction_components::RangeProofType;

#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -77,6 +78,8 @@ pub struct MinerConfig {
pub wallet_payment_address: String,
/// Stealth payment yes or no
pub stealth_payment: bool,
/// Range proof type - revealed_value or bullet_proof_plus: (default = bullet_proof_plus)
pub range_proof_type: RangeProofType,
}

/// The proof of work data structure that is included in the block header. For the Minotari miner only `Sha3x` is
Expand Down Expand Up @@ -110,6 +113,7 @@ impl Default for MinerConfig {
wait_timeout_on_error: 10,
wallet_payment_address: TariAddress::default().to_hex(),
stealth_payment: true,
range_proof_type: RangeProofType::BulletProofPlus,
hansieodendaal marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
1 change: 1 addition & 0 deletions applications/minotari_miner/src/run_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ async fn mining_cycle(
wallet_payment_address,
config.stealth_payment,
consensus_manager.consensus_constants(height),
config.range_proof_type,
)
.await
.map_err(|e| MinerError::CoinbaseError(e.to_string()))?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ async fn create_next_block(
key_manager,
script_key_id,
wallet_payment_address,
None,
)
.await;
let block = apply_mmr_to_block(db, block);
Expand Down
109 changes: 101 additions & 8 deletions base_layer/core/src/consensus/consensus_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub struct ConsensusConstants {
/// An allowlist of output types
permitted_output_types: &'static [OutputType],
/// The allowlist of range proof types
permitted_range_proof_types: &'static [RangeProofType],
permitted_range_proof_types: [(OutputType, &'static [RangeProofType]); 5],
/// Coinbase outputs are allowed to have metadata, but it has the following length limit
coinbase_output_features_extra_max_length: u32,
/// Maximum number of token elements permitted in covenants
Expand Down Expand Up @@ -305,7 +305,7 @@ impl ConsensusConstants {
}

/// Returns the permitted range proof types
pub fn permitted_range_proof_types(&self) -> &[RangeProofType] {
pub fn permitted_range_proof_types(&self) -> [(OutputType, &[RangeProofType]); 5] {
self.permitted_range_proof_types
}

Expand Down Expand Up @@ -379,7 +379,7 @@ impl ConsensusConstants {
output_version_range,
kernel_version_range,
permitted_output_types: OutputType::all(),
permitted_range_proof_types: RangeProofType::all(),
permitted_range_proof_types: Self::all_range_proof_types(),
max_covenant_length: 100,
vn_epoch_length: 10,
vn_validity_period_epochs: VnEpoch(100),
Expand Down Expand Up @@ -442,7 +442,7 @@ impl ConsensusConstants {
kernel_version_range,
// igor is the first network to support the new output types
permitted_output_types: OutputType::all(),
permitted_range_proof_types: RangeProofType::all(),
permitted_range_proof_types: Self::all_range_proof_types(),
max_covenant_length: 100,
vn_epoch_length: 10,
vn_validity_period_epochs: VnEpoch(3),
Expand Down Expand Up @@ -672,8 +672,33 @@ impl ConsensusConstants {
&[OutputType::Coinbase, OutputType::Standard, OutputType::Burn]
}

const fn current_permitted_range_proof_types() -> &'static [RangeProofType] {
&[RangeProofType::BulletProofPlus]
const fn current_permitted_range_proof_types() -> [(OutputType, &'static [RangeProofType]); 5] {
[
(OutputType::Standard, &[RangeProofType::BulletProofPlus]),
(OutputType::Coinbase, &[
RangeProofType::BulletProofPlus,
RangeProofType::RevealedValue,
]),
(OutputType::Burn, &[
RangeProofType::BulletProofPlus,
RangeProofType::RevealedValue,
]),
(OutputType::ValidatorNodeRegistration, &[
RangeProofType::BulletProofPlus,
RangeProofType::RevealedValue,
]),
(OutputType::CodeTemplateRegistration, &[RangeProofType::BulletProofPlus]),
]
}

hansieodendaal marked this conversation as resolved.
Show resolved Hide resolved
const fn all_range_proof_types() -> [(OutputType, &'static [RangeProofType]); 5] {
[
(OutputType::Standard, RangeProofType::all()),
(OutputType::Coinbase, RangeProofType::all()),
(OutputType::Burn, RangeProofType::all()),
(OutputType::ValidatorNodeRegistration, RangeProofType::all()),
(OutputType::CodeTemplateRegistration, RangeProofType::all()),
]
}
}

Expand Down Expand Up @@ -838,7 +863,10 @@ impl ConsensusConstantsBuilder {
self
}

pub fn with_permitted_range_proof_types(mut self, permitted_range_proof_types: &'static [RangeProofType]) -> Self {
pub fn with_permitted_range_proof_types(
mut self,
permitted_range_proof_types: [(OutputType, &'static [RangeProofType]); 5],
) -> Self {
self.consensus.permitted_range_proof_types = permitted_range_proof_types;
self
}
Expand All @@ -862,7 +890,10 @@ mod test {
emission::{Emission, EmissionSchedule},
ConsensusConstants,
},
transactions::tari_amount::{uT, MicroMinotari},
transactions::{
tari_amount::{uT, MicroMinotari},
transaction_components::{OutputType, RangeProofType},
},
};

#[test]
Expand Down Expand Up @@ -938,4 +969,66 @@ mod test {
previous_reward = reward;
}
}

// This function is to ensure all OutputType variants are assessed in the tests
fn cycle_output_type_enum(output_type: OutputType) -> OutputType {
match output_type {
OutputType::Standard => OutputType::Coinbase,
OutputType::Coinbase => OutputType::Burn,
OutputType::Burn => OutputType::ValidatorNodeRegistration,
OutputType::ValidatorNodeRegistration => OutputType::CodeTemplateRegistration,
OutputType::CodeTemplateRegistration => OutputType::Standard,
}
}

// This function is to ensure all RangeProofType variants are assessed in the tests
fn cycle_range_proof_type_enum(range_proof_type: RangeProofType) -> RangeProofType {
match range_proof_type {
RangeProofType::BulletProofPlus => RangeProofType::RevealedValue,
RangeProofType::RevealedValue => RangeProofType::BulletProofPlus,
}
}

#[test]
fn range_proof_types_coverage() {
let mut output_type_enums = vec![OutputType::Standard];
loop {
let next_variant = cycle_output_type_enum(*output_type_enums.last().unwrap());
if output_type_enums.contains(&next_variant) {
break;
}
output_type_enums.push(next_variant);
}

let mut range_proof_type_enums = vec![RangeProofType::BulletProofPlus];
loop {
let next_variant = cycle_range_proof_type_enum(*range_proof_type_enums.last().unwrap());
if range_proof_type_enums.contains(&next_variant) {
break;
}
range_proof_type_enums.push(next_variant);
}

let permitted_range_proof_types = ConsensusConstants::current_permitted_range_proof_types().to_vec();
for item in &output_type_enums {
let entries = permitted_range_proof_types
.iter()
.filter(|&&x| x.0 == *item)
.collect::<Vec<_>>();
assert_eq!(entries.len(), 1);
assert!(!entries[0].1.is_empty());
}

let permitted_range_proof_types = ConsensusConstants::all_range_proof_types().to_vec();
for output_type in &output_type_enums {
let entries = permitted_range_proof_types
.iter()
.filter(|&&x| x.0 == *output_type)
.collect::<Vec<_>>();
assert_eq!(entries.len(), 1);
for range_proof_type in &range_proof_type_enums {
assert!(entries[0].1.iter().any(|&x| x == *range_proof_type));
}
}
}
}
13 changes: 12 additions & 1 deletion base_layer/core/src/test_helpers/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ use crate::{
test_helpers::{block_spec::BlockSpecs, create_consensus_rules, default_coinbase_entities, BlockSpec},
transactions::{
key_manager::{create_memory_db_key_manager, MemoryDbKeyManager, TariKeyId},
transaction_components::{TransactionInput, TransactionKernel, TransactionOutput, WalletOutput},
transaction_components::{
RangeProofType,
TransactionInput,
TransactionKernel,
TransactionOutput,
WalletOutput,
},
CryptoFactories,
},
validation::{
Expand Down Expand Up @@ -440,6 +446,7 @@ pub async fn create_chained_blocks<T: Into<BlockSpecs>>(
&km,
&script_key_id,
&wallet_payment_address,
None,
)
.await;
let block = mine_block(block, prev_block.accumulated_data(), difficulty);
Expand Down Expand Up @@ -504,6 +511,7 @@ pub struct TestBlockchain {
pub km: MemoryDbKeyManager,
script_key_id: TariKeyId,
wallet_payment_address: TariAddress,
range_proof_type: RangeProofType,
}

impl TestBlockchain {
Expand All @@ -523,6 +531,7 @@ impl TestBlockchain {
km,
script_key_id,
wallet_payment_address,
range_proof_type: RangeProofType::BulletProofPlus,
};

blockchain.chain.push(("GB", genesis));
Expand Down Expand Up @@ -627,6 +636,7 @@ impl TestBlockchain {
&self.km,
&self.script_key_id,
&self.wallet_payment_address,
Some(self.range_proof_type),
)
.await;
let block = mine_block(block, parent.accumulated_data(), difficulty);
Expand All @@ -645,6 +655,7 @@ impl TestBlockchain {
&self.km,
&self.script_key_id,
&self.wallet_payment_address,
Some(self.range_proof_type),
)
.await;
block.body.sort();
Expand Down
4 changes: 3 additions & 1 deletion base_layer/core/src/test_helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use crate::{
generate_coinbase_with_wallet_output,
key_manager::{MemoryDbKeyManager, TariKeyId},
tari_amount::MicroMinotari,
transaction_components::{Transaction, WalletOutput},
transaction_components::{RangeProofType, Transaction, WalletOutput},
},
};

Expand Down Expand Up @@ -86,6 +86,7 @@ pub async fn create_block(
km: &MemoryDbKeyManager,
script_key_id: &TariKeyId,
wallet_payment_address: &TariAddress,
range_proof_type: Option<RangeProofType>,
) -> (Block, WalletOutput) {
let mut header = BlockHeader::from_previous(&prev_block.header);
let block_height = spec.height_override.unwrap_or(prev_block.header.height + 1);
Expand Down Expand Up @@ -113,6 +114,7 @@ pub async fn create_block(
wallet_payment_address,
false,
rules.consensus_constants(header.height),
range_proof_type.unwrap_or(RangeProofType::BulletProofPlus),
)
.await
.unwrap();
Expand Down
Loading
Loading