Skip to content

Commit

Permalink
style: solved linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
srdtrk committed Jul 22, 2024
1 parent 2f77913 commit 8f1d3d2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ICS26Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract ICS26Router is IICS26Router, IBCStore, Ownable {
// @return The sequence number of the packet
function sendPacket(MsgSendPacket calldata msg_) external returns (uint32) {
// TODO: implement
IIBCApp app = IIBCApp(apps[msg_.sourcePort]);
// IIBCApp app = IIBCApp(apps[msg_.sourcePort]);
return 0;
}

Expand Down
17 changes: 17 additions & 0 deletions src/errors/IICS24HostErrors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.25;

// @title IBC Store Interface
interface IICS24HostErrors {
/// @param path commitment path
error IBCPacketCommitmentNotFound(bytes path);

/// @param path commitment path
error IBCPacketCommitmentAlreadyExists(bytes path);

/// @param path commitment path
error IBCPacketReceiptAlreadyExists(bytes path);

/// @param path commitment path
error IBCPacketAcknowledgementAlreadyExists(bytes path);
}
29 changes: 24 additions & 5 deletions src/utils/IBCStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ pragma solidity >=0.8.25;
import { IIBCStore } from "./IIBCStore.sol";
import { IICS26RouterMsgs } from "../msgs/IICS26RouterMsgs.sol";
import { ICS24Host } from "./ICS24Host.sol";
import { IICS24HostErrors } from "../errors/IICS24HostErrors.sol";

abstract contract IBCStore is IIBCStore {
abstract contract IBCStore is IIBCStore, IICS24HostErrors {
// Commitments
// keccak256(IBC-compatible-store-path) => keccak256(IBC-compatible-commitment)
// solhint-disable-next-line named-parameters-mapping
Expand Down Expand Up @@ -38,7 +39,11 @@ abstract contract IBCStore is IIBCStore {
// modules/core/04-channel/types/packet.go#L38
function commitPacket(IICS26RouterMsgs.Packet calldata packet) internal {
bytes32 path = ICS24Host.packetCommitmentKeyCalldata(packet.sourcePort, packet.sourceChannel, packet.sequence);
require(commitments[path] == 0, "commitment exists");
if (commitments[path] != 0) {
revert IBCPacketCommitmentAlreadyExists(
ICS24Host.packetCommitmentPathCalldata(packet.sourcePort, packet.sourceChannel, packet.sequence)
);
}

bytes32 commitment = ICS24Host.packetCommitmentBytes32(packet);
commitments[path] = commitment;
Expand All @@ -48,7 +53,11 @@ abstract contract IBCStore is IIBCStore {
// @param packet The packet whose commitment to delete
function deletePacketCommitment(IICS26RouterMsgs.Packet calldata packet) internal {
bytes32 path = ICS24Host.packetCommitmentKeyCalldata(packet.sourcePort, packet.sourceChannel, packet.sequence);
require(commitments[path] != 0, "commitment does not exist");
if (commitments[path] == 0) {
revert IBCPacketCommitmentNotFound(
ICS24Host.packetCommitmentPathCalldata(packet.sourcePort, packet.sourceChannel, packet.sequence)
);
}

delete commitments[path];
}
Expand All @@ -57,7 +66,11 @@ abstract contract IBCStore is IIBCStore {
function setPacketReceipt(IICS26RouterMsgs.Packet calldata packet) internal {
bytes32 path =
ICS24Host.packetReceiptCommitmentKeyCalldata(packet.destPort, packet.destChannel, packet.sequence);
require(commitments[path] == 0, "receipt exists");
if (commitments[path] != 0) {
revert IBCPacketReceiptAlreadyExists(
ICS24Host.packetReceiptCommitmentPathCalldata(packet.destPort, packet.destChannel, packet.sequence)
);
}

commitments[path] = ICS24Host.PACKET_RECEIPT_SUCCESSFUL_KECCAK256;
}
Expand All @@ -66,7 +79,13 @@ abstract contract IBCStore is IIBCStore {
function commitPacketAcknowledgement(IICS26RouterMsgs.Packet calldata packet, bytes calldata ack) internal {
bytes32 path =
ICS24Host.packetAcknowledgementCommitmentKeyCalldata(packet.destPort, packet.destChannel, packet.sequence);
require(commitments[path] == 0, "ack exists");
if (commitments[path] != 0) {
revert IBCPacketAcknowledgementAlreadyExists(
ICS24Host.packetAcknowledgementCommitmentPathCalldata(
packet.destPort, packet.destChannel, packet.sequence
)
);
}

bytes32 commitment = ICS24Host.packetAcknowledgementCommitmentBytes32(ack);
commitments[path] = commitment;
Expand Down

0 comments on commit 8f1d3d2

Please sign in to comment.