Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ibc commitments #45

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 e2e/contracts/contracts/Dependencies.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {IBCChannelPacketTimeout} from
"@hyperledger-labs/yui-ibc-solidity/contracts/core/04-channel/IBCChannelPacketTimeout.sol";
import {
IBCChannelUpgradeInitTryAck,
IBCChannelUpgradeConfirmTimeoutCancel
IBCChannelUpgradeConfirmOpenTimeoutCancel
} from "@hyperledger-labs/yui-ibc-solidity/contracts/core/04-channel/IBCChannelUpgrade.sol";
import {IIBCHandler} from "@hyperledger-labs/yui-ibc-solidity/contracts/core/25-handler/IIBCHandler.sol";
import {OwnableIBCHandler} from "@hyperledger-labs/yui-ibc-solidity/contracts/core/25-handler/OwnableIBCHandler.sol";
Expand Down
2 changes: 1 addition & 1 deletion e2e/contracts/contracts/clients/ParliaClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract ParliaClient is ILightClient {
bytes32 private constant CONSENSUS_STATE_TYPE_URL_HASH =
keccak256(abi.encodePacked(CONSENSUS_STATE_TYPE_URL));

uint256 private constant COMMITMENT_SLOT = 0;
bytes32 private constant COMMITMENT_SLOT = 0x1ee222554989dda120e26ecacf756fe1235cd8d726706b57517715dde4f0c900;
uint8 private constant ACCOUNT_STORAGE_ROOT_INDEX = 2;

address internal ibcHandler;
Expand Down
6 changes: 3 additions & 3 deletions e2e/contracts/migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const IBCChannelHandshake = artifacts.require("IBCChannelHandshake");
const IBCChannelPacketSendRecv = artifacts.require("IBCChannelPacketSendRecv");
const IBCChannelPacketTimeout = artifacts.require("IBCChannelPacketTimeout");
const IBCChannelUpgradeInitTryAck = artifacts.require("IBCChannelUpgradeInitTryAck");
const IBCChannelUpgradeConfirmTimeoutCancel = artifacts.require("IBCChannelUpgradeConfirmTimeoutCancel");
const IBCChannelUpgradeConfirmOpenTimeoutCancel = artifacts.require("IBCChannelUpgradeConfirmOpenTimeoutCancel");
const IBCHandler = artifacts.require("OwnableIBCHandler");
const ERC20Token = artifacts.require("ERC20Token");
const ICS20TransferBank = artifacts.require("ICS20TransferBank");
Expand All @@ -18,15 +18,15 @@ module.exports = async function (deployer) {
await deployer.deploy(IBCChannelPacketSendRecv);
await deployer.deploy(IBCChannelPacketTimeout);
await deployer.deploy(IBCChannelUpgradeInitTryAck);
await deployer.deploy(IBCChannelUpgradeConfirmTimeoutCancel);
await deployer.deploy(IBCChannelUpgradeConfirmOpenTimeoutCancel);
await deployer.deploy(IBCHandler,
IBCClient.address,
IBCConnection.address,
IBCChannelHandshake.address,
IBCChannelPacketSendRecv.address,
IBCChannelPacketTimeout.address,
IBCChannelUpgradeInitTryAck.address,
IBCChannelUpgradeConfirmTimeoutCancel.address,
IBCChannelUpgradeConfirmOpenTimeoutCancel.address,
);

await deployer.deploy(ParliaClient, IBCHandler.address);
Expand Down
525 changes: 247 additions & 278 deletions e2e/contracts/package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion e2e/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"author": "",
"license": "ISC",
"dependencies": {
"@hyperledger-labs/yui-ibc-solidity": "git+https://github.com/hyperledger-labs/yui-ibc-solidity.git#v0.3.28"
"@hyperledger-labs/yui-ibc-solidity": "git+https://github.com/hyperledger-labs/yui-ibc-solidity.git#v0.3.35",
"solidity-rlp": "2.0.8",
"solidity-mpt": "0.1.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yoshidan Do you need these dependencies?

},
"devDependencies": {
"@truffle/hdwallet-provider": "^2.1.2",
Expand Down
10 changes: 5 additions & 5 deletions module/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ func (pr *Prover) getAccountProof(height int64) ([]byte, common.Hash, error) {

func (pr *Prover) getStateCommitmentProof(path []byte, height exported.Height) ([]byte, error) {
// calculate slot for commitment
slot := crypto.Keccak256Hash(append(
storageKey := crypto.Keccak256Hash(append(
crypto.Keccak256Hash(path).Bytes(),
common.Hash{}.Bytes()...,
IBCCommitmentsSlot.Bytes()...,
))
marshaledSlot, err := slot.MarshalText()
storageKeyHex, err := storageKey.MarshalText()
if err != nil {
return nil, fmt.Errorf("failed to marshal slot: height = %d, %+v", height.GetRevisionHeight(), err)
}

// call eth_getProof
stateProof, err := pr.chain.GetProof(
pr.chain.IBCAddress(),
[][]byte{marshaledSlot},
[][]byte{storageKeyHex},
big.NewInt(int64(height.GetRevisionHeight())),
)
if err != nil {
return nil, fmt.Errorf("failed to get state commitment proof : address = %s, height = %d, slot = %v, %+v",
pr.chain.IBCAddress(), height.GetRevisionHeight(), marshaledSlot, err)
pr.chain.IBCAddress(), height.GetRevisionHeight(), storageKeyHex, err)
}
return stateProof.StorageProofRLP[0], nil
}
Expand Down
6 changes: 4 additions & 2 deletions module/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package module
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/hyperledger-labs/yui-relayer/log"
"time"

Expand All @@ -16,6 +17,8 @@ import (

var _ core.Prover = (*Prover)(nil)

var IBCCommitmentsSlot = common.HexToHash("1ee222554989dda120e26ecacf756fe1235cd8d726706b57517715dde4f0c900")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yoshidan Can you add a comment // keccak256(abi.encode(uint256(keccak256("ibc.commitment")) - 1)) & ~bytes32(uint256(0xff)) to the above line?


type Prover struct {
chain Chain
config *ProverConfig
Expand Down Expand Up @@ -226,7 +229,6 @@ func (pr *Prover) buildInitialState(dstHeader core.Header) (exported.ClientState
return nil, nil, err
}

var commitmentsSlot [32]byte
latestHeight := toHeight(dstHeader.GetHeight())
clientState := ClientState{
TrustingPeriod: pr.config.TrustingPeriod,
Expand All @@ -235,7 +237,7 @@ func (pr *Prover) buildInitialState(dstHeader core.Header) (exported.ClientState
LatestHeight: &latestHeight,
Frozen: false,
IbcStoreAddress: pr.chain.IBCAddress().Bytes(),
IbcCommitmentsSlot: commitmentsSlot[:],
IbcCommitmentsSlot: IBCCommitmentsSlot[:],
}
consensusState := ConsensusState{
Timestamp: header.Time,
Expand Down
3 changes: 1 addition & 2 deletions tests/prover_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ func (ts *ProverNetworkTestSuite) TestSuccessCreateInitialLightClientState() {
ts.Require().Equal(cs.MaxClockDrift, 1*time.Second)
ts.Require().False(cs.Frozen)
ts.Require().Equal(common.Bytes2Hex(cs.IbcStoreAddress), strings.ToLower(ts.chain.IBCAddress().String()[2:]))
var commitment [32]byte
ts.Require().Equal(common.Bytes2Hex(cs.IbcCommitmentsSlot), common.Bytes2Hex(commitment[:]))
ts.Require().Equal(common.Bytes2Hex(cs.IbcCommitmentsSlot), common.Bytes2Hex(module.IBCCommitmentsSlot[:]))

header, err := ts.chain.Header(context.Background(), cs.GetLatestHeight().GetRevisionHeight())
ts.Require().NoError(err)
Expand Down