Skip to content

Commit

Permalink
Merge branch 'main' into rp/fix-make-test
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Dec 13, 2024
2 parents 27f24a5 + caa8175 commit 33b6ca9
Show file tree
Hide file tree
Showing 20 changed files with 267 additions and 139 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: lint
on:
pull_request:

jobs:
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- uses: golangci/[email protected]
with:
version: v1.61.0
args: --timeout 10m
github-token: ${{ secrets.github_token }}
# hadolint lints the Dockerfile
hadolint:
uses: celestiaorg/.github/.github/workflows/[email protected]
with:
dockerfile: "docker/Dockerfile"

yamllint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: celestiaorg/.github/.github/actions/[email protected]
7 changes: 7 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"default": true # Default state for all rules
"MD010":
"code_blocks": false # Disable rule for hard tabs in code blocks
"MD013": false # Disable rule for line length
"MD033": false # Disable rule banning inline HTML
"MD055":
"style": "leading_and_trailing" # Instead of "consistent" (default) which can vary per file, use one style across the entire project
1 change: 1 addition & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
solidity-ibc-eureka/
12 changes: 12 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# Built from docs https://yamllint.readthedocs.io/en/stable/configuration.html
extends: default

rules:
# 120 chars should be enough, but don't fail if a line is longer
line-length:
max: 120
level: warning

ignore:
- solidity-ibc-eureka/
11 changes: 6 additions & 5 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# IBC ZK-EVM Architecture Document

*This is a work in progress designed to describe all the components needed for transferring tokens from Celestia to a ZK proven EVM*
> [!NOTE]
> This is a work in progress designed to describe all the components needed for transferring tokens from Celestia to a ZK proven EVM
To provide some context on what we’re trying to achieve, we’re going to start with describing the user flow for transferring TIA to a ZK EVM (Based of the current flow)

Expand All @@ -9,14 +10,14 @@ To provide some context on what we’re trying to achieve, we’re going to star
1. A user submits a `MsgTransfer` to the Celestia chain. Celestia performs some validation checks on the message, then transfers the user’s funds to a module account, effectively locking the funds. The chain then creates a `Commitment` , a receipt of the successful execution of that message as well as an event emitted containing a `Packet` with information to send to the EVM rollup
2. A relayer listens for the event. It queries a Celestia consensus node for the `Commitment` in the state tree along with the merkle proof, proving the inclusion of that data. The relayer submits the packet along with the inclusion proofs to the rollups namespace.
3. The rollup full node validates the Celestia header as part of it’s STF, thus it does not require an `UpdateClient` message. It can be assumed that it always has the latest state root for verifying Celestia state. Reading the namespace it validates the `Commitment` and it’s inclusion in Celestia state. It then mints TIA (or the IBC denomination equivalent) and sends it to the recipient address. Similar to Celestia, it saves an `AcknowledgementCommitment` in state.
4. The relayer listens to the acknowledgement event, queries the state of the EVM Rollup alongside the 1) STF proof in groth16 form, 2) State inclusion proof of the `AcknowledgementCommitment` (as a Merkle Patricia Trie Proof). It submits a transaction with the first proof and often multiple second proofs batched together to Celestia.
4. The relayer listens to the acknowledgement event, queries the state of the EVM Rollup alongside the 1) STF proof in groth16 form, 2) State inclusion proof of the `AcknowledgementCommitment` (as a Merkle Patricia Trie Proof). It submits a transaction with the first proof and often multiple second proofs batched together to Celestia.
5. Celestia validates the groth16 proof to update the EVM state root it has stored, it verifies the `Acknowledgement` in the EVM state using the inclusion proof. It then cancels the pending timeout thus confirming the transfer. Alternatively, after a timeout period, a timeout message can be sent to Celestia which will unlock the funds returning them to the user.

To transfer back follows a similar process except, instead of minting tokens, the EVM proves that they burned the tokens and Celestia proves back to the EVM that it released the tokens and gave it back to the user.

## Architecture

The architecture involves several different logical components:
The architecture involves several different logical components:

