Skip to content

Commit

Permalink
fix more links
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Mar 21, 2024
1 parent d053a1f commit 721f15d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
22 changes: 11 additions & 11 deletions middleware/packet-forward-middleware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Asynchronous acknowledgements are utilized for atomic multi-hop packet flows. Th

## About

The packet-forward-middleware is an IBC middleware module built for Cosmos blockchains utilizing the IBC protocol. A chain which incorporates the
packet-forward-middleware is able to route incoming IBC packets from a source chain to a destination chain. As the Cosmos SDK/IBC become commonplace in the
blockchain space more and more zones will come online, these new zones joining are noticing a problem: they need to maintain a large amount of infrastructure
(archive nodes and relayers for each counterparty chain) to connect with all the chains in the ecosystem, a number that is continuing to increase quickly. Luckily
this problem has been anticipated and IBC has been architected to accommodate multi-hop transactions. However, a packet forwarding/routing feature was not in the
initial IBC release.
The packet-forward-middleware is an IBC middleware module built for Cosmos blockchains utilizing the IBC protocol. A chain which incorporates the
packet-forward-middleware is able to route incoming IBC packets from a source chain to a destination chain. As the Cosmos SDK/IBC become commonplace in the
blockchain space more and more zones will come online, these new zones joining are noticing a problem: they need to maintain a large amount of infrastructure
(archive nodes and relayers for each counterparty chain) to connect with all the chains in the ecosystem, a number that is continuing to increase quickly. Luckily
this problem has been anticipated and IBC has been architected to accommodate multi-hop transactions. However, a packet forwarding/routing feature was not in the
initial IBC release.

## Sequence diagrams

Expand Down Expand Up @@ -100,7 +100,7 @@ memo:
- The packet data `receiver` for the `MsgTransfer` on Chain A is set to `"pfm"` or some other invalid bech32 string.*
- The forward metadata `receiver` for the hop from Chain B to Chain C is set to `"pfm"` or some other invalid bech32 string.*
- The packet `memo` is included in `MsgTransfer` by user on Chain A.
- A packet timeout of 10 minutes and 2 retries is set for both forwards.
- A packet timeout of 10 minutes and 2 retries is set for both forwards.

In the case of a timeout after 10 minutes for either forward, the packet would be retried up to 2 times, at which case an error ack would be written to issue a refund on the prior chain.

Expand Down Expand Up @@ -152,7 +152,7 @@ The examples above show the intended usage of the `receiver` field for one or mu

## Implementation details

Flow sequence mainly encoded in [middleware](packetforward/ibc_middleware.go) and in [keeper](packetforward/keeper/keeper.go).
Flow sequence mainly encoded in [middleware](packetforward/ibc_middleware.go) and in [keeper](packetforward/keeper/keeper.go).

Describes `A` sending to `C` via `B` in several scenarios with operational opened channels, enabled denom composition, fees and available to refund, but no retries.

Expand All @@ -170,13 +170,13 @@ Generally without `memo` to handle, all handling by this module is delegated to
8. `B` Store tracking `in flight packet` under next `(channel, port, ICS-20 transfer sequence)`, do not `ACK` packet yet.
9. `C` Handle ICS-020 packet as usual.
10. `B` On ICS-020 ACK from `C` find `in flight packet`, delete it and write `ACK` for original packet from `A`.
11. `A` Handle ICS-020 `ACK` as usual
11. `A` Handle ICS-020 `ACK` as usual

[Example](https://testnet.mintscan.io/osmosis-testnet/txs/FAB912347B8729FFCA92AC35E6B1E83BC8169DE7CC2C254A5A3F70C8EC35D771?height=3788973) of USDC transfer from Osmosis -> Noble -> Sei
[Example](https://mintscan.io/osmosis-testnet/txs/FAB912347B8729FFCA92AC35E6B1E83BC8169DE7CC2C254A5A3F70C8EC35D771?height=3788973) of USDC transfer from Osmosis -> Noble -> Sei

### A -> B -> C with C error ACK

10. `B` On ICS-020 ACK from `C` find `in flight packet`, delete it
10. `B` On ICS-020 ACK from `C` find `in flight packet`, delete it
11. `B` Burns or escrows tokens.
12. `B` And write error `ACK` for original packet from `A`.
13. `A` Handle ICS-020 timeout as usual
Expand Down
2 changes: 1 addition & 1 deletion middleware/packet-forward-middleware/docs/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Here is an example of how to create an application stack using `transfer` and `p
The following `transferStack` is configured in `app/app.go` and added to the IBC `Router`.
The in-line comments describe the execution flow of packets between the application stack and IBC core.

For more information on configuring an IBC application stack see the ibc-go docs [here](https://github.com/cosmos/ibc-go/blob/main/docs/middleware/ics29-fee/integration.md#configuring-an-application-stack-with-fee-middleware).
For more information on configuring an IBC application stack see the ibc-go docs [here](https://github.com/cosmos/ibc-go/blob/e69a833de764fa0f5bdf0338d9452fd6e579a675/docs/docs/04-middleware/01-ics29-fee/02-integration.md#configuring-an-application-stack-with-fee-middleware).


```go
Expand Down
41 changes: 21 additions & 20 deletions modules/ibc-hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
## IBC hooks

The IBC hooks module is an IBC middleware that enables ICS-20 token transfers to initiate contract calls.
This functionality allows cross-chain contract calls that involve token movement.
This functionality allows cross-chain contract calls that involve token movement.
IBC hooks are useful for a variety of use cases, including cross-chain swaps, which are an extremely powerful primitive.

## How do IBC hooks work?

IBC hooks are made possible through the `memo` field included in every ICS-20 transfer packet, as introduced in [IBC v3.4.0](https://medium.com/the-interchain-foundation/moving-beyond-simple-token-transfers-d42b2b1dc29b).

The IBC hooks IBC middleware parses an ICS20 transfer, and if the `memo` field is of a particular form, executes a Wasm contract call.
The IBC hooks IBC middleware parses an ICS20 transfer, and if the `memo` field is of a particular form, executes a Wasm contract call.

The following sections detail the `memo` format for Wasm contract calls and the execution guarantees provided.

Expand All @@ -33,13 +33,14 @@ type MsgExecuteContract struct {
}
```

For use with IBC hooks, the message fields above can be derived from the following:
For use with IBC hooks, the message fields above can be derived from the following:

- `Sender`: IBC packet senders cannot be explicitly trusted, as they can be deceitful. Chains cannot risk the sender being confused with a particular local user or module address. To prevent this, the `sender` is replaced with an account that represents the sender prefixed by the channel and a Wasm module prefix. This is done by setting the sender to `Bech32(Hash("ibc-wasm-hook-intermediary" || channelID || sender))`, where the `channelId` is the channel id on the local chain.
- `Sender`: IBC packet senders cannot be explicitly trusted, as they can be deceitful. Chains cannot risk the sender being confused with a particular local user or module address. To prevent this, the `sender` is replaced with an account that represents the sender prefixed by the channel and a Wasm module prefix. This is done by setting the sender to `Bech32(Hash("ibc-wasm-hook-intermediary" || channelID || sender))`, where the `channelId` is the channel id on the local chain.
- `Contract`: This field should be directly obtained from the ICS-20 packet metadata
- `Msg`: This field should be directly obtained from the ICS-20 packet metadata.
- `Funds`: This field is set to the amount of funds being sent over in the ICS-20 packet. The denom in the packet must be specified as the counterparty chain's representation of the denom.

<!-- markdown-link-check-disable-next-line -->
> **_WARNING:_** Due to a [bug](https://twitter.com/SCVSecurity/status/1682329758020022272) in the packet forward middleware, we cannot trust the sender from chains that use PFM. Until that is fixed, we recommend chains to not trust the sender on contracts executed via IBC hooks.

Expand All @@ -63,7 +64,7 @@ msg := MsgExecuteContract{
Given the details above, you can propagate the implied ICS-20 packet data structure.
ICS20 is JSON native, so you can use JSON for the memo format.

```json
```json
{
//... other ibc fields that we don't care about
"data":{
Expand All @@ -86,15 +87,15 @@ ICS20 is JSON native, so you can use JSON for the memo format.
An ICS-20 packet is formatted correctly for IBC hooks if all of the following are true:

- The `memo` is not blank.
- The`memo` is valid JSON.
- The`memo` is valid JSON.
- The `memo` has at least one key, with the value `"wasm"`.
- The `memo["wasm"]` has exactly two entries, `"contract"` and `"msg"`.
- The `memo["wasm"]` has exactly two entries, `"contract"` and `"msg"`.
- The `memo["wasm"]["msg"]` is a valid JSON object.
- The `receiver == "" || receiver == memo["wasm"]["contract"]`.
- The `receiver == "" || receiver == memo["wasm"]["contract"]`.

An ICS-20 packet is directed toward IBC hooks if all of the following are true:

- The `memo` is not blank.
- The `memo` is not blank.
- The `memo` is valid JSON.
- The `memo` has at least one key, with the name `"wasm"`.

Expand All @@ -105,7 +106,7 @@ If an ICS-20 packet is directed towards IBC hooks, and is formatted incorrectly,

1. Pre-IBC hooks:

- Ensure the incoming IBC packet is cryptographically valid.
- Ensure the incoming IBC packet is cryptographically valid.
- Ensure the incoming IBC packet is not timed out.

2. In IBC hooks, pre-packet execution:
Expand All @@ -127,14 +128,14 @@ contracts to listen in on the `ack` of specific packets.

### Design

The sender of an IBC transfer packet may specify a callback for when the `Ack` of that packet is received in the memo
field of the transfer packet.
The sender of an IBC transfer packet may specify a callback for when the `Ack` of that packet is received in the memo
field of the transfer packet.

Crucially, **only the IBC packet sender can set the callback**.

### Use case

The cross-chain swaps implementation sends an IBC transfer. If the transfer were to fail, the sender should be able to retrieve their funds which would otherwise be stuck in the contract. To do this, users should be allowed to retrieve the funds after the timeout has passed. However, without the `Ack` information, one cannot guarantee that the send hasn't failed (i.e.: returned an error ack notifying that the receiving chain didn't accept it).
The cross-chain swaps implementation sends an IBC transfer. If the transfer were to fail, the sender should be able to retrieve their funds which would otherwise be stuck in the contract. To do this, users should be allowed to retrieve the funds after the timeout has passed. However, without the `Ack` information, one cannot guarantee that the send hasn't failed (i.e.: returned an error ack notifying that the receiving chain didn't accept it).

### Implementation

Expand Down Expand Up @@ -188,7 +189,7 @@ pub enum SudoMsg {

Follow these steps to install the IBC hooks module. The following lines are all added to `app.go`

1. Import the following packages.
1. Import the following packages.

```go
// import (
Expand All @@ -200,7 +201,7 @@ Follow these steps to install the IBC hooks module. The following lines are all
// )
```

2. Add the module.
2. Add the module.

```go
// var (
Expand All @@ -209,10 +210,10 @@ Follow these steps to install the IBC hooks module. The following lines are all
...
ibchooks.AppModuleBasic{},
...
// )
// )
```

3. Add the IBC hooks keeper.
3. Add the IBC hooks keeper.

```go

Expand All @@ -237,7 +238,7 @@ Follow these steps to install the IBC hooks module. The following lines are all
app.keys[ibchookstypes.StoreKey],
)
app.Ics20WasmHooks = ibchooks.NewWasmHooks(&app.IBCHooksKeeper, nil, AccountAddressPrefix) // The contract keeper needs to be set later

// initialize the wasm keeper with
// wasmKeeper := wasm.NewKeeper( ... )
app.WasmKeeper = &wasmKeeper
Expand All @@ -256,7 +257,7 @@ Follow these steps to install the IBC hooks module. The following lines are all
...
```

5. Register the genesis, begin blocker and end block hooks.
5. Register the genesis, begin blocker and end block hooks.

```go
...
Expand Down Expand Up @@ -358,4 +359,4 @@ Follow these steps to install the IBC hooks module. The following lines are all
```
## Tests

Tests are included in the [tests folder](./tests/testdata/counter/README.md).
Tests are included in the [tests folder](./tests/unit/testdata/counter/README.md).

0 comments on commit 721f15d

Please sign in to comment.