diff --git a/Cargo.lock b/Cargo.lock index f91e9879a7..6516eb89e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3369,6 +3369,7 @@ dependencies = [ "snarkvm-console", "snarkvm-ledger-block", "snarkvm-ledger-committee", + "snarkvm-ledger-narwhal-batch-header", "snarkvm-ledger-query", "snarkvm-ledger-store", "snarkvm-ledger-test-helpers", diff --git a/ledger/committee/src/lib.rs b/ledger/committee/src/lib.rs index 75b4a988a8..43ad8d1511 100644 --- a/ledger/committee/src/lib.rs +++ b/ledger/committee/src/lib.rs @@ -34,9 +34,9 @@ use ledger_narwhal_batch_header::BatchHeader; use std::collections::HashSet; /// The minimum amount of stake required for a validator to bond. -pub const MIN_VALIDATOR_STAKE: u64 = 1_000_000_000_000u64; // microcredits +pub const MIN_VALIDATOR_STAKE: u64 = 10_000_000_000_000u64; // microcredits /// The minimum amount of stake required for a delegator to bond. -pub const MIN_DELEGATOR_STAKE: u64 = 10_000_000u64; // microcredits +pub const MIN_DELEGATOR_STAKE: u64 = 10_000_000_000u64; // microcredits /// The maximum number of delegators. pub const MAX_DELEGATORS: u32 = 100_000u32; @@ -408,7 +408,7 @@ mod tests { // Set the number of rounds. const NUM_ROUNDS: u64 = 256 * 2_000; // Sample the number of members. - let num_members = rng.gen_range(3..50); + let num_members = rng.gen_range(3..=Committee::::MAX_COMMITTEE_SIZE); // Sample a committee. let committee = crate::test_helpers::sample_committee_custom(num_members, rng); // Check the leader distribution. @@ -420,7 +420,8 @@ mod tests { // Initialize the RNG. let rng = &mut TestRng::default(); // Sample a committee. - let committee = crate::test_helpers::sample_committee_custom(200, rng); + let committee = + crate::test_helpers::sample_committee_custom(Committee::::MAX_COMMITTEE_SIZE, rng); // Start a timer. let timer = std::time::Instant::now(); diff --git a/ledger/committee/src/prop_tests.rs b/ledger/committee/src/prop_tests.rs index 992be5e216..ebdbdbc06a 100644 --- a/ledger/committee/src/prop_tests.rs +++ b/ledger/committee/src/prop_tests.rs @@ -193,7 +193,7 @@ fn committee_members(input: CommitteeContext) { fn invalid_stakes(#[strategy(too_low_stake_committee())] committee: Result>) { assert!(committee.is_err()); if let Err(err) = committee { - assert_eq!(err.to_string().as_str(), "All members must have at least 1000000000000 microcredits in stake"); + assert_eq!(err.to_string().as_str(), "All members must have at least 10000000000000 microcredits in stake"); } } diff --git a/ledger/narwhal/batch-header/src/lib.rs b/ledger/narwhal/batch-header/src/lib.rs index ce79fc6c6a..c1ff8f0760 100644 --- a/ledger/narwhal/batch-header/src/lib.rs +++ b/ledger/narwhal/batch-header/src/lib.rs @@ -52,7 +52,12 @@ pub struct BatchHeader { impl BatchHeader { /// The maximum number of certificates in a batch. - pub const MAX_CERTIFICATES: u16 = 200; + #[cfg(not(any(test, feature = "test-helpers")))] + pub const MAX_CERTIFICATES: u16 = 10; + /// The maximum number of certificates in a batch. + /// This is set to a deliberately high value (100) for testing purposes only. + #[cfg(any(test, feature = "test-helpers"))] + pub const MAX_CERTIFICATES: u16 = 100; /// The maximum number of rounds to store before garbage collecting. pub const MAX_GC_ROUNDS: usize = 100; /// The maximum number of transmissions in a batch. diff --git a/ledger/src/tests.rs b/ledger/src/tests.rs index 6cc32d97d3..6188b57c28 100644 --- a/ledger/src/tests.rs +++ b/ledger/src/tests.rs @@ -502,7 +502,7 @@ fn test_bond_and_unbond_validator() { // Fund the new committee member. let inputs = [ Value::from_str(&format!("{new_member_address}")).unwrap(), - Value::from_str("10000000000000u64").unwrap(), // 10 million credits. + Value::from_str("20000000000000u64").unwrap(), // 20 million credits. ]; let transfer_transaction = ledger .vm @@ -521,7 +521,7 @@ fn test_bond_and_unbond_validator() { ledger.advance_to_next_block(&transfer_block).unwrap(); // Construct the bond public - let bond_amount = 1000000000000u64; // 1 million credits. + let bond_amount = MIN_VALIDATOR_STAKE; let inputs = [ Value::from_str(&format!("{new_member_address}")).unwrap(), Value::from_str(&format!("{new_member_address}")).unwrap(), @@ -569,7 +569,7 @@ fn test_bond_and_unbond_validator() { assert_eq!(num_validators, committee.num_members()); // Construct the bond public - let unbond_amount = committee.get_stake(new_member_address); // 1 million credits. + let unbond_amount = committee.get_stake(new_member_address); let inputs = [Value::from_str(&format!("{unbond_amount}u64")).unwrap()]; let unbond_public_transaction = ledger .vm diff --git a/synthesizer/Cargo.toml b/synthesizer/Cargo.toml index 42a5bdfdbb..ff0ff6034f 100644 --- a/synthesizer/Cargo.toml +++ b/synthesizer/Cargo.toml @@ -161,6 +161,11 @@ package = "snarkvm-ledger-committee" path = "../ledger/committee" features = [ "test-helpers" ] +[dev-dependencies.ledger-narwhal-batch-header] +package = "snarkvm-ledger-narwhal-batch-header" +path = "../ledger/narwhal/batch-header" +features = [ "test-helpers" ] + [dev-dependencies.ledger-test-helpers] package = "snarkvm-ledger-test-helpers" path = "../ledger/test-helpers" diff --git a/synthesizer/process/src/tests/test_credits.rs b/synthesizer/process/src/tests/test_credits.rs index 8dcb78cd6a..64d14970d0 100644 --- a/synthesizer/process/src/tests/test_credits.rs +++ b/synthesizer/process/src/tests/test_credits.rs @@ -231,7 +231,7 @@ fn initialize_stakers>( // Initialize a new account. let private_key = PrivateKey::::new(rng)?; let address = Address::try_from(&private_key)?; - let balance = 10_000_000_000_000u64; + let balance = 100_000_000_000_000u64; // Add the balance directly to the finalize store. let key = Plaintext::from(Literal::Address(address)); @@ -521,7 +521,7 @@ fn test_bond_validator_multiple_bonds() { /* First Bond */ // Perform the first bond. - let amount = 1_000_000_000_000u64; + let amount = MIN_VALIDATOR_STAKE; assert!(amount < public_balance); bond_public(&process, &store, validator_private_key, validator_address, validator_address, amount, rng) .unwrap(); @@ -539,7 +539,7 @@ fn test_bond_validator_multiple_bonds() { /* Second Bond */ // Perform the second bond. - let amount = 1_000_000_000_000u64; + let amount = MIN_VALIDATOR_STAKE; assert!(amount < public_balance_1); bond_public(&process, &store, validator_private_key, validator_address, validator_address, amount, rng) .unwrap(); @@ -1514,7 +1514,7 @@ fn test_unbond_delegator_as_validator() { /* Ensure unbonding a delegator as an open validator fails. */ // Bond the validators. - let validator_amount = 1_000_000_000_000u64; + let validator_amount = MIN_VALIDATOR_STAKE; bond_public( &process, &finalize_store, @@ -1596,7 +1596,7 @@ fn test_claim_unbond() { let public_balance = account_balance(&finalize_store, validator_address).unwrap(); // Perform the bond. - let validator_amount = 1_000_000_000_000u64; + let validator_amount = MIN_VALIDATOR_STAKE; bond_public( &process, &finalize_store, @@ -1642,7 +1642,7 @@ fn test_set_validator_state() { /* Ensure calling `set_validator_state` succeeds. */ // Perform the bond. - let amount = 1_000_000_000_000u64; + let amount = MIN_VALIDATOR_STAKE; bond_public(&process, &finalize_store, validator_private_key, validator_address, validator_address, amount, rng) .unwrap(); @@ -1699,7 +1699,7 @@ fn test_bonding_to_closed_fails() { /* Ensure bonding to a closed validator fails. */ // Perform the bond. - let amount = 1_000_000_000_000u64; + let amount = MIN_VALIDATOR_STAKE; bond_public(&process, &finalize_store, validator_private_key, validator_address, validator_address, amount, rng) .unwrap(); @@ -1707,7 +1707,7 @@ fn test_bonding_to_closed_fails() { set_validator_state(&process, &finalize_store, validator_private_key, false, rng).unwrap(); // Ensure that the validator can't bond additional stake. - let validator_amount = 1_000_000_000_000u64; + let validator_amount = MIN_VALIDATOR_STAKE; assert!( bond_public( &process, @@ -1722,7 +1722,7 @@ fn test_bonding_to_closed_fails() { ); // Ensure that delegators can't bond to the validator. - let delegator_amount = 1_000_000u64; + let delegator_amount = MIN_DELEGATOR_STAKE; assert!( bond_public( &process, diff --git a/synthesizer/program/src/resources/credits.aleo b/synthesizer/program/src/resources/credits.aleo index 75cabe5a00..51fc62e167 100644 --- a/synthesizer/program/src/resources/credits.aleo +++ b/synthesizer/program/src/resources/credits.aleo @@ -164,9 +164,9 @@ finalize bond_public: get.or_use metadata[aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc] 0u32 into r7; // Increment the committee size by one. add r7 1u32 into r8; - // Determine if the committee size is less than or equal to 200. - lte r8 200u32 into r9; - // Enforce that the committee size is less than or equal to 200. + // Determine if the committee size is less than or equal to 10. + lte r8 10u32 into r9; + // Enforce that the committee size is less than or equal to 10. assert.eq r9 true; // Set the new committee size. set r8 into metadata[aleo1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3ljyzc]; @@ -200,9 +200,9 @@ finalize bond_public: // Increment the microcredits in the bond state. add r11.microcredits r3 into r16; - // Determine if the amount is at least one million credits. - gte r16 1_000_000_000_000u64 into r17; - // Enforce the amount is at least one million credits. + // Determine if the amount is at least 10 million credits. + gte r16 10_000_000_000_000u64 into r17; + // Enforce the amount is at least 10 million credits. assert.eq r17 true; // Construct the updated bond state. @@ -283,9 +283,9 @@ finalize bond_public: // Increment the microcredits in the bond state. add r30.microcredits r3 into r31; - // Determine if the amount is at least 10 credits. - gte r31 10_000_000u64 into r32; - // Enforce the amount is at least 10 credits. + // Determine if the amount is at least 10 thousand credits. + gte r31 10_000_000_000u64 into r32; + // Enforce the amount is at least 10 thousand credits. assert.eq r32 true; // Construct the updated bond state. @@ -368,12 +368,12 @@ finalize unbond_public: // Decrement the microcredits in the bond state. sub r8.microcredits r1 into r9; - // Determine if the remaining bond is at least one million credits. - gte r9 1_000_000_000_000u64 into r10; + // Determine if the remaining bond is at least 10 million credits. + gte r9 10_000_000_000_000u64 into r10; - // If the remaining balance is at least 1 million credits, jump to the `decrement_validator` logic. + // If the remaining balance is at least 10 million credits, jump to the `decrement_validator` logic. branch.eq r10 true to decrement_validator; - // If the remaining balance is less than 1 million credits, jump to the `remove_validator` logic. + // If the remaining balance is less than 10 million credits, jump to the `remove_validator` logic. branch.eq r10 false to remove_validator; /*** Decrement Validator ***/ @@ -456,12 +456,12 @@ finalize unbond_public: // Decrement the microcredits in the bond state. sub r19.microcredits r1 into r20; - // Determine if the remaining bond is at least 10 credits. - gte r20 10_000_000u64 into r21; + // Determine if the remaining bond is at least 10 thousand credits. + gte r20 10_000_000_000u64 into r21; - // If the remaining balance is at least 10 credits, jump to the `decrement_delegator` logic. + // If the remaining balance is at least 10 thousand credits, jump to the `decrement_delegator` logic. branch.eq r21 true to decrement_delegator; - // If the remaining balance is less than 10 credits, jump to the `remove_delegator` logic. + // If the remaining balance is less than 10 thousand credits, jump to the `remove_delegator` logic. branch.eq r21 false to remove_delegator; /*** Decrement Delegator ***/ diff --git a/synthesizer/src/vm/finalize.rs b/synthesizer/src/vm/finalize.rs index c83ade3ebc..47e62834ee 100644 --- a/synthesizer/src/vm/finalize.rs +++ b/synthesizer/src/vm/finalize.rs @@ -2020,8 +2020,9 @@ finalize compute: assert!(result.is_err()); // Reset the validators. + // Note: We use a smaller committee size to ensure that there is enough supply to allocate to the validators and genesis block transactions. let validators = - sample_validators::(Committee::::MAX_COMMITTEE_SIZE as usize, rng); + sample_validators::(Committee::::MAX_COMMITTEE_SIZE as usize / 4, rng); // Construct the committee. // Track the allocated amount. @@ -2063,8 +2064,9 @@ finalize compute: VM::from(ConsensusStore::>::open(None).unwrap()).unwrap(); // Construct the validators. + // Note: We use a smaller committee size to ensure that there is enough supply to allocate to the validators and genesis block transactions. let validators = - sample_validators::(Committee::::MAX_COMMITTEE_SIZE as usize, rng); + sample_validators::(Committee::::MAX_COMMITTEE_SIZE as usize / 4, rng); // Construct the delegators, greater than the maximum delegator size. let delegators = (0..MAX_DELEGATORS + 1) @@ -2224,7 +2226,7 @@ finalize compute: // Note that the first validator is used to execute additional transactions in `VM::genesis_quorum`. // Therefore, the balance of the first validator will be different from the expected balance. if entry.0 == Plaintext::from_str(&first_validator.to_string()).unwrap() { - assert_eq!(entry.1, Value::from_str("294999983894244u64").unwrap()); + assert_eq!(entry.1, Value::from_str("249983999894244u64").unwrap()); } else { assert!(expected_account.contains(entry)); } diff --git a/synthesizer/src/vm/helpers/committee.rs b/synthesizer/src/vm/helpers/committee.rs index 513932a201..2725eaba16 100644 --- a/synthesizer/src/vm/helpers/committee.rs +++ b/synthesizer/src/vm/helpers/committee.rs @@ -247,7 +247,7 @@ pub fn to_next_withdraw_map( pub(crate) mod test_helpers { use super::*; use crate::vm::TestRng; - use ledger_committee::MIN_VALIDATOR_STAKE; + use ledger_committee::{MIN_DELEGATOR_STAKE, MIN_VALIDATOR_STAKE}; use rand::{CryptoRng, Rng}; @@ -262,8 +262,8 @@ pub(crate) mod test_helpers { .flat_map(|(validator, (microcredits, _))| { // Keep a tally of the remaining microcredits. let remaining_microcredits = microcredits.saturating_sub(MIN_VALIDATOR_STAKE); - // Set the staker amount to 10 credit. - let staker_amount = 10_000_000; + // Set the staker amount to `MIN_DELEGATOR_STAKE` microcredits. + let staker_amount = MIN_DELEGATOR_STAKE; // Determine the number of iterations. let num_iterations = (remaining_microcredits / staker_amount).saturating_sub(1); diff --git a/synthesizer/src/vm/mod.rs b/synthesizer/src/vm/mod.rs index 8f58c492d2..4c68fb2c7b 100644 --- a/synthesizer/src/vm/mod.rs +++ b/synthesizer/src/vm/mod.rs @@ -1001,7 +1001,7 @@ function a: // Note: `deployment_transaction_ids` is sorted lexicographically by transaction ID, so the order may change if we update internal methods. assert_eq!( deployment_transaction_ids, - vec![deployment_2.id(), deployment_1.id(), deployment_4.id(), deployment_3.id()], + vec![deployment_3.id(), deployment_4.id(), deployment_1.id(), deployment_2.id()], "Update me if serialization has changed" ); } diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out b/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out index 51fb5b5e60..0af538e48d 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out @@ -19,7 +19,7 @@ outputs: test_rand.aleo/rand_chacha_check: outputs: - '{"type":"future","id":"3094014759641313043901697261267946468626327163450942596641947962222295207390field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_check,\n arguments: [\n 0field,\n false\n ]\n}"}' - speculate: the execution was accepted + speculate: the execution was rejected add_next_block: succeeded. - verified: true execute: