Skip to content

Commit

Permalink
Merge pull request #73 from open-ibc/thomas/registry
Browse files Browse the repository at this point in the history
feat: add polymer registry
  • Loading branch information
tmsdkeys authored Apr 15, 2024
2 parents d284e48 + c21dfb5 commit eaefc30
Show file tree
Hide file tree
Showing 28 changed files with 353 additions and 366 deletions.
17 changes: 0 additions & 17 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,3 @@ BASE_ALCHEMY_API_KEY=''
OP_BLOCKSCOUT_API_KEY=''
BASE_BLOCKSCOUT_API_KEY=''
# TENDERLY_TOKEN=''

# Contract addresses last updated on 2024-03-05, for public testnet launch
OP_DISPATCHER='0x58f1863f75c9db1c7266dc3d7b43832b58f35e83'
BASE_DISPATCHER='0xfc1d3e02e00e0077628e8cc9edb6812f95db05dc'

OP_UC_MW='0x34a0e37cCCEdaC70EC1807e5a1f6A4a91D4AE0Ce'
BASE_UC_MW='0x50E32e236bfE4d514f786C9bC80061637dd5AF98'

# Contract addresses for the sim-client
OP_DISPATCHER_SIM="0x6C9427E8d770Ad9e5a493D201280Cc178125CEc0"
BASE_DISPATCHER_SIM="0x0dE926fE2001B2c96e9cA6b79089CEB276325E9F"

OP_UC_MW_SIM='0xC3318ce027C560B559b09b1aA9cA4FEBDDF252F5'
BASE_UC_MW_SIM='0x5031fb609569b67608Ffb9e224754bb317f174cD'

# Configuration file the scripts will use, defaulting to config.json when not set
CONFIG_PATH='config.json'
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/polymer-registry-poc"]
path = lib/polymer-registry-poc
url = https://github.com/tmsdkeys/polymer-registry-poc
17 changes: 12 additions & 5 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ install:
npm install
forge install --shallow

# Build config file at location specified in the .env file
# Usage: just build-config
build-config SOURCE DESTINATION:
echo "Building config file..."
node utils/buildConfig.js {{SOURCE}} {{DESTINATION}}

# Compile contracts using the specified compiler or default to Hardhat
# The compiler argument is optional; if not provided, it defaults to "hardhat".
# Usage: just compile [compiler]
Expand Down Expand Up @@ -62,13 +68,14 @@ send-packet SOURCE:
echo "Sending a packet with the values from the config..."
node scripts/private/_send-packet-config.js {{SOURCE}}

# DEPRECATED: Use single config file per client type
# Switch between the sim client and the client with proofs
# Usage: just switch-client
switch-client:
echo "Switching between sim client and client with proofs..."
npx hardhat run scripts/private/_update-vibc-address.js --network optimism
npx hardhat run scripts/private/_update-vibc-address.js --network base
node scripts/private/_switch-clients.js
# switch-client:
# echo "Switching between sim client and client with proofs..."
# npx hardhat run scripts/private/_update-vibc-address.js --network optimism
# npx hardhat run scripts/private/_update-vibc-address.js --network base
# node scripts/private/_switch-clients.js

# Run the full E2E flow by setting the contracts, deploying them, creating a channel, and sending a packet
# Usage: just do-it
Expand Down
88 changes: 38 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,26 @@ Additionally Hardhat will be installed as a dev dependency with some useful plug

> Note: In case you're experiencing issues with dependencies using the `just install` recipe, check that all prerequisites are correctly installed. If issues persist with forge, try to do the individual dependency installations...
## ⚙️ Set up your environment variables
## ⚙️ Set up your environment and configuration

The idea is to ensure that most configuration to add Polymer's vIBC is added as custom data in the configuration file of your development environment, e.g. Hardhat or Foundry. (Note that at the time of writing, only Hardhat is fully supported).

Make sure to add network information to the Hardhat configuration for all supported networks you're interested in building on, following this schema:
```javascript
networks: {
// for OP testnet
optimism: {
url: 'https://sepolia.optimism.io',
alchemyRPC: `https://opt-sepolia.g.alchemy.com/v2/${process.env.OP_ALCHEMY_API_KEY}`,
accounts: [process.env.PRIVATE_KEY_1],
chainId: 11155420,
}
}
```

Especially make sure the chain ID is added as it will be used to fetch the correct data from the Polymer registry by ID, while you can locally refer to the chain as the name you've specified in the Hardhat config.

### Environment variables

Convert the `.env.example` file into an `.env` file. This will ignore the file for future git commits as well as expose the environment variables. Add your private keys and update the other values if you want to customize (advanced usage feature).

Expand All @@ -55,17 +74,23 @@ This will enable you to sign transactions with your private key(s). If not added

The configuration file is where all important data is stored for the just commands and automation. We strive to make direct interaction with the config file as little as possible.

By default the configuration file is stored at root as `config.json`.
By default the configuration file is stored in the config folder as `config.json`.

However, it is recommended to split up different contracts/projects in the same repo into different config file in case you want to switch between them.
> 💡 However, it is recommended to split up different contracts/projects in the same repo into different config files in case you want to switch between them.
Store alternate config files in the /config directory and set
```sh
# .env file
CONFIG_PATH='config/alt-config.json'
Store alternate config files in the /config directory and set the path in the Hardhat coniguration file:
```javascript
// path to configuration file the scripts will use for Polymer's vibc, defaulting to config/config.json when not set
vibcConfigPath: 'config/alt-config.json',
```
to use a different config file.

