Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into chains/mainnet-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCherepovskyi committed Aug 30, 2024
2 parents fe49868 + fc185b3 commit 6bf9d16
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
1 change: 1 addition & 0 deletions x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ title: List of Modules
* [x/evm and x/feemarket](./evm/README.md) - EVM compatibility feature.
* [x/identity](./identity/README.md) - Storing aggregated identity data.
* [x/cscalist](./cscalist/README.md) - Storing and managing CSCA Master List
* [x/rootupdater](./rootupdater/README.md) - Storing and managing passport root

## EVM

Expand Down
56 changes: 56 additions & 0 deletions x/rootupdater/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
layout: default
title: x/rootupdater
---

# `x/rootupdater`

## Abstract

This module is designed to extract the passport root from Ethereum Virtual Machine (EVM) contract events and
subsequently create a new operation for `rarimo-core` module .

----

## Concepts

The core functionality of this module involves monitoring and processing events emitted by EVM contracts
to capture the passport root. Once the passport root is accurately extracted, the module proceeds to create
a new operation within the rarimo-core module.

An operation includes the following fields, such as `contract_address`, `root`, `root_timestamp`, `block_height`

## State

Model can be found in `proto/rootupdater`. Module data are stored inside Params

#### Module params proto

```protobuf
message Params {
string contract_address = 1;
string root = 2;
string last_signed_root = 3;
string last_signed_root_index = 4;
string event_name = 5;
int64 root_timestamp = 6;
uint64 block_height = 7;
}
```

Example values are provided in JSON for convenient reading.

#### Module params
```json
{
"params": {
"contract_address": "0x65D51e50453371392b4c1280BE9B75Cbe52F950e",
"root": "0x000000",
"last_signed_root": "0x000000",
"last_signed_root_index": "0x1c710a1e732c4178b110e01096f26c83c81a5a9118d8219ef8d204954ca09dd9",
"event_name": "RootUpdated",
"root_timestamp": "1724316208",
"block_height": "0"
}
}
```
3 changes: 3 additions & 0 deletions x/rootupdater/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ func (k Keeper) EndBlocker(ctx sdk.Context) {
params := k.GetParams(ctx)

if params.Root == params.LastSignedRoot && params.Root != "" {
k.Logger(ctx).Info("root is not updated. Skipping end block")
return
}

k.Logger(ctx).Info("root is updated. Operation creating")

// Creating operation to be signed by TSS parties
index, err := k.rarimo.CreateRootUpdateOperation(ctx, types.ModuleName, &rarimocoremoduletypes.PassportRootUpdate{
ContractAddress: params.ContractAddress,
Expand Down
17 changes: 14 additions & 3 deletions x/rootupdater/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,50 @@ func NewKeeper(
func (k Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *ethtypes.Receipt) error {
params := k.GetParams(ctx)

k.Logger(ctx).Error("PostTxProcessing", "msg", msg, "receipt", receipt)

stateV2, err := abi.JSON(strings.NewReader(state.PoseidonSMTABI))
if err != nil {
k.Logger(ctx).Error("failed to marshal poseidon smart abi", "error", err)
return err
}

contractAddress, err := hexutil.Decode(params.ContractAddress)
if err != nil {
// If return an error here, the whole EVM module won't work
k.Logger(ctx).Debug("failed to decode contract address")
k.Logger(ctx).Info("failed to decode contract address")
return nil
}

// Validating message receiver address (should be our state smart contract)
if msg.To() == nil || bytes.Compare(msg.To().Bytes(), contractAddress) != 0 {
k.Logger(ctx).Info("inappropriate contract address")
return nil
}

// https://docs.evmos.org/protocol/modules/evm#posttxprocessing

if len(receipt.Logs) == 0 {
k.Logger(ctx).Error("logs is empty")
}

for _, log := range receipt.Logs {
eventId := log.Topics[0]

event, err := stateV2.EventByID(eventId)
if err != nil {
k.Logger(ctx).Error("failed to get event by ID")
continue
}

if event.Name != params.EventName {
k.Logger(ctx).Info("unmatched event: got %s, expected %s", event.Name, params.EventName)
continue
}

eventBody := state.PoseidonSMTRootUpdated{}
if err := utils.UnpackLog(stateV2, &eventBody, event.Name, log); err != nil {
return err
k.Logger(ctx).Error("failed to unpack event body")
continue
}

params.Root = hexutil.Encode(eventBody.Root[:])
Expand Down

0 comments on commit 6bf9d16

Please sign in to comment.