Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7e58f5b
IBC-2: fix to update channel commitment in `timeoutPacket()`
bluele Nov 23, 2024
2e03fe8
Merge pull request #302 from hyperledger-labs/audit-202409-ibc-2
bluele Nov 23, 2024
baddaf2
IBC-3: fix to ensure `connection.state` is `OPEN` in `channelOpenAck()`
bluele Nov 23, 2024
9375b2a
Merge pull request #304 from hyperledger-labs/audit-202409-ibc-3
bluele Nov 23, 2024
877957b
IBC-4: fix to ensure the commitment of consensus state corresponding …
bluele Nov 23, 2024
4d59343
Merge pull request #305 from hyperledger-labs/audit-202409-ibc-4
bluele Nov 24, 2024
2b90889
IBC-5: delete packet commitment in `timeoutOnClose()`
bluele Nov 23, 2024
037ce6f
Merge pull request #307 from hyperledger-labs/audit-202409-ibc-5
bluele Nov 24, 2024
6321e35
IBC-14: clarify which sequence commitments are stored
bluele Nov 25, 2024
3b309dd
IBC-7: fix to remove state check in `timeoutPacket()` and `timeoutOnC…
bluele Nov 25, 2024
c9efed2
Merge pull request #308 from hyperledger-labs/audit-202409-ibc-7
bluele Nov 26, 2024
43f77d2
split `IBCChannelUpgradeBase` into two contracts
bluele Nov 24, 2024
deac22d
add `counterpartyUpgradeTimeout` to the storage
bluele Nov 24, 2024
eadd74c
introduce `hostHeight()` and check whether `upgradeTimeout` has passe…
bluele Nov 24, 2024
b36720b
Merge pull request #309 from hyperledger-labs/audit-202409-ibc-1
bluele Nov 29, 2024
c13824e
IBC-8: fix missing checks on `revision_number`
bluele Nov 25, 2024
ba1ce2b
use cancun for e2e-test
bluele Nov 25, 2024
9759e51
Merge pull request #310 from hyperledger-labs/audit-202409-ibc-8
bluele Dec 2, 2024
4a6f4c9
Merge pull request #313 from hyperledger-labs/audit-202409-ibc-14
bluele Dec 4, 2024
7e97315
IBC-11: fix `clientType` and `clientId` validations
bluele Nov 25, 2024
952f782
Merge pull request #311 from hyperledger-labs/audit-202409-ibc-11
bluele Dec 4, 2024
9c6b1c8
improve docs for `routerUpdateClient()`
bluele Nov 25, 2024
530737c
Merge pull request #312 from hyperledger-labs/audit-202409-ibc-12
bluele Dec 4, 2024
6ace215
S7: improve validation for `Version` in `connectionOpenInit()`
bluele Nov 25, 2024
718fe09
S8: remove redundant ERC165 checks
bluele Nov 25, 2024
1a8e20d
S1: improve comments for connection
bluele Nov 26, 2024
3c82e7a
S6: fix incorrect comment for `channelOpenConfirm()`
bluele Nov 26, 2024
c690dde
S4: fix to add address validation for `IBCClientConnectionChannelHand…
bluele Nov 26, 2024
11c488e
S3: separate `TimeoutPacket` event for `timeoutPacket()` and `timeout…
bluele Nov 26, 2024
15ecd73
S9: add some fields to `IBCChannelUnexpectedNextSequenceRecv` error
bluele Dec 4, 2024
61c65ec
Merge pull request #314 from hyperledger-labs/audit-202409-suggestions
bluele Dec 4, 2024
93311b1
fix to check if the generated channel ID is not already stored
bluele Dec 5, 2024
476a6d8
add main deviations from ibc spec to `architecture.md`
bluele Dec 5, 2024
0471691
Merge pull request #315 from hyperledger-labs/audit-202409-ibc-15
bluele Dec 5, 2024
af68fc1
IBC-6: add module developer warning to doc of `sendPacket()`
bluele Dec 6, 2024
3788b23
Merge pull request #316 from hyperledger-labs/audit-202409-ibc-6
bluele Dec 9, 2024
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FOUNDRY_PROFILE=default
FORGE=FOUNDRY_PROFILE=$(FOUNDRY_PROFILE) forge
SOLC_VERSION=0.8.24
EVM_VERSION=paris
EVM_VERSION=cancun
DOCKER=docker
ABIGEN="$(DOCKER) run -v .:/workspace -w /workspace -it ethereum/client-go:alltools-v1.11.6 abigen"
SOLHINT=npx solhint
Expand All @@ -16,7 +16,7 @@ TEST_UPGRADEABLE=false

.PHONY: build
build:
$(FORGE) build --sizes --skip test --use solc:$(SOLC_VERSION)
$(FORGE) build --sizes --skip test --use solc:$(SOLC_VERSION) --evm-version $(EVM_VERSION)

.PHONY: clean
clean:
Expand All @@ -33,7 +33,7 @@ lint:

.PHONY: test
test:
TEST_UPGRADEABLE=$(TEST_UPGRADEABLE) $(FORGE) test -vvvv --gas-report --isolate --use solc:$(SOLC_VERSION)
TEST_UPGRADEABLE=$(TEST_UPGRADEABLE) $(FORGE) test -vvvv --gas-report --isolate --use solc:$(SOLC_VERSION) --evm-version $(EVM_VERSION)

.PHONY: snapshot
snapshot:
Expand Down
3 changes: 2 additions & 1 deletion chains/ibft2/chain0/ibftConfigFile.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"genesis": {
"config": {
"chainId": 2018,
"muirglacierblock": 0,
"cancunTime": 0,
"zeroBaseFee": true,
"ibft2": {
"blockperiodseconds": 1,
"epochlength": 30000,
Expand Down
3 changes: 2 additions & 1 deletion chains/ibft2/chain1/ibftConfigFile.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"genesis": {
"config": {
"chainId": 3018,
"muirglacierblock": 0,
"cancunTime": 0,
"zeroBaseFee": true,
"ibft2": {
"blockperiodseconds": 1,
"epochlength": 30000,
Expand Down
2 changes: 1 addition & 1 deletion chains/qbft/chain0/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hyperledger/besu:24.3.0
FROM hyperledger/besu:24.10.0

USER root

Expand Down
3 changes: 2 additions & 1 deletion chains/qbft/chain0/qbftConfigFile.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"genesis": {
"config": {
"chainId": 2018,
"muirglacierblock": 0,
"cancunTime": 0,
"zeroBaseFee": true,
"qbft": {
"blockperiodseconds": 1,
"epochlength": 30000,
Expand Down
2 changes: 1 addition & 1 deletion chains/qbft/chain1/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hyperledger/besu:24.3.0
FROM hyperledger/besu:24.10.0

USER root

Expand Down
3 changes: 2 additions & 1 deletion chains/qbft/chain1/qbftConfigFile.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"genesis": {
"config": {
"chainId": 3018,
"muirglacierblock": 0,
"cancunTime": 0,
"zeroBaseFee": true,
"qbft": {
"blockperiodseconds": 1,
"epochlength": 30000,
Expand Down
5 changes: 2 additions & 3 deletions contracts/core/04-channel/IBCChannelPacketSendRecv.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ contract IBCChannelPacketSendRecv is
revert IBCChannelUnexpectedPacketSource(msg_.packet.sourcePort, msg_.packet.sourceChannel);
}

if (msg_.packet.timeoutHeight.revision_height != 0 && block.number >= msg_.packet.timeoutHeight.revision_height)
{
revert IBCChannelTimeoutPacketHeight(block.number, msg_.packet.timeoutHeight.revision_height);
if (!msg_.packet.timeoutHeight.isZero() && hostHeight().gte(msg_.packet.timeoutHeight)) {
revert IBCChannelTimeoutPacketHeight(hostHeight(), msg_.packet.timeoutHeight);
}
if (msg_.packet.timeoutTimestamp != 0 && hostTimestamp() >= msg_.packet.timeoutTimestamp) {
revert IBCChannelTimeoutPacketTimestamp(hostTimestamp(), msg_.packet.timeoutTimestamp);
Expand Down
18 changes: 10 additions & 8 deletions contracts/core/04-channel/IBCChannelUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Height} from "../../proto/Client.sol";
import {ConnectionEnd} from "../../proto/Connection.sol";
import {Channel, ChannelCounterparty, Upgrade, UpgradeFields, ErrorReceipt, Timeout} from "../../proto/Channel.sol";
import {ILightClient} from "../02-client/ILightClient.sol";
import {IBCHeight} from "../02-client/IBCHeight.sol";
import {IBCConnectionLib} from "../03-connection/IBCConnectionLib.sol";
import {IIBCConnectionErrors} from "../03-connection/IIBCConnectionErrors.sol";
import {IIBCChannelErrors} from "./IIBCChannelErrors.sol";
Expand Down Expand Up @@ -219,6 +220,8 @@ contract IBCChannelUpgradeInitTryAck is
IIBCConnectionErrors,
IIBCChannelErrors
{
using IBCHeight for Height.Data;

/**
* @dev See {IIBCChannelUpgrade-channelUpgradeInit}
*/
Expand Down Expand Up @@ -421,9 +424,9 @@ contract IBCChannelUpgradeInitTryAck is

// counterparty-specified timeout must not have exceeded
// if it has, then restore the channel and abort upgrade handshake
Timeout.Data calldata timeout = msg_.counterpartyUpgrade.timeout;
Timeout.Data memory timeout = msg_.counterpartyUpgrade.timeout;
if (
(timeout.height.revision_height != 0 && block.number >= timeout.height.revision_height)
(!timeout.height.isZero() && hostHeight().gte(timeout.height))
|| (timeout.timestamp != 0 && hostTimestamp() >= timeout.timestamp)
) {
restoreChannel(msg_.portId, msg_.channelId, UpgradeHandshakeError.Timeout);
Expand Down Expand Up @@ -547,6 +550,8 @@ contract IBCChannelUpgradeConfirmOpenTimeoutCancel is
IBCChannelUpgradeCommon,
IIBCChannelUpgradeConfirmOpenTimeoutCancel
{
using IBCHeight for Height.Data;

/**
* @dev See {IIBCChannelUpgrade-channelUpgradeConfirm}
*/
Expand Down Expand Up @@ -586,9 +591,9 @@ contract IBCChannelUpgradeConfirmOpenTimeoutCancel is

// counterparty-specified timeout must not have exceeded
// if it has, then restore the channel and abort upgrade handshake
Timeout.Data calldata timeout = msg_.counterpartyUpgrade.timeout;
Timeout.Data memory timeout = msg_.counterpartyUpgrade.timeout;
if (
(timeout.height.revision_height != 0 && block.number >= timeout.height.revision_height)
(!timeout.height.isZero() && hostHeight().gte(timeout.height))
|| (timeout.timestamp != 0 && hostTimestamp() >= timeout.timestamp)
) {
restoreChannel(msg_.portId, msg_.channelId, UpgradeHandshakeError.Timeout);
Expand Down Expand Up @@ -764,10 +769,7 @@ contract IBCChannelUpgradeConfirmOpenTimeoutCancel is
// Either timeoutHeight or timeoutTimestamp must be defined.
// if timeoutHeight is defined and proof is from before
// timeout height then abort transaction
if (
upgrade.timeout.height.revision_height != 0
&& msg_.proofHeight.revision_height < upgrade.timeout.height.revision_height
) {
if (!upgrade.timeout.height.isZero() && msg_.proofHeight.lt(upgrade.timeout.height)) {
revert IBCChannelUpgradeTimeoutHeightNotReached();
}
// if timeoutTimestamp is defined then the consensus time
Expand Down
4 changes: 2 additions & 2 deletions contracts/core/04-channel/IIBCChannelErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ interface IIBCChannelErrors {

error IBCChannelAckAlreadyProcessedInPreviousUpgrade(uint64 sequence, uint64 ackStartSequence);

/// @param currentBlockNumber current block number
/// @param currentHeight current height
/// @param timeoutHeight packet timeout height
error IBCChannelTimeoutPacketHeight(uint256 currentBlockNumber, uint64 timeoutHeight);
error IBCChannelTimeoutPacketHeight(Height.Data currentHeight, Height.Data timeoutHeight);

/// @param currentTimestamp current timestamp
/// @param timeoutTimestamp packet timeout timestamp
Expand Down
4 changes: 4 additions & 0 deletions contracts/core/25-handler/IBCQuerier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ contract IBCQuerier is IBCModuleManager, IIBCQuerier {
return _getCommitmentPrefix();
}

function getRevisionNumber() public view override returns (uint64) {
return _getRevisionNumber();
}

function getCommitmentsSlot() public pure override returns (bytes32) {
return COMMITMENT_STORAGE_LOCATION;
}
Expand Down
2 changes: 2 additions & 0 deletions contracts/core/25-handler/IIBCQuerier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {IIBCModule, IIBCModuleInitializer} from "../26-router/IIBCModule.sol";
interface IIBCQuerier {
function getCommitmentPrefix() external view returns (bytes memory);

function getRevisionNumber() external view returns (uint64);

function getCommitmentsSlot() external pure returns (bytes32);

function getCommitment(bytes32 hashedPath) external view returns (bytes32);
Expand Down
33 changes: 32 additions & 1 deletion pkg/contract/ibchandler/ibchandler.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pkg/testing/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ func (chain *Chain) WaitForReceiptAndGet(ctx context.Context, tx *gethtypes.Tran
func (chain *Chain) WaitIfNoError(ctx context.Context, txName string) func(tx *gethtypes.Transaction, err error) error {
return func(tx *gethtypes.Transaction, err error) error {
if err != nil {
return fmt.Errorf("failed to call transaction: tx=%v err='%v'", txName, err)
return fmt.Errorf("failed to call transaction: tx=%v txPayload=%#v err='%v'", txName, tx, err)
}
return chain.WaitForReceiptAndGet(ctx, tx, txName)
}
Expand Down Expand Up @@ -1290,6 +1290,8 @@ func makeGenTxOpts(chainID *big.Int, prv *ecdsa.PrivateKey) func(ctx context.Con
// Set non-zero value to avoid call `estimateGas`
// This allows we can extract the revert reason from the transaction receipt if the transaction fails.
GasLimit: 6382056,
// Use legacy tx
GasPrice: big.NewInt(0),
Signer: func(address common.Address, tx *gethtypes.Transaction) (*gethtypes.Transaction, error) {
if address != addr {
return nil, errors.New("not authorized to sign this account")
Expand Down
4 changes: 2 additions & 2 deletions tests/foundry/src/ICS04Packet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ contract TestICS04Packet is
vm.expectRevert(
abi.encodeWithSelector(
IIBCChannelErrors.IBCChannelTimeoutPacketHeight.selector,
getBlockNumber(),
p0.timeoutHeight.revision_height
H(getBlockNumber()),
p0.timeoutHeight
)
);
counterpartyHandler.recvPacket(msg_);
Expand Down