Files
zeekay 2cddf94e1c The P-chain speaks the node's names, and the node's one hash
platformvm had its own thirty-two-byte name wrapped in a struct, its own
twenty-byte address, and — under both of them — its own complete SHA-256.
Two implementations of the hash a transaction is NAMED by is the sharpest
version of this problem: they agree until the day they do not, and the day
they do not is a fork.

So ids.hpp now declares nothing. It adopts core's names and core's hash,
and keeps only the one thing that is a P-chain fact rather than a naming
fact: the primary network is the zero id. sha256.hpp is deleted; its FIPS
180-4 vectors moved to core, where the hash now lives, and sha256_test
became ids_test, which checks what is left to check here — that a UTXO's
name is the reference's ids.ID.Prefix.

Six identical local hex() helpers in the test files are gone too.

ONE HAZARD, NAMED, BECAUSE IT IS SILENT. FixedId::empty() meant "all
zero"; std::array::empty() means "has no elements", which is false for
thirty-two bytes and compiles without a word. Five checks were of the
first kind and would have become dead: the two empty-asset gates, the
empty-VM-id gate, and the reward transaction's own id. They now read
`== kEmptyId`, which cannot rot into a tautology. Three of the five were
caught by the suite; the reward-id one was not, and nothing tests it.

208 differential vectors still agree across Go, Rust and C++, so the names
that changed shape did not change value.
2026-09-05 15:04:34 -07:00

30 lines
1.0 KiB
C++

// Copyright (C) 2026, Lux Industries, Inc. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause-Eco
//
// ids_test.cpp — the names this chain derives, against the Go reference's own.
//
// The hash underneath is the node's and is checked against FIPS 180-4 where it
// lives (core/test/id_test.cpp). What is checked HERE is the derivation the
// P-chain builds on it: a UTXO's name is ids.ID.Prefix over the transaction
// that produced it, and two implementations that name the same UTXO
// differently have forked. The vectors were produced by the Go reference and
// are asserted verbatim.
#include "golden.hpp"
#include "harness.hpp"
#include "lux/platformvm/ids.hpp"
#include <string>
using namespace lux::platformvm;
TEST(UtxoIdDerivation) {
Id zero{};
REQUIRE(hex(prefix_id(zero, 0)) == pvmgold::prefix_zero_0);
REQUIRE(hex(prefix_id(zero, 1)) == pvmgold::prefix_zero_1);
Id seq{};
for (std::size_t i = 0; i < kIdLen; ++i) seq[i] = static_cast<std::uint8_t>(i + 1);
REQUIRE(hex(prefix_id(seq, 7)) == pvmgold::prefix_seq_7);
}