Skip to content

Commit

Permalink
[cantina finding #7] enhanced logs
Browse files Browse the repository at this point in the history
  • Loading branch information
voith committed Feb 23, 2025
1 parent 9c8615b commit 69aa559
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
4 changes: 3 additions & 1 deletion contracts/ccip/GovernanceCCIPReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ contract GovernanceCCIPReceiver is IGovernanceCCIPReceiver, CCIPReceiver {
internal
override
{
bytes32 messageId = message.messageId;

// Validate chain selector
require(
message.sourceChainSelector == mainnetChainSelector,
Expand All @@ -54,6 +56,6 @@ contract GovernanceCCIPReceiver is IGovernanceCCIPReceiver, CCIPReceiver {
(bool success, ) = target.call(payload);
require(success, MessageCallFailed());

emit MessageExecuted(target, payload);
emit MessageExecuted(messageId, target, payload);
}
}
2 changes: 1 addition & 1 deletion contracts/ccip/GovernanceCCIPRelay.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,6 @@ contract GovernanceCCIPRelay is IGovernanceCCIPRelay {
require(success, FailedToRefundEth());
}

emit MessageRelayed(target, payload);
emit MessageRelayed(messageId, target, payload);
}
}
13 changes: 9 additions & 4 deletions contracts/ccip/interfaces/IGovernanceCCIPReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.s
*/
interface IGovernanceCCIPReceiver {
/// @notice Emitted when a message is successfully executed.
/// @param messageId The ccip message id.
/// @param target The target address on the destination chain.
/// @param payload The payload of the message.
event MessageExecuted(address indexed target, bytes payload);

/// @dev Error thrown when a provided address is the zero address.
error AddressCannotBeZero();
event MessageExecuted(
bytes32 indexed messageId,
address indexed target,
bytes payload
);

/// @dev Error thrown when a provided address is the zero address.
error AddressCannotBeZero();

/// @dev Error thrown when an unauthorized caller tries to execute a restricted function.
/// @param caller The address of the unauthorized caller.
Expand Down
15 changes: 10 additions & 5 deletions contracts/ccip/interfaces/IGovernanceCCIPRelay.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@ import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/
*/
interface IGovernanceCCIPRelay {
/// @notice Emitted when a governance message is relayed.
/// @param messageId The ccip message id.
/// @param target The target address of the execution.
/// @param payload The calldata payload executed.
event MessageRelayed(address indexed target, bytes payload);
event MessageRelayed(
bytes32 indexed messageId,
address indexed target,
bytes payload
);

/// @notice Emitted when a new destination chain is added.
/// @param chainSelector The CCIP chain selector of the destination chain.
/// @param receiver The address of the receiver contract on the destination chain.
event DestinationChainAdded(uint64 indexed chainSelector, address receiver);

/// @dev Error thrown when a provided address is the zero address.
error AddressCannotBeZero();
/// @dev Error thrown when a provided address is the zero address.
error AddressCannotBeZero();

/// @dev Error thrown when payload is empty.
error PayloadCannotBeEmpty();
/// @dev Error thrown when payload is empty.
error PayloadCannotBeEmpty();

/// @dev Error thrown when an unauthorized caller tries to execute a restricted function.
error Unauthorized(address caller);
Expand Down
12 changes: 4 additions & 8 deletions test/ccip/GovernanceCCIPIntegrationTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,16 @@ contract GovernanceCCIPIntegrationTest is Test {

// Send the message via GovernanceRelay
vm.deal(address(timelock), fee); // Fund the contract with enough Ether
vm.expectEmit(true, true, true, true);
emit IGovernanceCCIPRelay.MessageRelayed(target, payload);
vm.prank(address(timelock));
governanceRelay.relayMessage{value: fee}(
bytes32 messageId = governanceRelay.relayMessage{value: fee}(
polygonMainnetChainSelector,
target,
payload
);

// Route the message to Polygon
vm.expectEmit(true, true, true, true);
emit IGovernanceCCIPReceiver.MessageExecuted(target, payload);
emit IGovernanceCCIPReceiver.MessageExecuted(messageId, target, payload);
ccipLocalSimulatorFork.switchChainAndRouteMessage(polygonMainnetForkId);

// Verify the message was received and executed on Polygon
Expand Down Expand Up @@ -275,17 +273,15 @@ contract GovernanceCCIPIntegrationTest is Test {
abi.encode(fee)
);
vm.deal(address(timelock), fee);
vm.expectEmit(true, true, true, true);
emit IGovernanceCCIPRelay.MessageRelayed(target, payload);
vm.prank(address(timelock));
governanceRelay.relayMessage{value: fee}(
bytes32 messageId = governanceRelay.relayMessage{value: fee}(
polygonMainnetChainSelector,
target,
payload
);

vm.expectEmit(true, true, true, true);
emit IGovernanceCCIPReceiver.MessageExecuted(target, payload);
emit IGovernanceCCIPReceiver.MessageExecuted(messageId, target, payload);
ccipLocalSimulatorFork.switchChainAndRouteMessage(polygonMainnetForkId);

vm.selectFork(polygonMainnetForkId);
Expand Down
1 change: 1 addition & 0 deletions test/ccip/GovernanceCCIPReceiverTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ contract GovernanceCCIPReceiverTest is Test {
vm.prank(ccipRouter);
vm.expectEmit(true, true, true, true);
emit IGovernanceCCIPReceiver.MessageExecuted(
bytes32(""),
address(numberUpdater),
payload
);
Expand Down
2 changes: 1 addition & 1 deletion test/ccip/GovernanceCCIPRelayTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ contract GovernanceCCIPRelayTest is Test {

vm.prank(timelock);
vm.expectEmit(true, true, true, true);
emit IGovernanceCCIPRelay.MessageRelayed(target, payload);
emit IGovernanceCCIPRelay.MessageRelayed(bytes32(""), target, payload);
relay.relayMessage{value: fee}(destinationChainSelector, target, payload);
}

Expand Down

0 comments on commit 69aa559

Please sign in to comment.