Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
725dfe5
Support P2MR sentry enrollment, collateral rollover and funding votes
sidhujag Dec 2, 2026
c0fb862
Gate new P2MR reward addresses on Core preparation
sidhujag Dec 2, 2026
5866a77
Gate Sentry updates and funding votes on confirmed owner enrollment
sidhujag Dec 2, 2026
f0c767e
Verify registered collateral before Sentry approvals and recheck acti…
sidhujag Dec 2, 2026
884517b
Forward registered collateral lookup through the production Sentry ad…
sidhujag Dec 2, 2026
5f317bc
Retry Sentry transactions orphaned out of the mempool
sidhujag Dec 2, 2026
11fd171
Use the P2MR-aware transaction builder for backend funding
sidhujag Dec 2, 2026
4445f1c
Build reviewed Sentry SDK in PR checks and refresh patched ws
sidhujag Dec 2, 2026
3f7a7f2
Stage reviewed SDK on push and PR checks
sidhujag Dec 2, 2026
baf6c3d
Match Pali’s reviewed sentry SDK and clarify governance roles
sidhujag Dec 2, 2026
476dbb2
Apply Sentry transaction size limits after authenticating the operation
sidhujag Dec 2, 2026
6d900ca
Pin reviewed Sentry and virtual-byte funding dependencies
sidhujag Dec 2, 2026
b3af65a
Return the registered owner commitment for PQ funding votes
sidhujag Dec 2, 2026
0af137b
Prepare and verify both P2MR collateral registration workflows
sidhujag Dec 3, 2026
d1fc229
Pin the Sentry SDK cold-key signing guard
sidhujag Dec 3, 2026
672bd47
Pin the same reviewed registration SDK as Pali
sidhujag Dec 3, 2026
8b992e1
Require the cold policy for all funded Sentry registrations
sidhujag Dec 3, 2026
b262008
Recheck live registration capabilities before retrying stored transac…
sidhujag Dec 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ jobs:
node-version: ${{ matrix.node }}
cache: npm

- name: Checkout reviewed Sentry SDK
if: github.head_ref == 'codex/p2mr-sentry-authorities' || github.ref == 'refs/heads/codex/p2mr-sentry-authorities'
uses: actions/checkout@v4
with:
repository: sidhujag/sysweb3
ref: db299e9ddcbd6931dc409e102737ade305a84bbd
path: sdk-review
persist-credentials: false

- name: Cache reviewed Sentry SDK
if: github.head_ref == 'codex/p2mr-sentry-authorities' || github.ref == 'refs/heads/codex/p2mr-sentry-authorities'
run: |
npm --prefix sdk-review/packages/sysweb3-sentry ci --ignore-scripts --include=dev
npm --prefix sdk-review/packages/sysweb3-sentry run build
mkdir -p "$RUNNER_TEMP/reviewed-sentry"
(cd sdk-review/packages/sysweb3-sentry && npm pack --ignore-scripts --pack-destination "$RUNNER_TEMP/reviewed-sentry")
node scripts/cache-reviewed-sentry-sdk.cjs "$RUNNER_TEMP/reviewed-sentry"
rm -rf sdk-review

- name: Install
# `npm ci` is strict about package-lock.json; if the lock
# drifts we want the CI to fail loudly rather than silently
Expand All @@ -63,6 +82,23 @@ jobs:
with:
node-version-file: '.nvmrc'
cache: npm
- name: Checkout reviewed Sentry SDK
if: github.head_ref == 'codex/p2mr-sentry-authorities' || github.ref == 'refs/heads/codex/p2mr-sentry-authorities'
uses: actions/checkout@v4
with:
repository: sidhujag/sysweb3
ref: db299e9ddcbd6931dc409e102737ade305a84bbd
path: sdk-review
persist-credentials: false
- name: Cache reviewed Sentry SDK
if: github.head_ref == 'codex/p2mr-sentry-authorities' || github.ref == 'refs/heads/codex/p2mr-sentry-authorities'
run: |
npm --prefix sdk-review/packages/sysweb3-sentry ci --ignore-scripts --include=dev
npm --prefix sdk-review/packages/sysweb3-sentry run build
mkdir -p "$RUNNER_TEMP/reviewed-sentry"
(cd sdk-review/packages/sysweb3-sentry && npm pack --ignore-scripts --pack-destination "$RUNNER_TEMP/reviewed-sentry")
node scripts/cache-reviewed-sentry-sdk.cjs "$RUNNER_TEMP/reviewed-sentry"
rm -rf sdk-review
- name: Install pinned Anvil
uses: foundry-rs/foundry-toolchain@908c540300062bd5a7e473851cdb4282204cee09 # v1
with:
Expand All @@ -86,6 +122,25 @@ jobs:
node-version-file: '.nvmrc'
cache: npm

