Skip to content
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ target-debian/
/Mintlayer_Node_win_*_Setup.exe
/Mintlayer_Node_GUI_win_*_Setup.exe

# JS dependencies from local wasm test runs
node_modules/
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/
## [Unreleased]

### Changed
- Consensus:
- the testnet is reset as the Babbage epoch: a fresh genesis (named after
Charles Babbage, continuing from the Lovelace testnet), new network
magic bytes, and every consensus and chainstate upgrade -- including the
tightening rules -- active from the first block. The initial supply is
40 trillion TML, sized so that faucet airdrops of one minimum stake
pledge (40,000 TML) per tester cannot crowd out the supply. Testnet
operators must resynchronize from scratch; old testnet data,
checkpoints and bootstrap files do not apply.

- Storage:
- the internal storage iteration APIs (`prefix_iter`, `greater_equal_iter`) now
take the key prefix by reference and return iterators that no longer borrow it,
Expand Down
312 changes: 46 additions & 266 deletions common/src/chain/config/builder.rs

Large diffs are not rendered by default.

1,583 changes: 3 additions & 1,580 deletions common/src/chain/config/checkpoints_data/testnet.rs

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions common/src/chain/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub enum ChainType {

impl ChainType {
pub const MAINNET_MAGIC_BYTES: MagicBytes = MagicBytes::new([0xB0, 0x07, 0x5F, 0xA0]);
pub const TESTNET_MAGIC_BYTES: MagicBytes = MagicBytes::new([0x2b, 0x7e, 0x19, 0xf8]);
pub const TESTNET_MAGIC_BYTES: MagicBytes = MagicBytes::new([0xBA, 0xBB, 0x18, 0x71]);
pub const REGTEST_MAGIC_BYTES: MagicBytes = MagicBytes::new([0xaa, 0xbb, 0xcc, 0xdd]);
pub const SIGNET_MAGIC_BYTES: MagicBytes = MagicBytes::new([0xf3, 0xf7, 0x7b, 0x45]);

Expand Down Expand Up @@ -832,13 +832,20 @@ fn create_mainnet_genesis() -> Genesis {
}

fn create_testnet_genesis() -> Genesis {
// We add 3_300_000_000 coins to the genesis mint account since it's just for testing. Nothing else changes.
let extra_testnet_mint = Amount::from_atoms(3_300_000_000 * CoinUnit::ATOMS_PER_COIN);
let total_amount = (extra_testnet_mint + DEFAULT_INITIAL_MINT).expect("Cannot fail");
// The Babbage testnet mints a generous total initial supply of
// 40 trillion TML, so that test-faucet airdrops of one minimum stake
// pledge (40,000 TML) per tester can never crowd out the supply while
// staking is being exercised.
let total_amount = Amount::from_atoms(40_000_000_000_000 * CoinUnit::ATOMS_PER_COIN);
let initial_pool_amount = MIN_STAKE_POOL_PLEDGE;
let mint_output_amount = (total_amount - initial_pool_amount).expect("must be valid");

let genesis_message = String::new();
// The Babbage testnet epoch: this message is part of the genesis hash, so
// changing it resets the testnet (new genesis id, fresh chain). Named
// after Charles Babbage, designer of the Analytical Engine -- the machine
// the first program, by Ada Lovelace (the previous testnet's namesake),
// was written for.
let genesis_message = String::from("babbage");

// To get these values, use the `newpublickey` and `getvrfpublickey` wallet-cli commands

Expand Down Expand Up @@ -1014,7 +1021,7 @@ mod tests {
fn testnet_creation() {
let config = create_testnet();

assert_eq!(3, config.consensus_upgrades.len());
assert_eq!(2, config.consensus_upgrades.len());
assert_eq!(config.chain_type(), &ChainType::Testnet);
}

Expand Down Expand Up @@ -1057,7 +1064,7 @@ mod tests {
);
assert_eq!(
format!("{:?}", ChainType::Testnet.magic_bytes()),
"MagicBytes(0x2B7E19F8)"
"MagicBytes(0xBABB1871)"
);
assert_eq!(
format!("{:?}", ChainType::Regtest.magic_bytes()),
Expand Down
2 changes: 1 addition & 1 deletion p2p/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Currently, the following message variants exist:
| Length | Description | Type | Comments |
|--------|-------------|---------|----------|
| 4 bytes | Protocol version | `u32` | The latest protocol version that the node supports.
| 4 bytes | Network | `[u8; 4]` | "Magic bytes" that identify the network. For mainnet, this will be equal to `B0075FA0`; for testnet, this will be `2B7E19F8`.
| 4 bytes | Network | `[u8; 4]` | "Magic bytes" that identify the network. For mainnet, this will be equal to `B0075FA0`; for testnet, this will be `BABB1871` (the Babbage epoch).
| 8 bytes | Services | `u64` | Bitmap of services that the node provides/supports.
| Variable | User agent | `Vec<u8>` | An ASCII string containing the name of the user's software.
| 4 bytes | Software version | `SemVer` | The version of the user's software.
Expand Down
8 changes: 3 additions & 5 deletions wasm-wrappers/js-bindings-test/tests/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import {
gen_random_int,
} from "./utils.js";

// Taken from TESTNET_FORK_HEIGHT_5_ORDERS_V1 in common/src/chain/config/builder.rs
// (which corresponds both to the orders and input commitments upgrade).
const ORDERS_V1_INPUT_COMMITMENTS_V1_TESTNET_FORK_HEIGHT = 566060;
export const ORDERS_V1_TESTNET_FORK_HEIGHT = ORDERS_V1_INPUT_COMMITMENTS_V1_TESTNET_FORK_HEIGHT;
export const SIGHASH_INPUT_COMMITMENTS_V1_TESTNET_FORK_HEIGHT = ORDERS_V1_INPUT_COMMITMENTS_V1_TESTNET_FORK_HEIGHT;
// On the Babbage testnet every chainstate upgrade (orders V1, input
// commitments V1, ...) is active from the genesis block, so there is no fork
// height to straddle anymore and V0-side encodings are unreachable there.

// A random height for cases where the height doesn't matter.
export const RANDOM_HEIGHT = gen_random_int(0, 10_000_000_000, "RANDOM_HEIGHT");
Expand Down
37 changes: 7 additions & 30 deletions wasm-wrappers/js-bindings-test/tests/test_input_commitments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
MNEMONIC,
POOL_ID,
ORDER_ID,
SIGHASH_INPUT_COMMITMENTS_V1_TESTNET_FORK_HEIGHT,
TOKEN_ID,
HTLC_SECRET_HASH,
HTLC_SECRET,
Expand All @@ -62,21 +61,12 @@ import {
OUTPUTS,
} from "./test_encode_other_outputs.js";

// Note: the exact heights don't matter as long as they are at the "correct side" of the fork.
const SIGHASH_INPUT_COMMITMENTS_V0_HEIGHT =
gen_random_int(0, SIGHASH_INPUT_COMMITMENTS_V1_TESTNET_FORK_HEIGHT - 1, "SIGHASH_INPUT_COMMITMENTS_V0_HEIGHT");
const SIGHASH_INPUT_COMMITMENTS_V1_HEIGHT = SIGHASH_INPUT_COMMITMENTS_V0_HEIGHT + SIGHASH_INPUT_COMMITMENTS_V1_TESTNET_FORK_HEIGHT;
// The Babbage testnet activates input commitments V1 from genesis, so only
// the V1 encoding is reachable; the height is arbitrary.
const SIGHASH_INPUT_COMMITMENTS_V1_HEIGHT = gen_random_int(0, 10_000_000_000, "SIGHASH_INPUT_COMMITMENTS_V1_HEIGHT");

export function test_input_commitments() {
function v0() {
test_impl(false);
}
function v1() {
test_impl(true);
}

run_one_test(v0);
run_one_test(v1);
run_one_test(test_impl);
}

const POOL_INFO = {
Expand Down Expand Up @@ -129,13 +119,8 @@ const DIFFERENT_ORDER_INFO = {
give_balance: { atoms: "5000000000000000" }
};

function test_impl(is_v1: boolean) {
let height: number;
if (is_v1) {
height = SIGHASH_INPUT_COMMITMENTS_V1_HEIGHT;
} else {
height = SIGHASH_INPUT_COMMITMENTS_V0_HEIGHT;
};
function test_impl() {
const height = SIGHASH_INPUT_COMMITMENTS_V1_HEIGHT;

const account_privkey = make_default_account_privkey(
MNEMONIC,
Expand Down Expand Up @@ -294,7 +279,7 @@ function test_impl(is_v1: boolean) {
witness_verification_func(witness, correct_tx_info);

console.log("Testing verification with incorrect tx info");
if (is_v1) {
{
// In v1 we do commit to the info, so passing incorrect info should result in verification
// failure.
expect_exception(
Expand All @@ -303,14 +288,6 @@ function test_impl(is_v1: boolean) {
},
signature_verification_failure_msg
);
} else {
// In v0, we only commit to UTXOs, so passing incorrect info won't cause the verification
// to fail.
// Note though that *some* info has to be passed anyway. This is because we want the input
// commitment construction to have the same requirements on the provided objects both in V0
// and V1. See the note and the TODO in `make_sighash_input_commitments_for_transaction_inputs`
// in `common`.
witness_verification_func(witness, different_tx_info);
}

console.groupEnd();
Expand Down
58 changes: 3 additions & 55 deletions wasm-wrappers/js-bindings-test/tests/test_orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ import {
import {
assert_eq_arrays,
gen_random_int,
get_err_msg,
} from "./utils.js";

import {
ORDER_ID,
ORDERS_V1_TESTNET_FORK_HEIGHT,
TOKEN_ID,
} from "./defs.js";
import {
Expand Down Expand Up @@ -78,31 +76,11 @@ export function test_orders() {
assert_eq_arrays(create_order_output_2, expected_create_order_output_2);
console.log("create order tokens for coins encoding ok");

// Note: the exact heights don't matter as long as they are at the "correct side" of the fork.
const order_v0_height = gen_random_int(0, ORDERS_V1_TESTNET_FORK_HEIGHT - 1, "order_v0_height");
const order_v1_height = order_v0_height + ORDERS_V1_TESTNET_FORK_HEIGHT;
// The Babbage testnet activates orders V1 from genesis, so the height is
// arbitrary and only the V1 encoding is reachable.
const order_v1_height = gen_random_int(0, 10_000_000_000, "order_v1_height");
// Note: the nonce is ignored since orders v1.
const order_v1_nonce = gen_random_int(0, 1000000, "order_v1_nonce");
const fill_order_v0_input = encode_input_for_fill_order(
ORDER_ID,
Amount.from_atoms("40000"),
ADDRESS,
BigInt(1),
BigInt(order_v0_height),
Network.Testnet
);
const expected_fill_order_v0_input = [
2, 4, 7, 49, 150, 254, 178, 75, 93, 83, 251,
1, 235, 159, 200, 27, 237, 187, 175, 123, 34, 179,
118, 53, 6, 173, 213, 7, 212, 102, 232, 253, 9,
244, 197, 2, 113, 2, 0, 1, 91, 58, 110, 176,
100, 207, 6, 194, 41, 193, 30, 91, 4, 195, 202,
103, 207, 80, 217, 178
];

assert_eq_arrays(fill_order_v0_input, expected_fill_order_v0_input);
console.log("fill order v0 encoding ok");

const fill_order_v1_input = encode_input_for_fill_order(
ORDER_ID,
Amount.from_atoms("40000"),
Expand All @@ -120,23 +98,6 @@ export function test_orders() {
assert_eq_arrays(fill_order_v1_input, expected_fill_order_v1_input);
console.log("fill order v1 encoding ok");

const conclude_order_v0_input = encode_input_for_conclude_order(
ORDER_ID,
BigInt(1),
BigInt(order_v0_height),
Network.Testnet
);
const expected_conclude_order_v0_input = [
2, 4, 6, 49, 150, 254, 178, 75,
93, 83, 251, 1, 235, 159, 200, 27,
237, 187, 175, 123, 34, 179, 118, 53,
6, 173, 213, 7, 212, 102, 232, 253,
9, 244, 197
];

assert_eq_arrays(conclude_order_v0_input, expected_conclude_order_v0_input);
console.log("conclude order v0 encoding ok");

const conclude_order_v1_input = encode_input_for_conclude_order(
ORDER_ID,
BigInt(order_v1_nonce),
Expand Down Expand Up @@ -170,17 +131,4 @@ export function test_orders() {
assert_eq_arrays(freeze_order_input, expected_freeze_order_input);
console.log("freeze order encoding ok");

try {
encode_input_for_freeze_order(
ORDER_ID,
BigInt(order_v0_height),
Network.Testnet
);
throw new Error("Freezing an order before v1 worked somehow!");
} catch (e) {
if (!get_err_msg(e).includes("Orders V1 not activated")) {
throw e;
}
console.log("Tested order freezing before v1 successfully");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,23 @@ import {
TxAdditionalInfo,
} from "../../pkg/wasm_wrappers.js";

import { assert_eq_vals } from "./utils.js";
import { assert_eq_vals, gen_random_int } from "./utils.js";

import {
ANOTHER_ORDER_ID,
MNEMONIC,
POOL_ID,
ORDER_ID,
SIGHASH_INPUT_COMMITMENTS_V1_TESTNET_FORK_HEIGHT,
TOKEN_ID,
HTLC_SECRET_HASH,
HTLC_SECRET,
} from "./defs.js";
import { ADDRESS } from "./test_address_generation.js";

export function test_partially_signed_transaction_encoding() {
const height = SIGHASH_INPUT_COMMITMENTS_V1_TESTNET_FORK_HEIGHT;
// The Babbage testnet activates input commitments V1 from genesis, so the
// height is arbitrary.
const height = gen_random_int(0, 10_000_000_000, "psbt_encoding_height");
const account_privkey = make_default_account_privkey(
MNEMONIC,
Network.Testnet,
Expand Down
Loading