Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/protocol/switchboard/EVMxSwitchboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ contract EVMxSwitchboard is SwitchboardBase {
* @dev Checks for double attestation, updates state, and emits event
*/
function _processAttestation(bytes32 payloadId_, bytes32 digest_, address watcher_) internal {
if (isAttestedByWatcher[watcher_][payloadId_][digest_]) revert AlreadyAttested();
if (isAttestedByWatcher[watcher_][payloadId_][digest_]) return;
isAttestedByWatcher[watcher_][payloadId_][digest_] = true;
attestations[payloadId_][digest_]++;

Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/switchboard/MessageSwitchboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ contract MessageSwitchboard is SwitchboardBase, ReentrancyGuard {
* @dev Checks for double attestation, updates state, and emits event
*/
function _processAttestation(bytes32 payloadId_, bytes32 digest_, address watcher_) internal {
if (isAttestedByWatcher[watcher_][payloadId_][digest_]) revert AlreadyAttested();
if (isAttestedByWatcher[watcher_][payloadId_][digest_]) return;
isAttestedByWatcher[watcher_][payloadId_][digest_] = true;
attestations[payloadId_][digest_]++;
if (attestations[payloadId_][digest_] >= totalWatchers) isValid[payloadId_][digest_] = true;
Expand Down
13 changes: 10 additions & 3 deletions test/protocol/switchboard/EVMxSwitchboard.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ contract SocketPayloadIdVerificationTest is EVMxSwitchboardTestBase {
assertTrue(evmxSwitchboard.isValid(payloadId, digest), "Digest should be valid");
}

function test_Attest_AlreadyAttested_Reverts() public {
function test_Attest_AlreadyAttested_NoOp() public {
bytes32 digest = keccak256(abi.encode("test payload"));
bytes32 payloadId = bytes32(uint256(0x1234));
bytes memory signature = _createAttestSignature(payloadId, digest);
Expand All @@ -657,10 +657,17 @@ contract SocketPayloadIdVerificationTest is EVMxSwitchboardTestBase {
vm.prank(getWatcherAddress());
evmxSwitchboard.attest(payloadId, digest, signature);

// Second attest - should revert
// Verify state after first attestation
assertTrue(evmxSwitchboard.isAttestedByWatcher(getWatcherAddress(), payloadId, digest));
assertEq(evmxSwitchboard.attestations(payloadId, digest), 1);

// Second attest - should be a no-op (early return), not revert
vm.prank(getWatcherAddress());
vm.expectRevert(AlreadyAttested.selector);
evmxSwitchboard.attest(payloadId, digest, signature);

// Verify state remains unchanged after duplicate attestation
assertTrue(evmxSwitchboard.isAttestedByWatcher(getWatcherAddress(), payloadId, digest));
assertEq(evmxSwitchboard.attestations(payloadId, digest), 1);
}

function test_Attest_InvalidWatcher_Reverts() public {
Expand Down
13 changes: 10 additions & 3 deletions test/protocol/switchboard/MessageSwitchboard.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ contract MessageSwitchboardTest is Test, Utils {
messageSwitchboard.attest(digestParams.payloadId, digest, signature);
}

function test_attest_AlreadyAttested_Reverts() public {
function test_attest_AlreadyAttested_NoOp() public {
// Setup sibling config
_setupSiblingConfig();

Expand All @@ -973,10 +973,17 @@ contract MessageSwitchboardTest is Test, Utils {
vm.prank(getWatcherAddress());
messageSwitchboard.attest(digestParams.payloadId, digest, signature);

// Second attest - should revert
// Verify state after first attestation
assertTrue(messageSwitchboard.isAttestedByWatcher(getWatcherAddress(), payloadId, digest));
assertEq(messageSwitchboard.attestations(payloadId, digest), 1);

// Second attest - should be a no-op (early return), not revert
vm.prank(getWatcherAddress());
vm.expectRevert(AlreadyAttested.selector);
messageSwitchboard.attest(digestParams.payloadId, digest, signature);

// Verify state remains unchanged after duplicate attestation
assertTrue(messageSwitchboard.isAttestedByWatcher(getWatcherAddress(), payloadId, digest));
assertEq(messageSwitchboard.attestations(payloadId, digest), 1);
}

// ============================================
Expand Down