M11.2b: restore funded life state with canonical closure checks
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m53s
Foundation / checks (client) (push) Failing after 9m57s
Foundation / checks (network) (push) Successful in 13m32s
Foundation / checks (tsan) (push) Successful in 7m56s
Foundation / checks (checks) (push) Successful in 33m49s
Foundation / checks (postgres) (push) Successful in 46m39s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

This commit is contained in:
dingo
2026-10-09 18:30:58 -04:00
parent 69101a74c2
commit 48684d30d9
7 changed files with 336 additions and 1 deletions
+65
View File
@@ -185,6 +185,70 @@ void invalid_sites_and_bounds() {
CHECK(huge && (*huge)->spawn(request(1), allocation(1)));
CHECK(summed((*huge)->balances()) == c.funding);
}
void reseal(std::vector<std::uint8_t>& bytes) {
std::uint64_t value = 14695981039346656037ULL;
for (std::size_t i = 0; i < bytes.size() - 8; ++i)
value = (value ^ bytes[i]) * 1099511628211ULL;
for (std::size_t i = bytes.size() - 8; i < bytes.size(); ++i, value >>= 8U)
bytes[i] = static_cast<std::uint8_t>(value & 255U);
}
void recover_complete_creation_state() {
auto made = PrimitiveLives::create(config());
CHECK(made);
const auto genesis = (*made)->snapshot();
auto empty = PrimitiveLives::restore(genesis, 90, 1, 7);
CHECK(empty && (*empty)->snapshot() == genesis && (*empty)->lives().empty());
const auto first = (*made)->spawn(request(1), allocation(1));
CHECK(first);
const auto bytes = (*made)->snapshot();
CHECK(bytes.size() <= max_primitive_lives_bytes);
auto restored = PrimitiveLives::restore(bytes, 90, 1, 7);
CHECK(restored && (*restored)->snapshot() == bytes && cut(**restored) == cut(**made));
CHECK((*restored)->spawn(request(1), {}) == first);
CHECK((*restored)->snapshot() == bytes);
CHECK((*restored)->spawn(request(2), allocation(2)) ==
(*made)->spawn(request(2), allocation(2)));
CHECK((*restored)->snapshot() == (*made)->snapshot());
CHECK(!PrimitiveLives::restore(bytes, 91, 1, 7));
CHECK(!PrimitiveLives::restore(bytes, 90, 2, 7));
CHECK(!PrimitiveLives::restore(bytes, 90, 1, 8));
// Every truncation is refused without reading past the input under ASan.
for (std::size_t size = 0; size < bytes.size(); ++size)
CHECK(!PrimitiveLives::restore(std::span{bytes}.first(size), 90, 1, 7));
auto changed = bytes;
changed.push_back(0);
CHECK(!PrimitiveLives::restore(changed, 90, 1, 7));
// Resealing distinguishes invariant validation from checksum detection.
const auto rejects = [&](std::size_t offset, LifeCodecError error) {
auto altered = bytes;
altered[offset] ^= 1U;
reseal(altered);
const auto result = PrimitiveLives::restore(altered, 90, 1, 7);
CHECK(!result && result.error() == error);
};
rejects(0, LifeCodecError::format); // Magic.
rejects(8, LifeCodecError::version); // Format.
rejects(12, LifeCodecError::version); // Rules.
rejects(48, LifeCodecError::version); // Quantum.
rejects(108, LifeCodecError::format); // Reserved.
rejects(96, LifeCodecError::format); // Site count/length disagreement.
rejects(100, LifeCodecError::format); // Life count/length disagreement.
rejects(104, LifeCodecError::format); // Archive length.
rejects(128 + 64, LifeCodecError::closure); // Source provenance.
rejects(128 + 72, LifeCodecError::closure); // Resolved placement.
rejects(128 + 80, LifeCodecError::closure); // Growth.
rejects(128 + 84, LifeCodecError::closure); // Damage.
rejects(128 + 88, LifeCodecError::closure); // Body ownership.
rejects(128 + 92, LifeCodecError::closure); // Reserve ownership.
rejects(128 + 96, LifeCodecError::closure); // Funding balance.
rejects(bytes.size() - 20, LifeCodecError::closure); // Archived history.
changed = bytes;
changed[128] ^= 1U;
CHECK(!PrimitiveLives::restore(changed, 90, 1, 7)); // Unsealed corruption.
changed.assign(max_primitive_lives_bytes + 1, 0);
CHECK(!PrimitiveLives::restore(changed, 90, 1, 7));
}
} // namespace
int main() try {
@@ -192,6 +256,7 @@ int main() try {
failures_and_retries_spend_nothing();
every_channel_must_be_funded();
invalid_sites_and_bounds();
recover_complete_creation_state();
std::puts("PASS primitive lives: funded bodies, equal starts, atomic refusals and retries");
return 0;
} catch (const std::exception& e) {