Skip to content

Commit

Permalink
feat(evm): refactor to custom errors/delegate passthrough (#1185)
Browse files Browse the repository at this point in the history
closes #392 
closes #1168
  • Loading branch information
hussein-aitlahcen authored Jan 22, 2024
2 parents 432e324 + e4d7f48 commit c984d2a
Show file tree
Hide file tree
Showing 37 changed files with 1,365 additions and 1,332 deletions.
20 changes: 14 additions & 6 deletions evm/contracts/apps/Base.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
pragma solidity ^0.8.19;
pragma solidity ^0.8.23;

import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/utils/Context.sol";
import "../core/05-port/IIBCModule.sol";

library IBCAppLib {
error ErrNotIBC();
}

/**
* @dev Base contract of the IBC App protocol
*/
Expand All @@ -24,10 +28,9 @@ abstract contract IBCAppBase is Context, IIBCModule {
* @dev Throws if the sender is not the IBC contract.
*/
function _checkIBC() internal view virtual {
require(
ibcAddress() == _msgSender(),
"IBCAppBase: caller is not the IBC contract"
);
if (ibcAddress() != _msgSender()) {
revert IBCAppLib.ErrNotIBC();
}
}

/**
Expand Down Expand Up @@ -128,6 +131,11 @@ abstract contract IBCAppBase is Context, IIBCModule {
address relayer
) external virtual override onlyIBC {}

/**
* @dev See IIBCModule-onTimeoutPacket
*
* NOTE: You should apply an `onlyIBC` modifier to the function if a derived contract overrides it.
*/
function onTimeoutPacket(
IbcCoreChannelV1Packet.Data calldata packet,
address relayer
Expand Down
16 changes: 8 additions & 8 deletions evm/contracts/apps/ucs/00-pingpong/PingPong.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ contract PingPong is IBCAppBase {
IbcCoreChannelV1Packet.Data calldata packet,
address relayer
) external virtual override onlyIBC returns (bytes memory acknowledgement) {
PingPongPacket memory packet = PingPongPacketLib.decode(packet.data);
emit Ring(packet.ping);
uint64 counterpartyTimeoutRevisionNumber = packet
PingPongPacket memory pp = PingPongPacketLib.decode(packet.data);
emit Ring(pp.ping);
uint64 counterpartyTimeoutRevisionNumber = pp
.counterpartyTimeoutRevisionNumber;
uint64 counterpartyTimeoutRevisionHeight = packet
uint64 counterpartyTimeoutRevisionHeight = pp
.counterpartyTimeoutRevisionHeight;
packet.ping = !packet.ping;
packet.counterpartyTimeoutRevisionNumber = revisionNumber;
packet.counterpartyTimeoutRevisionHeight =
pp.ping = !pp.ping;
pp.counterpartyTimeoutRevisionNumber = revisionNumber;
pp.counterpartyTimeoutRevisionHeight =
uint64(block.number) +
numberOfBlockBeforePongTimeout;
initiate(
packet,
pp,
counterpartyTimeoutRevisionNumber,
counterpartyTimeoutRevisionHeight
);
Expand Down
2 changes: 1 addition & 1 deletion evm/contracts/apps/ucs/01-relay/ERC20Denom.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.8.23;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/token/ERC20/ERC20.sol";
import "./IERC20Denom.sol";

contract ERC20Denom is ERC20, IERC20Denom {
Expand Down
2 changes: 1 addition & 1 deletion evm/contracts/apps/ucs/01-relay/IERC20Denom.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.8.23;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/token/ERC20/IERC20.sol";

interface IERC20Denom is IERC20 {
function mint(address to, uint256 amount) external;
Expand Down
Loading

0 comments on commit c984d2a

Please sign in to comment.