Skip to content

Commit

Permalink
chore: add verify-script for checking validator migration proofs (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreithecker authored Jan 8, 2025
1 parent 0f60c1e commit 5941397
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: run all jobs
on: push

jobs:
verify-migration-proofs:
uses: ./.github/workflows/migration.yml

lint:
uses: ./.github/workflows/lint.yml

Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/migration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: migration
on:
workflow_call:

jobs:
test:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Check out repository code
uses: actions/checkout@v4
# Setup Python
- name: Install dependencies
run: pip3 install bech32 requests
- name: Verify migration proofs
working-directory: ./app/upgrades/v2_0/validator-proofs
run: python3 verify.py
8 changes: 5 additions & 3 deletions app/upgrades/v2_0/validator-proofs/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ all stake is returned to the original delegators during the migration.

### Steps

1. Enter the `mainnet`-directory and copy the `example-validator.json` config file and name it after your validator.
1. Enter the `mainnet`-directory and copy an existing config file and name it after your validator.

2. Fill out the `name`, `protocol_address` and `consensus_address`

3. Send 1 $KYVE from the protocol-address to the consensus-validator-operator address using the memo "Shared-Staking"
and put the tx-hash in proof_1.

4. Send 1 $KYVE from the consensus-validator-operator address to the protocol address using the memo "Shared-Staking"
4. Send 1 $KYVE from the consensus-validator-operator address to the protocol-address using the memo "Shared-Staking"
and put the tx-hash in proof_2.

5. Submit a Pull-Request to https://github.com/KYVENetwork/chain

6. (Optional) Perform the same steps for the `kaon` directory with your Kaon validators.
6. (Optional) Perform the same steps for the `kaon` directory with your Kaon validators. (Transactions must be submitted on the Kaon network.)

7. Check if the GitHub action (verify-migration-proofs) is passing. You can also run `python3 verify.py` locally to check if everything is correct.

## General Upgrade Procedure

Expand Down

This file was deleted.

This file was deleted.

69 changes: 69 additions & 0 deletions app/upgrades/v2_0/validator-proofs/verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os
import json
import sys

import requests
import bech32


def verify_tx(api_endpoint, tx_hash, expect_from_address, expect_to_address):
x = requests.get(api_endpoint + "/cosmos/tx/v1beta1/txs/" + tx_hash)
if x.status_code != 200:
raise Exception("transaction does not exist: ", tx_hash)

tx = x.json()
if tx["tx"]["body"]["memo"] != "Shared-Staking":
raise Exception("incorrect memo for transaction: ", tx_hash)

if tx["tx"]["body"]["messages"][0]["from_address"] != expect_from_address:
raise Exception("Incorrect from_address. Expected: {}, got: {}"
.format(expect_from_address, tx["tx"]["body"]["messages"][0]["from_address"]))

if tx["tx"]["body"]["messages"][0]["to_address"] != expect_to_address:
raise Exception("Incorrect to_address. Expected: {}, got: {}"
.format(expect_to_address, tx["tx"]["body"]["messages"][0]["to_address"]))


def verify_proof(api_endpoint, entry):
x = requests.get(api_endpoint + "/cosmos/staking/v1beta1/validators/" + entry["consensus_address"])
if x.status_code != 200:
raise Exception("Consensus validator does not exist: ", entry["consensus_address"])

x = requests.get(api_endpoint + "/kyve/query/v1beta1/staker/" + entry["protocol_address"])
if x.status_code != 200:
raise Exception("Protocol validator does not exist: ", entry["protocol_address"])

prefix, address_bytes = bech32.bech32_decode(entry["consensus_address"])
validator_acc_address = bech32.bech32_encode("kyve", address_bytes)

verify_tx(api_endpoint, entry["proof_1"], entry["protocol_address"], validator_acc_address)
verify_tx(api_endpoint, entry["proof_2"], validator_acc_address, entry["protocol_address"])


def verify_network(name, api_endpoint):
status = {"correct": 0, "error": 0}
for file in os.listdir("./" + name):
try:
proof = json.load(open("./{}/{}".format(name, file)))
verify_proof(api_endpoint, proof)
print("[{}]".format(name.title()), file, "✅")
status["correct"] += 1

except Exception as e:
print("[{}]".format(name.title()), file, "❌")
print(e)
status["error"] += 1

return status


status_kaon = verify_network("kaon", "https://api.kaon.kyve.network")
print("\n[Kaon] Correct: {}, Error: {}".format(status_kaon["correct"], status_kaon["error"]))

print("\n")

status_mainnet = verify_network("mainnet", "https://api.kyve.network")
print("\n[Mainnet] Correct: {}, Error: {}".format(status_mainnet["correct"], status_mainnet["error"]))

if status_kaon["error"] != 0 or status_mainnet["error"] != 0:
sys.exit(1)

0 comments on commit 5941397

Please sign in to comment.