-
Notifications
You must be signed in to change notification settings - Fork 11
Fix watcher #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix watcher #214
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2fba849
feat: updated payloadId implementation
tHeMaskedMan981 101fb60
Merge branch 'phase-1' of https://github.com/SocketDotTech/socket-pro…
tHeMaskedMan981 0dac919
Merge branch 'phase-1' of https://github.com/SocketDotTech/socket-pro…
tHeMaskedMan981 4c55c6a
feat: added payloadId tests, fixed old tests
tHeMaskedMan981 933900b
feat: updated deposit to trigger
tHeMaskedMan981 e1e990b
fix: lint
ameeshaagrawal e7970bf
fix: trigger
ameeshaagrawal 0ccbc51
fix: watcher and transmitter fees
ameeshaagrawal 8cbd5b7
fix: promise retryable with deadline
ameeshaagrawal 5b62e53
fix: tests
ameeshaagrawal 8672361
fix: switchboardId, counter type change. idUtils optimize
tHeMaskedMan981 3c8f98f
Merge pull request #211 from SocketDotTech/feat/id
arthcp 1334556
Merge pull request #212 from SocketDotTech/fix/fee-deposit-to-trigger
arthcp d5f20eb
Merge branch 'phase-1' into fix-watcher
ameeshaagrawal 73e6c78
fix: bugs
ameeshaagrawal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| # Payload ID Architecture - Unified Design | ||
|
|
||
| ## Overview | ||
| Unified payload ID structure for all three payload types: Write, Trigger, and Message. | ||
|
|
||
| ## Payload ID Structure | ||
|
|
||
| ### Bit Layout (256 bits total) | ||
| ``` | ||
| [Origin: 64 bits][Verification: 64 bits][Pointer: 64 bits][Reserved: 64 bits] | ||
| ``` | ||
|
|
||
| Each component breakdown: | ||
| - **Origin (64 bits)**: `chainSlug (32 bits) | switchboardId/watcherId (32 bits)` | ||
| - **Verification (64 bits)**: `chainSlug (32 bits) | switchboardId/watcherId (32 bits)` | ||
| - **Pointer (64 bits)**: Counter value | ||
| - **Reserved (64 bits)**: For future extensibility | ||
|
|
||
| ## Payload Type Specifications | ||
|
|
||
| ### 1. Write Payloads (EVMX → On-chain) | ||
| - **Origin**: `evmxChainSlug (32) | watcherId (32)` | ||
| - Generated by: Watcher (on EVMX) | ||
| - Verified by: Watcher offchain (links source) | ||
| - **Verification**: `dstChainSlug (32) | dstSwitchboardId (32)` | ||
| - Generated by: Watcher (from config) | ||
| - Used by: Socket for routing | ||
| - **Pointer**: `payloadCounter (64)` | ||
| - Generated by: Watcher (switchboard-specific counter) | ||
|
|
||
| **Where Created**: `Watcher.sol` → `getCurrentPayloadId()` | ||
|
|
||
| ### 2. Trigger Payloads (On-chain → EVMX) | ||
| - **Origin**: `srcChainSlug (32) | srcSwitchboardId (32)` | ||
| - Generated by: FastSwitchboard | ||
| - Verified by: Watcher offchain (verifies source) | ||
| - **Verification**: `evmxChainSlug (32) | watcherId (32)` | ||
| - Generated by: FastSwitchboard (from stored config) | ||
| - Used by: Socket for routing | ||
| - **Pointer**: `switchboardCounter (64)` | ||
| - Generated by: FastSwitchboard (switchboard-specific counter) | ||
|
|
||
| **Where Created**: `FastSwitchboard.sol` → `processPayload()` | ||
|
|
||
| ### 3. Message Payloads (Plug → Plug) | ||
| - **Origin**: `srcChainSlug (32) | srcSwitchboardId (32)` | ||
| - Generated by: MessageSwitchboard | ||
| - Verified by: Destination switchboard (checks source) | ||
| - **Verification**: `dstChainSlug (32) | dstSwitchboardId (32)` | ||
| - Generated by: MessageSwitchboard | ||
| - Used by: Socket for routing | ||
| - **Pointer**: `switchboardCounter (64)` | ||
| - Generated by: MessageSwitchboard (switchboard-specific counter) | ||
|
|
||
| **Where Created**: `MessageSwitchboard.sol` → `_createDigestAndPayloadId()` | ||
|
|
||
| ## Decoding and Verification | ||
|
|
||
| ### Socket Verification (Destination) | ||
| 1. Decode `payloadId` using `getVerificationInfo(payloadId)` | ||
| 2. Extract `verificationChainSlug` and `verificationSwitchboardId` | ||
| 3. Verify against local config: | ||
| - `verificationChainSlug == local chainSlug` | ||
| - `verificationSwitchboardId == local switchboardId` | ||
|
|
||
| ### Source Verification (Off-chain Watcher) | ||
| 1. Decode `payloadId` using `getOriginInfo(payloadId)` | ||
| 2. Extract `originChainSlug` and `originId` | ||
| 3. Verify source configuration matches expected values | ||
|
|
||
| ### Payload Type Detection | ||
| - Check if `originChainSlug` or `verificationChainSlug` matches `evmxChainSlug` | ||
| - If `originChainSlug == evmxChainSlug`: **Write Payload** | ||
| - If `verificationChainSlug == evmxChainSlug`: **Trigger Payload** | ||
| - If neither: **Message Payload** | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| ### IdUtils.sol Functions | ||
|
|
||
| #### Encoding | ||
| - `createPayloadId(originChainSlug, originId, verificationChainSlug, verificationId, pointer)` | ||
| - Creates new payload ID with all components | ||
|
|
||
| #### Decoding | ||
| - `decodePayloadId(payloadId)` - Full decode | ||
| - `getVerificationInfo(payloadId)` - Gets verification components (for Socket routing) | ||
| - `getOriginInfo(payloadId)` - Gets origin components (for source verification) | ||
|
|
||
| ### Required Updates | ||
|
|
||
| 1. **Watcher.sol** | ||
| - Update `getCurrentPayloadId()` to use new format | ||
| - Use `evmxSlug` as origin chain slug | ||
| - Use hardcoded `watcherId = 1` for now | ||
| - Get `dstSwitchboardId` from `switchboards` mapping | ||
|
|
||
| 2. **FastSwitchboard.sol** | ||
| - Add state variables: `evmxChainSlug`, `watcherId` (with onlyOwner setters) | ||
| - Implement `processPayload()` to create payload ID | ||
| - Add counter: `uint64 public triggerPayloadCounter` | ||
| - Use: `origin = (chainSlug, switchboardId)`, `verification = (evmxChainSlug, watcherId)` | ||
|
|
||
| 3. **MessageSwitchboard.sol** | ||
| - Update `_createDigestAndPayloadId()` to use new format | ||
| - Use: `origin = (chainSlug, switchboardId)`, `verification = (dstChainSlug, dstSwitchboardId)` | ||
|
|
||
| 4. **Socket.sol** | ||
| - Update `execute()` to decode payload ID and verify verification components | ||
| - Remove old `createPayloadId` usage | ||
| - Use `getVerificationInfo()` to extract routing info | ||
|
|
||
| 5. **SocketConfig.sol** | ||
| - Update `plugSwitchboardIds` type from `uint64` to `uint32` if needed (or keep uint64 and cast) | ||
|
|
||
| ## Security Considerations | ||
|
|
||
| ### Verification Flow | ||
| 1. **Destination (Socket)**: Verifies verification component matches local config | ||
| 2. **Source (Watcher offchain)**: Verifies origin component matches expected source | ||
| 3. **Pointer verification**: Skipped for now (to be added later) | ||
|
|
||
| ### Counter Management | ||
| - Each switchboard maintains its own counter | ||
| - Prevents cross-switchboard collisions | ||
| - Counters are monotonic (never decrease) | ||
|
|
||
| ### ID Uniqueness | ||
| - Guaranteed by switchboard-specific counters | ||
| - Origin + Verification provide additional context | ||
| - Reserved bits allow future expansion without breaking changes | ||
|
|
||
| ## Migration Notes | ||
|
|
||
| - No production deployments yet, so no migration needed | ||
| - All existing test code will need updates | ||
| - Backward compatibility not required | ||
|
|
||
| ## Future Enhancements | ||
|
|
||
| - Add pointer verification mechanism | ||
| - Use reserved bits for additional metadata (payload version, flags, etc.) | ||
| - Support multiple watchers (remove hardcoded watcherId = 1) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.