Contrary to previous version, you have to build the default configuration file by specifying the networks (from the Hardhat config) you want it to include:
```sh
# Usage: just build-config SOURCE DESTINATION
just build-config optimism base
```

### Obtaining testnet ETH

The account associated with your private key must have both Base Sepolia and Optimism Sepolia ETH. To obtain the testnet ETH visit:
Expand Down Expand Up @@ -240,56 +265,19 @@ to send a packet over a channel (script looks at the config's isUniversal flag t

## Verify, don't trust

As a starter value, the sim-client is used to improve latency. **The sim-client is useful for iterative development and testing BUT also insecure as it involves no proofs**. Make sure to move to the client **with proofs** by running another just command...
As a starter value, the sim-client is used to improve latency. **The sim-client is useful for iterative development and testing BUT also insecure as it involves no proofs**. Make sure to move to the client **with proofs** by setting the `proofsEnabled` flag in the config file to true:

```bash
# Usage: just switch-client
just switch-client
```

This will use the op-stack client with proofs, making sure that the relayer is proving what is being submitted every step along the way, ensuring there's no trust assumption on the relayer.

An overview of the different clients can be found in `ibc.json`:
```json
// In config/proof-config.json
{
"optimism": {
"sim-client": {
"canonConnFrom": "connection-0",
"canonConnTo": "connection-1",
"universalChannel": "channel-10"
},
"op-client": {
"canonConnFrom": "connection-8",
"canonConnTo": "connection-9",
"universalChannel": "channel-16"
}
},
"base": {
"sim-client" : {
"canonConnFrom": "connection-4",
"canonConnTo": "connection-5",
"universalChannel": "channel-11"
},
"op-client": {
"canonConnFrom": "connection-10",
"canonConnTo": "connection-11",
"universalChannel": "channel-17"
}
}
...,
"proofsEnabled": true,
...
}
```

## 🦾 Advanced usage

For advanced users, there's multiple custimizations to follow. These includes configuring the config.json manually and/or running the scripts without using just.

For example, the last action to send a packet on a universal channel could be executed with this command:

```bash
npx hardhat run scripts/send-universal-packet.js --network base
```

To send a universal packet from the contract specified in the config.sendUniversalPacket field in the config.
This will use the op-stack client with proofs, making sure that the relayer is proving what is being submitted every step along the way, ensuring there's no trust assumption on the relayer.

## 🤝 Contributing

Expand Down
42 changes: 0 additions & 42 deletions config/alt-config.json

This file was deleted.

21 changes: 10 additions & 11 deletions config.json → config/config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"proofsEnabled": false,
"isUniversal": true,
"deploy": {
"optimism": "XCounterUC",
"base": "XCounterUC"
"optimism": "",
"molten": ""
},
"isUniversal": true,
"createChannel": {
"srcChain": "optimism",
"srcChain": "",
"srcAddr": "0x1234567890AbCdEf1234567890aBcDeF12345678",
"dstChain": "base",
"dstChain": "",
"dstAddr": "0x1234567890AbCdEf1234567890aBcDeF12345678",
"version": "1.0",
"ordering": 0,
Expand All @@ -20,7 +20,7 @@
"channelId": "channel-n",
"timeout": 36000
},
"base": {
"molten": {
"portAddr": "0x1234567890abcdef1234567890abcdef12345678",
"channelId": "channel-n",
"timeout": 36000
Expand All @@ -29,14 +29,13 @@
"sendUniversalPacket": {
"optimism": {
"portAddr": "0x1234567890abcdef1234567890abcdef12345678",
"channelId": "channel-x",
"channelId": "channel-n",
"timeout": 36000
},
"base": {
"molten": {
"portAddr": "0x1234567890abcdef1234567890abcdef12345678",
"channelId": "channel-y",
"channelId": "channel-n",
"timeout": 36000
}
},
"backup": {}
}
}
19 changes: 8 additions & 11 deletions contracts/XCounter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.9;

import './base/CustomChanIbcApp.sol';
import "./base/CustomChanIbcApp.sol";

contract XCounter is CustomChanIbcApp {
// app specific state
Expand All @@ -28,7 +28,6 @@ contract XCounter is CustomChanIbcApp {
* @param channelId The ID of the channel (locally) to send the packet to.
* @param timeoutSeconds The timeout in seconds (relative).
*/

function sendPacket( bytes32 channelId, uint64 timeoutSeconds) external {
// incrementing counter on source chain
increment();
Expand All @@ -46,14 +45,14 @@ contract XCounter is CustomChanIbcApp {
/**
* @dev Packet lifecycle callback that implements packet receipt logic and returns and acknowledgement packet.
* MUST be overriden by the inheriting contract.
*
* @param packet the IBC packet encoded by the source and relayed by the relayer.
*/
function onRecvPacket(IbcPacket memory packet) external override onlyIbcDispatcher returns (AckPacket memory ackPacket) {
recvedPackets.push(packet);
// decoding the caller address from the packet data
address _caller = abi.decode(packet.data, (address));
// updating the counterMap with the caller address and incrementing the counter
counterMap[packet.sequence] = _caller;

increment();

return AckPacket(true, abi.encode(counter));
Expand All @@ -62,24 +61,22 @@ contract XCounter is CustomChanIbcApp {
/**
* @dev Packet lifecycle callback that implements packet acknowledgment logic.
* MUST be overriden by the inheriting contract.
*
* @param ack the acknowledgment packet encoded by the destination and relayed by the relayer.
*/
function onAcknowledgementPacket(IbcPacket calldata, AckPacket calldata ack) external override onlyIbcDispatcher {
ackPackets.push(ack);

// decoding the counter from the acknowledgment packet
(uint64 _counter) = abi.decode(ack.data, (uint64));

if (_counter != counter) {
resetCounter();
}
// resetting the counter if the counter in the acknowledgment packet is different from the local counter
if (_counter != counter) {
resetCounter();
}
}

/**
* @dev Packet lifecycle callback that implements packet receipt logic and return and acknowledgement packet.
* MUST be overriden by the inheriting contract.
* NOT SUPPORTED YET
*
* @param packet the IBC packet encoded by the counterparty and relayed by the relayer
*/
function onTimeoutPacket(IbcPacket calldata packet) external override onlyIbcDispatcher {
Expand Down
10 changes: 3 additions & 7 deletions contracts/XCounterUC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ contract XCounterUC is UniversalChanIbcApp {
/**
* @dev Packet lifecycle callback that implements packet receipt logic and returns and acknowledgement packet.
* MUST be overriden by the inheriting contract.
*
* @param channelId the ID of the channel (locally) the packet was received on.
* @param packet the Universal packet encoded by the source and relayed by the relayer.
*/
Expand All @@ -53,10 +52,10 @@ contract XCounterUC is UniversalChanIbcApp {
returns (AckPacket memory ackPacket)
{
recvedPackets.push(UcPacketWithChannel(channelId, packet));

// decode the packet data
(address payload, uint64 c) = abi.decode(packet.appData, (address, uint64));
// update the counterMap with the caller address and increment the counter
counterMap[c] = payload;

increment();

return AckPacket(true, abi.encode(counter));
Expand All @@ -65,7 +64,6 @@ contract XCounterUC is UniversalChanIbcApp {
/**
* @dev Packet lifecycle callback that implements packet acknowledgment logic.
* MUST be overriden by the inheriting contract.
*
* @param channelId the ID of the channel (locally) the ack was received on.
* @param packet the Universal packet encoded by the source and relayed by the relayer.
* @param ack the acknowledgment packet encoded by the destination and relayed by the relayer.
Expand All @@ -76,10 +74,9 @@ contract XCounterUC is UniversalChanIbcApp {
onlyIbcMw
{
ackPackets.push(UcAckWithChannel(channelId, packet, ack));

// decode the counter from the ack packet
(uint64 _counter) = abi.decode(ack.data, (uint64));

// reset the counter if the counter in the ack packet is different from the local counter
if (_counter != counter) {
resetCounter();
}
Expand All @@ -89,7 +86,6 @@ contract XCounterUC is UniversalChanIbcApp {
* @dev Packet lifecycle callback that implements packet receipt logic and return and acknowledgement packet.
* MUST be overriden by the inheriting contract.
* NOT SUPPORTED YET
*
* @param channelId the ID of the channel (locally) the timeout was submitted on.
* @param packet the Universal packet encoded by the counterparty and relayed by the relayer
*/
Expand Down
Loading

0 comments on commit eaefc30

Please sign in to comment.