- name: Checkout reviewed Sentry SDK
if: github.head_ref == 'codex/p2mr-sentry-authorities' || github.ref == 'refs/heads/codex/p2mr-sentry-authorities'
uses: actions/checkout@v4
with:
repository: sidhujag/sysweb3
ref: db299e9ddcbd6931dc409e102737ade305a84bbd
path: sdk-review
persist-credentials: false

- name: Cache reviewed Sentry SDK
if: github.head_ref == 'codex/p2mr-sentry-authorities' || github.ref == 'refs/heads/codex/p2mr-sentry-authorities'
run: |
npm --prefix sdk-review/packages/sysweb3-sentry ci --ignore-scripts --include=dev
npm --prefix sdk-review/packages/sysweb3-sentry run build
mkdir -p "$RUNNER_TEMP/reviewed-sentry"
(cd sdk-review/packages/sysweb3-sentry && npm pack --ignore-scripts --pack-destination "$RUNNER_TEMP/reviewed-sentry")
node scripts/cache-reviewed-sentry-sdk.cjs "$RUNNER_TEMP/reviewed-sentry"
rm -rf sdk-review

- name: Install
run: npm ci

Expand Down
48 changes: 40 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ enabling management: historical registration and transaction readback use
treated as transaction absence and do not demote confirmed operation records.

`GET /capabilities` and `GET /context` are rate-limited public chain reads for
wallets. All node-watch and operation endpoints require a verified session;
wallets. For a large historical collateral transaction, wallets can request
`GET /collateral-transaction?network=<network>&proTxHash=<registered-node>`.
Core selects the node's registered collateral outpoint. The response contains its
verified witness-stripped transaction in `hex` and shares the governance batch read limit.
All node-watch and operation endpoints require a verified session;
writes also require the configured exact Origin and the existing CSRF token.
The public API remains `/api/sentry/v1/`, including Pali's default
`https://sysnode.info/api/sentry/v1/context`. The proxy example forwards that
Expand Down Expand Up @@ -445,11 +449,14 @@ Core network/genesis check. Its fixed `gobject_get` call verifies a valid,
non-deleted proposal and returns the on-chain name/URL, not a dapp-provided title.
The optional URL is omitted unless it is an HTTP(S) address without credentials;
this does not reject an otherwise valid proposal with a non-web URI.
The response is `{ chain, now, proposalHash, proposal: { name, url? }, nodes }`;
each node has `{ proTxHash, collateralOutpoint: { txid, vout }, votingKeyId,
valid: true }`. `valid` means a confirmed registered identity with a voting key,
not a claim about its hosting provider or operational status. Active PQ voting
is not supported by this legacy ECDSA context and is explicitly rejected.
The response includes the proposal, chain era and each confirmed sentry's
collateral outpoint and registered voting identity. Before activation the
identity is the ECDSA key ID. After activation it is the raw P2MR voting root,
with its key version and activation height. PQ responses include
`signingBlock: { height, hash }`, selected six blocks behind the tip. A wallet
can pin that block on a second read by supplying both `signingHeight` and
`signingBlockHash`. Core must still report that block as an active ancestor
for which the current voter registration is eligible.
The request has a 10-second total deadline, at most four concurrent node reads,
and a 64-KiB limit per Core response. It has a separate 12-request-per-minute IP
limit shared across both proxy prefixes, in addition to the normal read limit.
Expand Down Expand Up @@ -495,15 +502,40 @@ original transaction first, then revalidates and republishes only the stored
signed bytes if needed. A per-operation cooldown and atomic claim bound retries;
no new signature, new transaction ID, replacement transaction or fee bump occurs.

At PQ activation, registration accepts P2MR owner and voting addresses.
For owner-bound collateral, send the confirmed `collateralOutpoint` and
`changes.boundCollateral` with the descriptor's `coldKeyCommitment` and
`bootstrapOwnerRoot`. Pali derives the live owner during approval. The
registration keeps the funded outpoint and collateral height.

To spend a chosen P2MR payment into new collateral, send `fundingOutpoint`,
`changes.collateralAddress` and `changes.collateralKeyCommitment`. Select
the funding P2MR account in Pali. Its address identifies the funding
coins and receives change. Additional coins from that account cover fees.
The new collateral starts aging in the registration block.

