Skip to content

fix(ix-proxy): map a source shorter than the index map when the missing tail is dropped - #5

Closed
jpe7s wants to merge 4 commits into
mainfrom
fix/omitted-trailing-optional-accounts
Closed

jpe7s wants to merge 4 commits into
mainfrom
fix/omitted-trailing-optional-accounts

Conversation

@jpe7s

@jpe7s jpe7s commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

A client that follows a codama IDL's omitted optional-account strategy leaves an absent trailing optional account out entirely, so the source instruction arrives with fewer accounts than the index map covers. IxProxyRecord sized the mapped array by the difference and wrote past it, or failed to size it (ArrayIndexOutOfBoundsException or NegativeArraySizeException). It now maps what arrives when every missing position is one the map drops (-1), refuses with a message naming the position and slot when it would have to seat an account it was not given, and still passes accounts beyond the map through as remaining accounts.

The case in hand is the Stake program's authorize and withdraw, whose trailing lockup authority is an optional signer: glamsystems/glam#1393 generates their maps as [4, -1, -1] and [4, -1, -1, -1], so a client that leaves the lockup authority out maps, and one that supplies it has it dropped like any authority the vault stands in for. Against those configs, on main the two-account authorize throws; on this branch it maps to the same accounts as the full form.

Design point, recorded rather than decided here: this mapper maps any short source whose missing positions the map drops, required or optional, because the map carries no such distinction and a missing dropped account maps exactly as a supplied one (two independent refuters confirmed no new mapped instruction becomes reachable). The TypeScript mapper refuses every short source. Narrowing to positions the generator marks omittable would need a config field the v1 schema does not have. The README's index_map section states the rule and the other two places the engines differ on the same document, both older than this PR: the TypeScript mapper refuses index_map values below -1 and non-dense proxy indices at load, where this mapper treats any negative value as dropped and checks no density; and data shorter than a fixed-length discriminator matches nothing there, while this mapper's fixed-length lookup zero-pads it and the mapping then refuses by message. GLAM-1422 carries the alignment.

Tests, OmittedTrailingAccountsTests: every declared account; the trailing dropped ones left out; accounts beyond the map; a missing account the proxy seats; the seat at index zero; and a dropped missing position ahead of a seated one, which a check by counts would pass and then fail at the seat with an index error instead of a refusal. The ported too-few-keys test asserts IllegalStateException and the message naming to at index 4, so a deleted check loop cannot pass it on an index error.

Fuzzing: the harness's catch around the mapping is IllegalStateException, so an index or array error can no longer hide behind it, and it asserts no mapped account is null. Its "payer" entry carried a proxy discriminator and so built a full rewrite; PayerIxProxy was never fuzzed. A third fixed-length entry now builds one, the account pool carries the source program id so the optional-account sentinel swap is reachable, the catch around lookupProxy is gone (neither lookup throws: the fixed-length one zero-pads short data, the scan skips a longer discriminator), and the class doc states the precondition the rejection branch relies on: no configured discriminator ends in a zero byte. Seeds are named for what they pin (four new, three renamed; all 13 replay in check). A 90 s campaign ran 39.5M inputs with no finding.

Hardening: pitestIxProxy -PnoMutationHistory — 341 mutants, 328 killed, the 13 survivors are the accepted baseline rows, none new on the changed lines; pitestIxProxyBaselineRetag moved the two empty-copy-equivalent hints to the guard's new line and the README prose follows. Clusters: Property: a source shorter than the map maps iff every missing position is dropped, refused by position otherwise | Oracle: codama's omitted strategy and the map's -1 meaning | Outcome: production bug, fixed. Property: a mapped instruction never carries a null account | Oracle: sava's Instruction accepts one, the runtime would not | Outcome: missing assertion, fuzz property added.

Merge: squash under this title; c6cb8b0 is typed test: but also touches IxProxyRecord.

Outside this PR: sava's own StakeProgram builders emit the legacy layout with the Clock sysvar, which the generated Stake maps do not fit (the authority lands as a remaining account and GLAM's handlers refuse it). -PglamMappingsDir reaches only Test tasks, not PIT (from 71b00a2); sava-build's minionJvmArgs would carry it, at the cost of a different evidence hash for that override run.

glam-sdk-java consumes ix-proxy 25.0.4; a release with this fix lets it bump.

…ng tail is dropped

A client that follows a codama IDL's omitted optional-account strategy leaves an absent
trailing optional account out entirely (the Stake program's lockup authority), so the
source arrives with fewer accounts than the index map covers. The proxy sized the mapped
array by the difference and read past the accounts it was given, an
ArrayIndexOutOfBoundsException. It now maps what arrives when every missing position is
one the map drops, and refuses by message when it would have to seat an account it was
not given; accounts beyond the map still pass through as remaining accounts.
jpe7s added a commit to glamsystems/glam-sdk-java that referenced this pull request Sep 22, 2026
… set at glam 47df4f7

The Stake program's authorize and withdraw keep a dropped entry for the optional lockup
authority again: supplied, it is dropped; left out, the mapper maps what arrives from
glamsystems/ix-mapper-java#5 on, which this embedding depends on before it merges.
Index zero is a seat like any other; the review of this fix asked for the boundary to be
pinned: a source that leaves out an account the proxy maps there is refused by message.
…divergence recorded

Review of the short-source fix. The check loop already refuses by position, so the
Math.min bound and the reset of the extras loop were redundant and are gone; the earlier
message said the old code read past the accounts, when it wrote past an undersized mapped
array, or failed to size it. A new test pins that which positions are missing decides, not
how many: index_map [-1, -1, 2, -1] with one account is refused by message, where a check by
counts would return a null account. The fixture is named for the shape it models, a Stake
authorize whose map is [4, -1, -1].

This mapper maps any short source whose missing positions the map drops, required or
optional, since the map carries no such distinction and a missing dropped account maps
exactly as a supplied one; the TypeScript mapper refuses every short source. The README's
index_map section and the ported TS test record the difference.

Fuzzing: a seed reaches the short-source success path; the harness asserts that a mapped
instruction carries no null account; and its catch around the mapping is IllegalStateException,
the refusal in contract, so an index or array error can no longer hide behind it.
…DME's prose

pitestIxProxyBaselineRetag moves the two empty-copy-equivalent rows to the line the guard
now sits on; the README's prose named lines the rows had left behind before this branch.
@jpe7s jpe7s closed this Sep 23, 2026
jpe7s added a commit to glamsystems/glam-sdk-java that referenced this pull request Sep 23, 2026
… set at glam 47df4f7

The Stake program's authorize and withdraw keep a dropped entry for the optional lockup
authority again: supplied, it is dropped; left out, the mapper maps what arrives from
glamsystems/ix-mapper-java#5 on, which this embedding depends on before it merges.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant