Add M10.8b signed handoff tickets and ticket admission
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m55s
Foundation / checks (client) (push) Successful in 12m40s
Foundation / checks (postgres) (push) Canceled after 4s
Foundation / checks (network) (push) Successful in 12m53s
Foundation / checks (tsan) (push) Successful in 7m55s
Foundation / checks (checks) (push) Successful in 31m47s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped

ADR-0096. A source region's handoff key signs a 160-byte ticket for one probe
transfer, account and destination; it rides the Hello grant slot and is
verified against neighbour keys bound to their regions. SessionControl
admits a ticket once per region, superseding like a grant, with the session
ending at the client's original grant expiry. RegionSessions makes the
destination's durable step first: PostgresHandoffLedger stages and commits
the transfer and moves the account's control, idempotently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-06 18:32:14 -04:00
co-authored by Claude Opus 5.5
parent 6a645ef7e4
commit 0ce51077b1
18 changed files with 1039 additions and 19 deletions
+90
View File
@@ -1,5 +1,6 @@
#include "evo/identity/identity.hpp"
#include "evo/network/dev_grant.hpp"
#include "evo/network/handoff_ticket.hpp"
#include "evo/network/intent_admission.hpp"
#include "evo/network/session_control.hpp"
#include "evo/network/session_grant.hpp"
@@ -619,10 +620,99 @@ void intent_admission() {
}
} // namespace
// M10.8b handoff tickets (ADR-0096): signed by the source region's handoff key, verified
// by the destination against keys bound to source regions; then admitted by SessionControl.
TicketClaims ticket(const AccountId& who, std::uint8_t transfer, std::uint64_t source = 4,
std::uint32_t expires = now + 30, std::uint32_t session = now + 200) {
TicketClaims c;
c.transfer.fill(transfer);
c.account = who;
c.world = world_id;
c.source = source;
c.destination = region;
c.expires_at = expires;
c.session_expires_at = session;
return c;
}
void handoff_tickets() {
const auto alice = account(1), bob = account(2);
auto source = *HandoffSigningKey::generate(DeploymentEnvironment::dev, 41);
auto other = *HandoffSigningKey::generate(DeploymentEnvironment::dev, 42);
auto verifier = *HandoffVerifier::create(DeploymentEnvironment::dev, world_id, region);
CHECK(verifier.add_key(4, 41, *source.public_key()));
CHECK(verifier.add_key(5, 42, *other.public_key()));
CHECK(refused(verifier.add_key(6, 41, *other.public_key()), HandoffTicketError::duplicate_key));
CHECK(refused(verifier.add_key(region, 43, *other.public_key()),
HandoffTicketError::invalid_key)); // Never its own region.
const auto good = source.sign(ticket(alice, 0x71));
CHECK(good && looks_like_handoff_ticket(*good));
const auto v = verifier.verify(*good, now);
CHECK(v && v->claims().account == alice && v->claims().source == 4 &&
v->claims().destination == region && v->claims().transfer[0] == 0x71 &&
v->claims().session_expires_at == now + 200);
// Every signed byte matters; the signature too.
for (std::size_t at = 0; at < handoff_ticket_bytes; at += 7) {
auto bad = *good;
bad.at(at) ^= 0x10;
CHECK(!verifier.verify(bad, now));
}
// A key may only sign for its own region; scope, environment and times are checked.
CHECK(refused(verifier.verify(*other.sign(ticket(alice, 0x72, 4)), now),
HandoffTicketError::wrong_source));
auto elsewhere = ticket(alice, 0x73);
elsewhere.destination = 12;
CHECK(refused(verifier.verify(*source.sign(elsewhere), now), HandoffTicketError::wrong_scope));
elsewhere = ticket(alice, 0x73);
elsewhere.world = {7, 4};
CHECK(refused(verifier.verify(*source.sign(elsewhere), now), HandoffTicketError::wrong_scope));
CHECK(refused(verifier.verify(*good, now + 30), HandoffTicketError::expired));
CHECK(refused(verifier.verify(*source.sign(ticket(alice, 0x74, 4, now + 121)), now),
HandoffTicketError::expired)); // Longer than the maximum lifetime.
CHECK(refused(verifier.verify(*source.sign(ticket(alice, 0x75, 4, now + 30, now)), now),
HandoffTicketError::expired)); // The session would already have ended.
auto stage_key = *HandoffSigningKey::generate(DeploymentEnvironment::stage, 44);
CHECK(verifier.add_key(6, 44, *stage_key.public_key()));
CHECK(refused(verifier.verify(*stage_key.sign(ticket(alice, 0x76, 6)), now),
HandoffTicketError::wrong_environment));
auto unknown = *HandoffSigningKey::generate(DeploymentEnvironment::dev, 99);
CHECK(refused(verifier.verify(*unknown.sign(ticket(alice, 0x77)), now),
HandoffTicketError::unknown_key));
CHECK(refused(source.sign(ticket(alice, 0x78, region)), HandoffTicketError::invalid_claims));
CHECK(refused(source.sign(ticket(AccountId{}, 0x78)), HandoffTicketError::invalid_claims));
// Tickets and grants never verify as each other.
Keys dev{DeploymentEnvironment::dev};
CHECK(!dev.verifier.verify(*good));
const auto grant = dev.signer.sign(claims(alice, 1));
CHECK(grant && !looks_like_handoff_ticket(*grant) && !verifier.verify(*grant, now));
// SessionControl: a ticket opens a session for its account, once; it supersedes a grant
// session; the session ends at the ticket's session expiry, capped at the maximum
// grant lifetime from now.
auto c = config();
c.max_account_attempts = 16;
auto control = *SessionControl::create(c);
const auto by_grant = control.open(dev.verified(claims(alice, 3)), now);
CHECK(by_grant);
CHECK(control.check_handoff(*v, now));
const auto opened = control.open_handoff(*v, now);
CHECK(opened && opened->superseded == by_grant->session && opened->expires_at == now + 200 &&
control.holder(alice) == opened->session);
CHECK(refused(control.check_handoff(*v, now + 1), ControlError::stale_grant)); // Replay.
CHECK(refused(control.open_handoff(*v, now + 1), ControlError::stale_grant));
const auto long_session =
verifier.verify(*source.sign(ticket(bob, 0x79, 4, now + 30, now + 4000)), now);
CHECK(long_session);
const auto capped = control.open_handoff(*long_session, now);
CHECK(capped && capped->expires_at == now + c.max_grant_lifetime);
// A later grant for the account still opens normally (serials are untouched).
CHECK(control.open(dev.verified(claims(alice, 4)), now + 2));
}
void control_tests() {
grants();
identity_adapter();
control_rules();
handoff_tickets();
session_codec();
intent_admission();
durable_actions();