Skip to content

Commit

Permalink
feat(native-currency): Time-lock half of coinbase
Browse files Browse the repository at this point in the history
The tokenomics of Neptune Cash stipulate that half of all mining
be time-locked for three years. This commit time-locks half of the
coinbase. Half of the guesser fee is already automatically
time-locked.

Specifically, this commit modifies the tasm code for consensus program
`NativeCurrency` to verify that across all outputs (and counting half
of the transaction fee), at least half of the coinbase is time-locked
for three years.

Co-authored-by: Thorkil Schmidiger <[email protected]>
  • Loading branch information
aszepieniec and Sword-Smith committed Dec 19, 2024
1 parent f179836 commit da724fa
Show file tree
Hide file tree
Showing 6 changed files with 445 additions and 97 deletions.
8 changes: 3 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,6 @@ harness = false
[[bench]]
name = "consensus"
harness = false

[patch.crates-io]
tasm-lib = { git = "https://github.com/TritonVM/tasm-lib.git", rev = "bc50c3320b7ca7527a0066e2b28455f4b4e18003" }
18 changes: 13 additions & 5 deletions src/models/blockchain/transaction/primitive_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt::Display;
use get_size::GetSize;
use itertools::Itertools;
use num_traits::CheckedSub;
use num_traits::Zero;
use proptest::arbitrary::Arbitrary;
use proptest::collection::vec;
use proptest::strategy::BoxedStrategy;
Expand Down Expand Up @@ -439,7 +440,7 @@ impl PrimitiveWitness {
)
.prop_flat_map(
move |(
total_amount,
mut total_amount,
input_address_seeds,
input_dist,
output_address_seeds,
Expand Down Expand Up @@ -471,8 +472,12 @@ impl PrimitiveWitness {
.skip(1)
.cloned()
.sum::<NeptuneCoins>();
*input_amounts.last_mut().unwrap() =
total_amount.checked_sub(&sum_of_all_but_last).unwrap();
if let Some(last_input) = input_amounts.last_mut() {
*last_input =
total_amount.checked_sub(&sum_of_all_but_last).unwrap();
} else {
total_amount = NeptuneCoins::zero();
}

let (input_utxos, input_lock_scripts_and_witnesses) =
Self::transaction_inputs_from_address_seeds_and_amounts(
Expand Down Expand Up @@ -503,7 +508,11 @@ impl PrimitiveWitness {
.map(|utxo| utxo.get_native_currency_amount())
.sum::<NeptuneCoins>();

assert_eq!(maybe_coinbase.unwrap_or(total_inputs), total_outputs + fee);
assert_eq!(
maybe_coinbase.unwrap_or(total_inputs),
total_outputs + fee,
"total outputs: {total_outputs:?} fee: {fee:?}"
);

let output_utxos = Self::valid_tx_outputs_from_amounts_and_address_seeds(
&output_amounts,
Expand Down Expand Up @@ -1215,7 +1224,6 @@ mod test {
#[strategy(PrimitiveWitness::arbitrary_with_size_numbers(Some(2), 2, 2))]
primitive_witness: PrimitiveWitness,
) {
println!("generated primitive witness.");
let mut total = if let Some(amount) = primitive_witness.kernel.coinbase {
amount
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/models/blockchain/transaction/transaction_kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ use crate::util_types::mutator_set::removal_record::RemovalRecord;

/// TransactionKernel is immutable and its hash never changes.
///
/// See [TransactionKernelModifier] for generating modified copies.
/// See [`TransactionKernelModifier`] for generating modified copies.
#[derive(Clone, Debug, Serialize, Deserialize, Eq, GetSize, BFieldCodec, TasmObject)]
#[readonly::make]
pub struct TransactionKernel {
// note: see field descriptions in TransactionKernelProxy
// note: see field descriptions in [`TransactionKernelProxy`]
pub inputs: Vec<RemovalRecord>,
pub outputs: Vec<AdditionRecord>,
pub public_announcements: Vec<PublicAnnouncement>,
Expand Down
2 changes: 1 addition & 1 deletion src/models/blockchain/transaction/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl<'a> Arbitrary<'a> for Utxo {
}
}
#[cfg(test)]
mod utxo_tests {
mod test {
use proptest::prelude::*;
use rand::thread_rng;
use rand::Rng;
Expand Down
Loading

0 comments on commit da724fa

Please sign in to comment.