A wallet can also let coin selection fund the new output. Supply
`changes.collateralAddress` and the descriptor’s `changes.collateralKeyCommitment`
in Core RPC hex order. Pali checks that the new output has the cold spending
policy and the required collateral amount before signing the funding inputs. To migrate
registered P2WPKH collateral, pass `changes.collateralAddress` and
`changes.collateralKeyCommitment` (Core RPC hex order) on an `updateRegistrar`.
The selected wallet must control the old collateral input and fund the fee
separately. The replacement retains the full collateral amount. An enrolled
owner's wallet fills its current opening locally and authorizes the successor
owner root. Preparation exposes only the registered root and requested changes.

Run `npm test -- --runInBand` and `npm run test:sentry-codec`. Codec integration
uses real legacy/PQ signatures and fee signatures with synthetic RPC fixtures;
it does not submit transactions to a public network.

For the actual legacy consensus smoke test, set `SENTRY_CORE_BIN` to a directory
For the legacy and PQ preparation consensus smoke test, set `SENTRY_CORE_BIN` to a directory
containing the metadata-enabled `syscoind` and `syscoin-cli`, then run
`npm run test:sentry-core`. It creates a fresh disconnected regtest and synthetic
wallet, registers a node, signs NEVM add/update/remove requests with the shared
SDK, and requires Core mempool acceptance plus mined registration readback.
SDK, then activates PQ preparation. It rolls the existing collateral into a
cold P2MR address, checks the original seniority, and confirms a subsequent
owner transfer signed by the enrolled P2MR owner.
The test stops its Core process and prints its isolated temporary data directory
for inspection. It never uses a configured service RPC or an existing wallet.

Expand Down
5 changes: 3 additions & 2 deletions lib/appFactory.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { parseNonSentryJson } = require('./sentryBodyLimits');
const express = require('express');
const cookieParser = require('cookie-parser');
const helmet = require('helmet');
Expand Down Expand Up @@ -253,7 +254,7 @@ function mountAuthAndVault(
csrfMw: services.csrfMw,
limiter: disableRateLimit ? rateLimiters.disabled() : rateLimiters.sentryManagementLimiter(),
readLimiter: disableRateLimit ? rateLimiters.disabled() : rateLimiters.sentryReadLimiter(),
votingContextLimiter: disableRateLimit ? rateLimiters.disabled() : rateLimiters.sentryVotingContextLimiter(),
heavyReadLimiter: disableRateLimit ? rateLimiters.disabled() : rateLimiters.sentryHeavyReadLimiter(),
frontendUrl,
}));

