Skip to content

[sdk]: clear stale reverse mapping in setEidMapping#876

Merged
Wizdave97 merged 2 commits into
mainfrom
roy/lz-endpoint-stale-eid-reverse-map
May 18, 2026
Merged

[sdk]: clear stale reverse mapping in setEidMapping#876
Wizdave97 merged 2 commits into
mainfrom
roy/lz-endpoint-stale-eid-reverse-map

Conversation

@royvardhan
Copy link
Copy Markdown
Collaborator

@royvardhan royvardhan commented May 18, 2026

Summary

  • HyperbridgeLzEndpoint.setEidMapping previously overwrote the forward map _eidToStateMachine[lzEid] and added a new reverse map entry, but never deleted the prior state machine's reverse entry. Inbound source authorization in onAccept reads only _stateMachineToEid[keccak256(request.source)], so a remapped or "disabled" EID continued to authorize messages from the previously-trusted state machine (incomplete revocation).
  • setEidMapping now reads the prior state machine, deletes its reverse entry if non-empty, writes the new forward, and writes the new reverse only when stateMachineId is non-empty. Clean disable path with no keccak256("") residue.

Tests

Added fork-free unit tests at sdk/packages/lz-endpoint/test/HyperbridgeLzEndpointConfigTest.sol covering:

  • testRemapClearsPriorReverseEntrysetEidMapping(101, A)setEidMapping(101, B) leaves eidFor(A) == 0 and eidFor(B) == 101.
  • testDisableClearsReverseAndAvoidsEmptyKeyResiduesetEidMapping(101, A)setEidMapping(101, hex"") clears eidFor(A), does not populate eidFor(hex""), and isSupportedEid(101) is false.
  • testSetEidMappingIsIdempotent — same args twice ends in byte-identical state.
  • testReassignStateMachineAcrossEidsPointsReverseToLatest — admin remap of the same state machine across two EIDs leaves the reverse pointing to the latest EID; sanity check for behavior under admin mistake.

All 4 tests pass locally:

[PASS] testDisableClearsReverseAndAvoidsEmptyKeyResidue() (gas: 52399)
[PASS] testReassignStateMachineAcrossEidsPointsReverseToLatest() (gas: 90358)
[PASS] testRemapClearsPriorReverseEntry() (gas: 72670)
[PASS] testSetEidMappingIsIdempotent() (gas: 67532)

Split into a separate file from HyperbridgeLzEndpointTest.sol because the new tests are pure config-state checks and don't need the mainnet fork (MAINNET_FORK_URL) that the existing E2E tests require.

@Wizdave97 Wizdave97 merged commit 23a9463 into main May 18, 2026
1 check passed
@Wizdave97 Wizdave97 deleted the roy/lz-endpoint-stale-eid-reverse-map branch May 18, 2026 14:08
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.

2 participants