From b17ab28406e7ca9d0086f59753e57e8c6c0188fd Mon Sep 17 00:00:00 2001 From: microproofs Date: Sun, 17 Dec 2023 22:40:14 -0500 Subject: [PATCH] chore: some minor updates --- lib/hardfork.ak | 20 +++++++++++++++++--- lib/hardfork/params.ak | 4 ++++ validators/hard_fork.ak | 10 ++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/hardfork.ak b/lib/hardfork.ak index 406beaa..be7e391 100644 --- a/lib/hardfork.ak +++ b/lib/hardfork.ak @@ -14,8 +14,9 @@ use hardfork/hftypes.{ LockState, MinerLockInit, MinerLockMore, MinerLockState, NftState, NotForked, } use hardfork/params.{ - miner_hardfork_threshold, tuna_count_blocks_from, - tuna_hardfork_threshold_denominator, tuna_hardfork_threshold_numerator, + hardfork_block_height, hardfork_next_hash, miner_hardfork_threshold, + tuna_count_blocks_from, tuna_hardfork_threshold_denominator, + tuna_hardfork_threshold_numerator, } pub const miner_lock_state_token: ByteArray = "miner_lock_state" @@ -25,8 +26,11 @@ pub const lock_state_token: ByteArray = "lock_state" pub const hard_fork_state_token: ByteArray = "hfs" pub fn initialize( + // Input initializer_input: OutputReference, + // Tx transaction: Transaction, + // Purpose own_policy: ByteArray, ) -> Bool { let Transaction { inputs, outputs, mint, .. } = transaction @@ -71,7 +75,12 @@ pub fn initialize( expect InlineDatum(miner_state_datum) = miner_state_datum expect InlineDatum(lock_state_datum) = lock_state_datum - expect HardForkState { status: NotForked, .. }: ForkDatum = hfs_datum + // The values are chosen by the + expect HardForkState { + status: NotForked, + fork_block_height, + fortuna_next_validator_hash, + }: ForkDatum = hfs_datum expect MinerLockState { locked_tuna: 0, block_signals: 0 }: ForkDatum = miner_state_datum @@ -85,7 +94,10 @@ pub fn initialize( quantity_of(hfs_value, own_policy, hard_fork_state_token) == 1, quantity_of(miner_state_value, own_policy, miner_lock_state_token) == 1, quantity_of(lock_state_value, own_policy, lock_state_token) == 1, + // Needed to prevent removal of genesis input check genesis_input == genesis_input, + fork_block_height == hardfork_block_height, + fortuna_next_validator_hash == hardfork_next_hash, } } @@ -106,10 +118,12 @@ pub fn lock_not_forked( stake_credential: None, } + // Needed to ensure all validator spends from this script hash are accounted for let script_inputs = list.filter(inputs, fn(input) { input.output.address == own_address }) when lock_action is { + // TODO: refactor some the shared parts in code MinerLockInit { fortuna_v1_output } -> { // Use blake hash since it's faster and this is unrelated to Proof of Work let own_token_name = diff --git a/lib/hardfork/params.ak b/lib/hardfork/params.ak index 433df10..1f8720b 100644 --- a/lib/hardfork/params.ak +++ b/lib/hardfork/params.ak @@ -7,3 +7,7 @@ pub const tuna_hardfork_threshold_denominator = 3 pub const tuna_count_blocks_from = 1000 pub const tuna_hardfork_version = 2 + +pub const hardfork_block_height = 100 + +pub const hardfork_next_hash = "" diff --git a/validators/hard_fork.ak b/validators/hard_fork.ak index 35d9b54..3afb64e 100644 --- a/validators/hard_fork.ak +++ b/validators/hard_fork.ak @@ -99,6 +99,7 @@ validator( let mint = value.from_minted_value(mint) + // We reference the locked v1 tuan NFTState that we have the NFT key for. let own_input = utils.resolve_output_reference(reference_inputs, locked_tokens_ref) @@ -128,9 +129,9 @@ validator( } } - fn mine(datum: State, redeemer: MineAction, ctx: ScriptContext) -> Bool { + fn mine(datum: Data, redeemer: MineAction, ctx: ScriptContext) -> Bool { // Access transaction information - let State { + expect State { block_number, current_hash, leading_zeros, @@ -139,7 +140,7 @@ validator( current_posix_time, interlink, .. - } = datum + }: State = datum let ScriptContext { transaction, purpose } = ctx @@ -253,7 +254,8 @@ validator( let halving_exponent = block_number / halving_number let expected_quantity = - if halving_exponent > 29 { + // This should be 32 not 29 + if halving_exponent > 32 { 0 } else { initial_payout / math.pow2(halving_exponent)