Expand Down Expand Up @@ -401,7 +402,7 @@ function createApp({
// Public pool snapshots never enter the session or credentialed-CORS path.
app.use(PRIVACY_PREFIXES, createPrivacyRouter({ index: privacyIndex, relayers: privacyRelayers }));
app.use(cors({ origin: effectiveCorsOrigin, credentials: true }));
app.use(express.json({ limit: '256kb' }));
app.use(parseNonSentryJson);
app.use(cookieParser());

mountAuthAndVault(app, {
Expand Down
40 changes: 13 additions & 27 deletions lib/gov.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,20 @@
// imported voting keys correspond to live masternodes.
// * Vote-relay validation + fan-out. The browser signs locally
// (VaultGovernanceSigner / voteSigner.js), and we relay each
// compact ECDSA signature to Syscoin Core's `voteraw` RPC. We
// intentionally enforce `voteSignal === "funding"` here — non-
// funding signals (valid/delete/endorsed) use the BLS operator
// key, NOT the voting key, and the vault doesn't hold operator
// keys.
// ECDSA signature or PQ funding envelope to Core's `voteraw` RPC. We
// accept only proposal funding here. Core authorizes other signals
// with the operator key for the active era. The vault holds voting keys.
//
// Error taxonomy for validation: we return `{ ok: false, error: "<code>" }`
// rather than throwing, so the HTTP layer maps codes to 4xx without
// rebuilding error objects across module boundaries. Codes are stable
// (UI copy / i18n keys hang off them).

const HEX64 = /^[0-9a-fA-F]{64}$/;
// Permissive base64 charset guard: the real length/shape check happens
// via `Buffer.from(sig, 'base64').length === 65` plus a canonical
// re-encode roundtrip, so the regex is just a cheap filter that
// rejects obviously malformed input (whitespace, non-base64 chars)
// before we allocate a decode buffer.
const BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
// A recoverable ECDSA signature produced by CKey::SignCompact is
// exactly 65 bytes (1-byte header + 32-byte r + 32-byte s). Anything
// else is a programming or tampering error — Core would reject it at
// `voteraw` anyway, but we fail fast here with a stable error code
// so the UI can surface a precise message.
const VOTE_SIG_BYTES = 65;
const FUNDING_ENVELOPE_BYTES = 7963;
const FUNDING_LEAF_OFFSET = 2 + 4 + 32 + 32 + 4;

const OUTCOMES = Object.freeze({ yes: 1, no: 2, abstain: 3 });
// PR5 intentionally supports only `funding`. The other signals
Expand Down Expand Up @@ -148,26 +138,22 @@ function validateVoteBody(body, { nowMs = Date.now() } = {}) {
) {
return { ok: false, error: `invalid_entry:${i}:collateralIndex` };
}
if (typeof voteSig !== "string" || !BASE64.test(voteSig)) {
if (typeof voteSig !== "string" || (voteSig.length !== 88 && voteSig.length !== Math.ceil(FUNDING_ENVELOPE_BYTES / 3) * 4) ||
!BASE64.test(voteSig)) {
return { ok: false, error: `invalid_entry:${i}:voteSig` };
}
// Decode and verify the exact raw length. The character-count
// check we used to perform accepted `"A".repeat(88)` (decodes to
// 66 bytes) and `"A".repeat(86) + "=="` (decodes to 64 bytes)
// because both are syntactically valid base64 strings of the
// "right" length. Decoding is the only way to enforce the 65-
// byte invariant. We also require the roundtrip
// (decode → re-encode) to equal the input so non-canonical
// padding (extra "=" chars, non-zero trailing bits) is rejected.
// `Buffer.from(_, 'base64')` never throws on junk input — it
// silently coerces — so both checks are load-bearing here.
// Only legacy compact signatures and Core's delegated funding envelope are relayable.
// Core checks the branch, registered authority, and signature before accepting the vote.
const decodedSig = Buffer.from(voteSig, "base64");
const pqFunding = decodedSig.length === FUNDING_ENVELOPE_BYTES && decodedSig[0] === 1 && decodedSig[1] === 1 &&
decodedSig[FUNDING_LEAF_OFFSET] === 0xc2;
if (
decodedSig.length !== VOTE_SIG_BYTES ||
(!pqFunding && decodedSig.length !== VOTE_SIG_BYTES) ||
decodedSig.toString("base64") !== voteSig
) {
return { ok: false, error: `invalid_entry:${i}:voteSig` };
}
if (pqFunding && entries.length > 20) return { ok: false, error: "too_many_entries" };
const k = `${collateralHash.toLowerCase()}:${collateralIndex}`;
if (dupKey.has(k)) {
return { ok: false, error: `duplicate_entry:${i}` };
Expand Down
17 changes: 17 additions & 0 deletions lib/gov.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,23 @@ describe('validateVoteBody', () => {
expect(res.error).toMatch(/collateralIndex$/);
}
});

test('relays bounded PQ funding envelopes and rejects other formats, roles and leaves', () => {
const envelope = Buffer.alloc(7963);
const check = (size) => validateVoteBody(goodBody({ entries: Array.from({ length: size }, (_, collateralIndex) =>
({ collateralHash: VALID_HASH_2, collateralIndex, voteSig: envelope.toString('base64') })) }), { nowMs: NOW_MS });
envelope[0] = envelope[1] = 1;
envelope[74] = 0xc2;
expect(check(20).ok).toBe(true);
expect(check(21)).toMatchObject({ ok: false, error: 'too_many_entries' });
envelope[74] = 0xc4;
expect(check(1)).toMatchObject({ ok: false, error: 'invalid_entry:0:voteSig' });
envelope[74] = 0xc2;
envelope[1] = 0;
expect(check(1)).toMatchObject({ ok: false, error: 'invalid_entry:0:voteSig' });
envelope[0] = 2; envelope[1] = 1;
expect(check(1)).toMatchObject({ ok: false, error: 'invalid_entry:0:voteSig' });
});
});

describe('lookupMatches', () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/proposalPsbt.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ function createDefaultSyscoinClient({ blockbookURL, networkKey } = {}) {
bitcoinjs: syscoinjs.utils.bitcoinjs,
exportPsbtToJson: syscoinjs.utils.exportPsbtToJson,
fetchUtxos: (xpub) => syscoinjs.utils.fetchBackendUTXOS(blockbookURL, xpub),
createTransaction: (txOpts, changeAddress, outputs, feeRate, xpub, utxos) =>
lib.createTransaction(txOpts, changeAddress, outputs, feeRate, xpub, utxos),
createTransaction: (txOpts, changeAddress, outputs, feeRate, xpub, utxos, forcedInputs) =>
lib.createTransaction(txOpts, changeAddress, outputs, feeRate, xpub, utxos, undefined, forcedInputs),
};
}

Expand Down
Loading
Loading