@@ -4,7 +4,7 @@ pragma solidity ^0.8.21;
44import "./SocketUtils.sol " ;
55
66import {WRITE} from "../utils/common/Constants.sol " ;
7- import {createPayloadId } from "../utils/common/IdUtils.sol " ;
7+ import {getVerificationInfo } from "../utils/common/IdUtils.sol " ;
88
99/**
1010 * @title Socket
@@ -31,7 +31,10 @@ contract Socket is SocketUtils {
3131 error LowGasLimit ();
3232 /// @notice Thrown when the message value is insufficient
3333 error InsufficientMsgValue ();
34-
34+ /// @notice Thrown when the verification chain slug is invalid
35+ error InvalidVerificationChainSlug ();
36+ /// @notice Thrown when the verification switchboard id is invalid
37+ error InvalidVerificationSwitchboardId ();
3538 /**
3639 * @notice Constructor for the Socket contract
3740 * @param chainSlug_ The chain slug
@@ -70,11 +73,15 @@ contract Socket is SocketUtils {
7073 if (msg .value < executeParams_.value + transmissionParams_.socketFees)
7174 revert InsufficientMsgValue ();
7275
73- bytes32 payloadId = createPayloadId (
74- executeParams_.payloadPointer,
75- switchboardId,
76- chainSlug
77- );
76+ // Get payloadId from executeParams
77+ bytes32 payloadId = executeParams_.payloadId;
78+
79+ // Verify payload ID matches destination
80+ (uint32 verificationChainSlug , uint32 verificationSwitchboardId ) = getVerificationInfo (payloadId);
81+ if (verificationChainSlug != chainSlug)
82+ revert InvalidVerificationChainSlug ();
83+ if (verificationSwitchboardId != uint32 (switchboardId))
84+ revert InvalidVerificationSwitchboardId ();
7885
7986 // validate the execution status
8087 _validateExecutionStatus (payloadId);
@@ -93,7 +100,7 @@ contract Socket is SocketUtils {
93100 * @notice Verifies the digest of the payload
94101 * @param payloadId_ The id of the payload
95102 * @param switchboardId_ The id of the switchboard
96- * @param executeParams_ The execution parameters (appGatewayId, value, payloadPointer , callType, gasLimit)
103+ * @param executeParams_ The execution parameters (appGatewayId, value, payloadId , callType, gasLimit)
97104 * @param transmitterProof_ The transmitter proof
98105 */
99106 function _verify (
@@ -129,7 +136,7 @@ contract Socket is SocketUtils {
129136 /**
130137 * @notice Executes the payload
131138 * @param payloadId_ The id of the payload
132- * @param executeParams_ The execution parameters (appGatewayId, value, payloadPointer , callType, gasLimit)
139+ * @param executeParams_ The execution parameters (appGatewayId, value, payloadId , callType, gasLimit)
133140 * @param transmissionParams_ The transmission parameters (socketFees, transmitterProof, refundAddress)
134141 */
135142 function _execute (
@@ -185,52 +192,43 @@ contract Socket is SocketUtils {
185192 }
186193
187194 ////////////////////////////////////////////////////////
188- ////////////////////// Trigger //////////////////////
195+ ////////////////////// Outbound Payloads //////////////////////
189196 ////////////////////////////////////////////////////////
190197
191198 /**
192- * @notice To trigger to a connected remote chain. Should only be called by a plug.
193- * @param data_ The data to trigger the app gateway
194- * @return triggerId The id of the trigger
199+ * @notice Sends a payload to a connected remote chain (used for both triggers and messages)
200+ * @dev Should only be called by a plug. The switchboard will create the payload ID.
201+ * @param data_ The payload data
202+ * @return payloadId The created payload ID
195203 */
196- function triggerAppGateway (bytes calldata data_ ) external payable returns (bytes32 triggerId ) {
197- triggerId = _triggerAppGateway (msg .sender , msg .value , data_);
204+ function sendPayload (bytes calldata data_ ) external payable returns (bytes32 payloadId ) {
205+ payloadId = _sendPayload (msg .sender , msg .value , data_);
198206 }
199207
200208 /**
201- * @notice To trigger to a connected remote chain. Should only be called by a plug.
209+ * @notice Internal function to send a payload to a connected remote chain
202210 * @param plug_ The address of the plug
203- * @param value_ The value to trigger the app gateway
204- * @param data_ The data to trigger the app gateway
205- * @return triggerId The id of the trigger
211+ * @param value_ The value to send with the payload
212+ * @param data_ The payload data
213+ * @return payloadId The created payload ID from the switchboard
206214 */
207- function _triggerAppGateway (
215+ function _sendPayload (
208216 address plug_ ,
209217 uint256 value_ ,
210218 bytes calldata data_
211- ) internal returns (bytes32 triggerId ) {
219+ ) internal returns (bytes32 payloadId ) {
212220 (uint64 switchboardId , address switchboardAddress ) = _verifyPlugSwitchboard (plug_);
213221 bytes memory plugOverrides = IPlug (plug_).overrides ();
214- triggerId = _encodeTriggerId ();
215222
216- // todo: need gas limit?
217- ISwitchboard (switchboardAddress).processTrigger {value: value_}(
223+ // Switchboard creates the payload ID and emits PayloadRequested event
224+ payloadId = ISwitchboard (switchboardAddress).processPayload {value: value_}(
218225 plug_,
219- triggerId,
220226 data_,
221227 plugOverrides
222228 );
223-
224- emit AppGatewayCallRequested (
225- triggerId,
226- bytes32 (0 ), // TODO: clean this up
227- switchboardId,
228- toBytes32Format (plug_),
229- plugOverrides,
230- data_
231- );
232229 }
233230
231+
234232 /**
235233 * @notice Increase fees for a pending payload
236234 * @param payloadId_ The payload ID to increase fees for
@@ -256,13 +254,13 @@ contract Socket is SocketUtils {
256254 switchboardAddress = switchboardAddresses[switchboardId];
257255 }
258256 /**
259- * @notice Fallback function that forwards all calls to Socket's callAppGateway
260- * @dev The calldata is passed as-is to the gateways
261- * @return The trigger id
257+ * @notice Fallback function that forwards all calls to Socket's sendPayload
258+ * @dev The calldata is passed as-is to the switchboard
259+ * @return The payload ID
262260 */
263261 fallback (bytes calldata ) external payable returns (bytes memory ) {
264- // return the trigger id
265- return abi.encode (_triggerAppGateway (msg .sender , msg .value , msg .data ));
262+ // return the payload ID
263+ return abi.encode (_sendPayload (msg .sender , msg .value , msg .data ));
266264 }
267265
268266 /**
0 commit comments