Repository navigation
Add msig:propose-updateauth for WA keys under multisig - #46
Conversation
New msig:propose-updateauth wraps eosio::updateauth in an eosio.msig propose, with early PUB_WA_/PUB_K1_/PUB_R1_ validation, threshold/weight checks, and chain-order sorting. Covers the WebAuthn-under-multisig case PR XPRNetwork#45 left without a dedicated flow.
Validate the permission side of --accounts entries, accept 13-character EOSIO names with a restricted final character, and pin the key-sort test to an explicit order.
| }) | ||
| } | ||
|
|
||
| export const buildUpdateauthAuth = (options: { |
There was a problem hiding this comment.
Is it intentional to have the word auth twice here?
There was a problem hiding this comment.
Not really!
buildUpdateauthAuth -> buildRequiredAuth
Thanks :)
buildUpdateauthAuth -> buildRequiredAuth (matches RpcInterfaces.RequiredAuth return type); buildUpdateauthAction -> buildUpdateAuthAction (camelCase fix). Update caller and tests.
squdgy
left a comment
There was a problem hiding this comment.
Static review of head 7c770ce (read from the diff and the helpers it calls; tests and the CLI were not run).
Blocking: bugs in src/utils/sortRequiredAuth.ts (not in this diff, but buildRequiredAuth calls it on every proposal)
- Crash with 2+ waits (
sortRequiredAuth.ts:26):a.wait_sec.localeCompare(b.wait_sec)is called on numbers (parseWaitWeightsreturnswait_sec: Number(...)).--waits 86400,3600:2should throwTypeError: a.wait_sec.localeCompare is not a function. Theanyannotation hides it from tsc. With 0 or 1 waits the comparator never runs, which is why no test hits it. Even if it ran on strings,'10000'would sort before'9'; it needs a numeric compare. - Accounts sorted by actor only (
sortRequiredAuth.ts:25):--accounts a@owner,a@activehas equal actors, so input order is kept. As I understand it the chain wants (actor, permission) order, soupdateauthwould be rejected at exec time, after approvals are collected.localeCompareis also not EOSIO name order; this PR's owncompareNamesis the right comparator. - Keys fall back to
localeCompareon the base58 string (sortRequiredAuth.ts:49): only WA-vs-WA pairs are compared bytewise. K1/R1 pairs and mixed K1/WA pairs use locale string order, which is not the chain's (type, bytes) order.sorts keys deterministicallyonly uses two K1 keys that differ in the first character, so it can't catch this.
Points 2 and 3 are from my knowledge of EOSIO canonical-form rules and were not checked against a node. Point 1 follows directly from the code.
Other
isPositiveInteger(src/utils/integer.ts:1) accepts'0'(n >= 0), so--waits 0is accepted. Also see the inline comment on range limits.- Test coverage: nothing exercises multiple waits, mixed K1/WA keys, several permissions for one actor, or duplicates through
buildRequiredAuth(inline comment on the test file). These are the cases that break the sorting.
Inline comments below cover the lines that are in this diff.
| throw new Error(`--threshold ${threshold} exceeds total weight ${total}`) | ||
| } | ||
|
|
||
| const auth: RpcInterfaces.RequiredAuth = {threshold, keys, accounts, waits} |
There was a problem hiding this comment.
No duplicate or range validation before the authority is built. --keys K,K, --accounts a@active,a@active, a weight above 65535 (uint16), or a threshold/wait above 2^32-1 all pass here and, as I understand the chain rules, fail only when eosio.msig::exec runs, after approvals are collected. Suggest rejecting duplicates and out-of-range values here. (Chain-side limits not verified against a node.)
| const seconds = separator === -1 ? entry : entry.slice(0, separator) | ||
| const weight = separator === -1 ? 1 : parseWeight(entry, entry.slice(separator + 1), argument) | ||
|
|
||
| if (!isPositiveInteger(seconds)) { |
There was a problem hiding this comment.
isPositiveInteger returns true for '0' (it checks n >= 0), so --waits 0 yields wait_sec: 0, and the error text says "positive integer". parseWeight already guards this with Number(value) < 1; do the same here. A value above the uint32 range also passes.
|
|
||
| parent = '' | ||
| } else { | ||
| parent = parent === undefined || parent === '' ? 'owner' : parent |
There was a problem hiding this comment.
When --parent is omitted, any non-owner permission is parented to owner. For an existing custom permission such as trading (parent active), this silently reparents it and changes who can act on it. Either look up the current parent via the chain API and default to that, or require --parent for anything other than active.
| return { | ||
| account: 'eosio', | ||
| name: 'updateauth', | ||
| authorization: [{actor: account, permission}], |
There was a problem hiding this comment.
Question, not verified: the action is authorized by account@permission (the permission being changed). For a brand-new permission, getRequiredAccounts(account, 'newperm') in the command cannot resolve and throws "could not resolve required accounts" for what may be a valid operation. If chain rules want the parent's (or an existing permission's) authority here, the signer set in requested may also differ from what the chain demands. Worth confirming against a node, with a test for a new permission.
| async run(): Promise<void> { | ||
| const {args, flags: commandFlags} = this.parse(MultisigProposeUpdateauth) | ||
| const authorization = parseAuthorization(args.auth) | ||
| const permission = commandFlags.permission || 'active' |
There was a problem hiding this comment.
commandFlags.permission || 'active' turns an empty --permission (e.g. --permission "$PERM" with an unset variable) into active, silently rewriting the wrong permission. Only default when the flag is undefined and reject an empty string. The help text also describes defaults that oclif doesn't apply.
| accounts: commandFlags.accounts as string | undefined, | ||
| waits: commandFlags.waits as string | undefined, | ||
| }) | ||
| const updateAuthAction = buildUpdateAuthAction({ |
There was a problem hiding this comment.
This builds a proposal that can replace owner or active with no diff of old vs new authority, no warning, and no check that the new key set can satisfy the threshold on its own. A mistyped but valid key becomes permanent lockout once approved and executed. Suggest printing the authority being replaced and the new one, and requiring an explicit confirm flag (e.g. --yes) when --permission owner is used. This is an irreversible account-control change, so it should also go through your compliance/infosec review path.
| 0, | ||
| ) | ||
|
|
||
| // Find required signers |
There was a problem hiding this comment.
This required-signer resolution (and the compareNames-based sort below) duplicates the body of msig:propose, and propose.ts keeps its own private compareNames while utils/updateauth.ts now exports a second copy. A future fix to signer resolution or ordering would have to be made twice, in a signer-selection path. Suggest a shared helper in utils/multisig.ts taking parsedActions, used by both commands.
| .catch((error: Error & {oclif?: {exit?: number}}) => { | ||
| expect(error.oclif?.exit).to.equal(1) | ||
| }) | ||
| .it('exits non-zero when the proposal fails') |
There was a problem hiding this comment.
exits non-zero when the proposal fails is the same command as rejects empty authorities and passes because validation throws, not because a proposal failed. Nothing covers a rejecting network.transact or getRequiredAccounts (including the empty-required-accounts error). Stub one of those to reject and assert the exit code and message.
| assert.deepEqual(requiredAuth.waits, []) | ||
| }) | ||
|
|
||
| it('sorts keys deterministically', () => { |
There was a problem hiding this comment.
Coverage gap: no test sends multiple waits, mixed K1/WA keys, several permissions for one actor, or duplicates through buildRequiredAuth. parseWaitWeights is only tested on its own, so its output is never sorted in a test, which is how the localeCompare crash on wait_sec goes unnoticed. Add those cases (they should fail today).
…fer parent and auth defaults Fix waits crash (numeric compare), sort accounts by (actor, permission) and keys by (type, bytes) with compareNames. Reject weights above uint16, delays and thresholds above uint32, zero waits, and duplicate keys, accounts, and waits. Require explicit --parent for custom permissions and default to the on-chain parent otherwise. Authorize new permissions with the parent authority, require --yes to replace owner, reject empty --permission, print old and proposed authorities, and share signer resolution between msig:propose and msig:propose-updateauth. Cover all of it with tests and sync the README flags.
…ecode-once key sort Validate proposal name, account, permission, and authorization before any chain call. Reject a parent permission that does not exist on the account. Make the new-permission authorization rule explicit via buildUpdateAuthAction actionPermission instead of mutating the built action. Decode authority keys once when sorting instead of per comparison. Rename argument parameters to flagName/label and validName to isValidEosioName. Add tests for all of it.
Match Leap updateauth rules: canonical EOSIO names without trailing-dot aliases, reserved eosio. permissions, immutable parents, active parent owner, existing account authorities, chain maximum delay, the 2^16 authority entry cap, and field-wise WebAuthn key ordering. Reject waits-only satisfaction, self-referential and otherwise invalid direct authorities, and malformed WebAuthn payloads without echoing mistakenly supplied private keys. Dedupe and validate multisig approver resolution, add ABI serialization coverage, and rename sortRequiredAuth to kebab case so touched files pass lint.
|
@squdgy Thanks for the careful review. I fixed the sorting and validation issues, tightened the parent/owner handling, and added tests for the cases you called out. PTAL. |
squdgy
left a comment
There was a problem hiding this comment.
Follow-up review of head 12bc245. The three new commits resolve all nine points from my previous review (numeric wait sort, (actor, permission) account order, type-then-bytes key order, duplicate/range checks, --waits 0, explicit/existing parent, --yes for owner, empty --permission, shared resolveRequestedApprovers, real failing-transact test). I checked these in the code.
What I ran
tsc --noEmit: no errors.test/updateauth-utils.test.tsandtest/msig-utils.test.ts: 38 passing.- Not verified: the oclif command tests (
test/commands/msig-propose-updateauth.test.ts),npm testcoverage and the eslint posttest. Every oclif test file fails to load in my environment (TypeError: Cannot read properties of undefined (reading 'filename')from@oclif/test, Node v24.16.0), and it does the same on master, so this looks environmental, but please confirm in CI.
On the EOSIO rule that updateauth is authorized by the existing permission, or by the parent when the permission is new: that matches my recollection of the chain source, but I did not verify it against a node.
Remaining items are inline. Only the first needs action before merge, in my view.
| } | ||
| } | ||
|
|
||
| export const sortRequiredAuth = (auth: RpcInterfaces.RequiredAuth): void => { |
There was a problem hiding this comment.
Scope note: sortRequiredAuth is also used by permission and contract:enableinline (their imports are renamed in this PR). Their behaviour changes: WA keys are now compared by RP ID bytes instead of localeCompare, key order is now type-then-bytes, and an undecodable key now throws from Numeric.stringToPublicKey instead of being string-compared. The new order is more correct, but neither command has a test, and the PR description doesn't mention it. Suggest a regression test for each command's sort path and a line in the description.
|
|
||
| try { | ||
| return [actor, await network.rpc.get_account(actor)] as const | ||
| } catch { |
There was a problem hiding this comment.
This bare catch reports any get_account failure as account "x" does not exist. A node outage, timeout or rate limit would send the user hunting for a typo. Only map a genuine not-found response to this message and rethrow anything else, and add a test that stubs a non-not-found rejection.
|
|
||
| // A parent that does not exist would only fail at exec, after approvals | ||
| // are collected. Reject it now while the chain state is in hand. | ||
| if (parent !== undefined && parent !== '' && !onChain.permissions.some(entry => entry.perm_name === parent)) { |
There was a problem hiding this comment.
Low: the parent, account, permission and max-delay checks are a snapshot of chain state at propose time. Approvals can take up to expireSeconds (default 7 days), and the state can change before eosio.msig::exec, so a proposal that validates now can still fail at exec. Worth a sentence in the command description or help text.
| throw new Error(`${labels.threshold} ${auth.threshold} exceeds total weight ${total}`) | ||
| } | ||
|
|
||
| const principalWeight = [...auth.keys, ...auth.accounts].reduce((sum, entry) => sum + entry.weight, 0) |
There was a problem hiding this comment.
Low: rejecting authorities that waits alone could satisfy is stricter than the chain requires. It is a sensible safety rule, but it is a policy choice and is not mentioned in the flag help or the PR description. Document it so it isn't a surprise to users who intentionally build delay-based permissions.
Add save-path regression tests for permission and contract:enableinline now that they share canonical authority sorting. Only map genuine account-not-found RPC failures to the missing-account message, document the propose-time chain snapshot caveat, and state the waits-alone threshold policy in help and README.
|
@squdgy pushed fixes for the four remaining items: sort regression tests for permission/enableinline, RPC timeout handling + test, and help/PR notes for the snapshot caveat and waits policy. 80 passing locally on Node 23.11; tsc/eslint clean. PTAL. |
squdgy
left a comment
There was a problem hiding this comment.
Code changes look good to me. @blasrodri How do we test this on testnet before publishing to npm?
Tested the msig:propose-updateauth branch end-to-end on proton-test with account msigtest1111 Happy paths (propose → approve → exec, all verified on-chain): • New permission, 1 K1 key → testperm11 — tx 8598edc3 Negative paths (all rejected client-side, nothing touched chain): bad proposal name, nonexistent parent, |
|
Thanks for this. Nice work, especially the canonical authority sorting. I reviewed it and checked a few things against a live chain using only read RPCs (nothing signed or broadcast). Bug:
The PR description says the goal is to reject authorities that a delay alone could satisfy. That check would be Tests don't exercise real serialization
Things I verified that look right
Minor limitation: the inner |
Follows up on #45, which added generic multisig lifecycle commands but no dedicated flow for the reported WebAuthn-under-multisig updateauth case (Explorer /wallet/msig rejects PUB_WA_ with base-58/checksum errors, and there is no CLI path for it).
What this adds:
Scope notes:
permissionandcontract:enableinlinesave paths; regression tests now cover both.Verification:
tradingpermission authorized by its parentactive, then proposed/approved/executed an updateauth replacingactiveand read the result back from chain state.Example ( victorcrisan shape, threshold-1 WA active ):
proton msig:propose-updateauth waprop victorcrisan ruter1@active --threshold 1 --keys PUB_WA_...