- User + Light Node: Performs actions on either chain or rollup and uses the light client to verify every interaction
- Data Availability Layer (DA): Publishes a canonical serialised stream of transactions for rollup full nodes and light nodes alike to read and execute. Here we have a convention of separating the STF proofs and the rollup data into separate namespaces. The Celestia namespace can be one or more namespaces that Celestia validators read and execute over.
Expand All @@ -31,7 +32,7 @@ The architecture involves several different logical components:

Celestia will track the state roots of the ZK EVM through a ZK IBC Client. To update it, the relayer needs to submit a transaction with a groth16 proof and the public inputs (trusted reference height, new height, new state root etc.)

RSP has a circuit for proving the execution of a single block.
RSP has a circuit for proving the execution of a single block.

We need to write a circuit that proves the following computation:

Expand All @@ -54,7 +55,7 @@ type PublicWitness struct {
}
```

**API**
## API

The prover needs to provide an API for the relayer to query aggregated proofs to submit to Celestia to update the IBC client state.

Expand Down
10 changes: 0 additions & 10 deletions ibc/lightclients/groth16/changes.md

This file was deleted.

37 changes: 3 additions & 34 deletions ibc/lightclients/groth16/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
sdkerrors "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/celestiaorg/celestia-zkevm-ibc-demo/ibc/mpt"
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
Expand All @@ -32,10 +31,10 @@ func NewClientState(
genesisStateRoot []byte,
) *ClientState {
return &ClientState{
LatestHeight: latestHeight,
LatestHeight: latestHeight,
// StateTransitionVerifierKey: stateTransitionVerifierKey,
CodeCommitment: codeCommitment,
GenesisStateRoot: genesisStateRoot,
CodeCommitment: codeCommitment,
GenesisStateRoot: genesisStateRoot,
}
}

Expand Down Expand Up @@ -94,36 +93,6 @@ func (cs ClientState) initialize(ctx context.Context, cdc codec.BinaryCodec, cli
return nil
}

// verifyDelayPeriodPassed will ensure that at least delayTimePeriod amount of time and delayBlockPeriod number of blocks have passed
// since consensus state was submitted before allowing verification to continue.
func verifyDelayPeriodPassed(ctx sdk.Context, store storetypes.KVStore, proofHeight exported.Height, delayTimePeriod, delayBlockPeriod uint64) error {
// check that executing chain's timestamp has passed consensusState's processed time + delay time period
processedTime, ok := GetProcessedTime(store, proofHeight)
if !ok {
return sdkerrors.Wrapf(ErrProcessedTimeNotFound, "processed time not found for height: %s", proofHeight)
}
currentTimestamp := uint64(ctx.BlockTime().UnixNano())
validTime := processedTime + delayTimePeriod
// NOTE: delay time period is inclusive, so if currentTimestamp is validTime, then we return no error
if currentTimestamp < validTime {
return sdkerrors.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until time: %d, current time: %d",
validTime, currentTimestamp)
}
// check that executing chain's height has passed consensusState's processed height + delay block period
processedHeight, ok := GetProcessedHeight(store, proofHeight)
if !ok {
return sdkerrors.Wrapf(ErrProcessedHeightNotFound, "processed height not found for height: %s", proofHeight)
}
currentHeight := clienttypes.GetSelfHeight(ctx)
validHeight := clienttypes.NewHeight(processedHeight.GetRevisionNumber(), processedHeight.GetRevisionHeight()+delayBlockPeriod)
// NOTE: delay block period is inclusive, so if currentHeight is validHeight, then we return no error
if currentHeight.LT(validHeight) {
return sdkerrors.Wrapf(ErrDelayPeriodNotPassed, "cannot verify packet until height: %s, current height: %s",
validHeight, currentHeight)
}
return nil
}

//------------------------------------

// The following are modified methods from the v9 IBC Client interface. The idea is to make
Expand Down
26 changes: 4 additions & 22 deletions ibc/lightclients/groth16/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ const (
)

var (
height = clienttypes.NewHeight(0, 4)
newClientHeight = clienttypes.NewHeight(1, 1)
upgradePath = []string{"upgrade", "upgradedIBCState"}
invalidUpgradePath = []string{"upgrade", ""}
height = clienttypes.NewHeight(0, 4)
newClientHeight = clienttypes.NewHeight(1, 1)
upgradePath = []string{"upgrade", "upgradedIBCState"}
)

type ClientConfig interface {
Expand All @@ -48,8 +47,7 @@ type Grtoth16Config struct {
}

func NewGrtoth16Config() *Grtoth16Config {
return &Grtoth16Config{
}
return &Grtoth16Config{}
}

func (*Grtoth16Config) GetClientType() string {
Expand Down Expand Up @@ -115,22 +113,6 @@ func (suite *Groth16TestSuite) SetupTest() {
suite.ctx = app.BaseApp.NewContext(checkTx)
}

func getAltSigners(altVal *cmttypes.Validator, altPrivVal cmttypes.PrivValidator) map[string]cmttypes.PrivValidator {
return map[string]cmttypes.PrivValidator{altVal.Address.String(): altPrivVal}
}

func getBothSigners(suite *Groth16TestSuite, altVal *cmttypes.Validator, altPrivVal cmttypes.PrivValidator) (*cmttypes.ValidatorSet, map[string]cmttypes.PrivValidator) {
// Create bothValSet with both suite validator and altVal. Would be valid update
bothValSet := cmttypes.NewValidatorSet(append(suite.valSet.Validators, altVal))
// Create signer array and ensure it is in same order as bothValSet
_, suiteVal := suite.valSet.GetByIndex(0)
bothSigners := map[string]cmttypes.PrivValidator{
suiteVal.Address.String(): suite.privVal,
altVal.Address.String(): altPrivVal,
}
return bothValSet, bothSigners
}

func TestGroth16TestSuite(t *testing.T) {
testifysuite.Run(t, new(Groth16TestSuite))
}
2 changes: 0 additions & 2 deletions ibc/lightclients/groth16/light_client_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/cosmos/cosmos-sdk/codec"

"github.com/celestiaorg/celestia-zkevm-ibc-demo/x/header"
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
Expand All @@ -20,7 +19,6 @@ var _ exported.LightClientModule = (*LightClientModule)(nil)
type LightClientModule struct {
cdc codec.BinaryCodec
storeProvider clienttypes.StoreProvider
headerKeeper header.Keeper
}

// NewLightClientModule creates and returns a new zk LightClientModule.
Expand Down
6 changes: 3 additions & 3 deletions ibc/lightclients/groth16/light_client_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/celestiaorg/celestia-zkevm-ibc-demo/ibc/lightclients/groth16"
"github.com/celestiaorg/celestia-zkevm-ibc-demo/ibc/mpt"
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types"
commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors"
Expand Down Expand Up @@ -255,7 +254,8 @@ func (suite *Groth16TestSuite) TestVerifyMembership() {

// get the proof for the key
proof := mpt.ProofList{}
trie.Prove(mptKey, &proof)
err := trie.Prove(mptKey, &proof)
suite.Require().NoError(err)

proofBytes, err := mpt.ProofListToBytes(proof)
suite.Require().NoError(err)
Expand All @@ -276,7 +276,7 @@ func (suite *Groth16TestSuite) TestVerifyMembership() {

// set consensus state to the trie root
consensusState := testingpath.EndpointB.GetConsensusState(latestHeight).(*ibctm.ConsensusState)
root := types.NewMerkleRoot(trie.Hash().Bytes())
root := commitmenttypes.NewMerkleRoot(trie.Hash().Bytes())
newConsState := ibctm.ConsensusState{
Timestamp: consensusState.Timestamp,
Root: root,
Expand Down
3 changes: 1 addition & 2 deletions ibc/lightclients/groth16/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v9/modules/core/exported"

)

// VerifyClientMessage checks if the clientMessage is of type Header
Expand All @@ -29,7 +28,7 @@ func (cs *ClientState) VerifyClientMessage(
}
}

func (cs ClientState) verifyHeader(ctx context.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec,
func (cs ClientState) verifyHeader(_ context.Context, clientStore storetypes.KVStore, cdc codec.BinaryCodec,
header *Header) error {
// sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917

Expand Down
Loading

0 comments on commit 33b6ca9

Please sign in to comment.