Skip to content

Instantly share code, notes, and snippets.

@sophoah
Last active March 6, 2020 16:22
Show Gist options
  • Save sophoah/e1a6baf00feb11cac67b39cf7bc490b1 to your computer and use it in GitHub Desktop.
Save sophoah/e1a6baf00feb11cac67b39cf7bc490b1 to your computer and use it in GitHub Desktop.
OSTN double-signing test procedure

OSTN Double-Signing Procedure

Installation

Prerequisites: If you don't have curl or jq installed - install them first (e.g. sudo apt-get install curl jq on Linux)

Download the custom static double-signing binary, node.sh and hmy:

bash <(curl -sSL https://raw.githubusercontent.com/SebastianJ/harmony-tools/master/install/install.sh) --node --enable-double-signing

Account Setup

Create a new validator account and a new delegator account:

./hmy keys add DSValidator
./hmy keys add DSDelegator

Set the following variables with the corresponding address:

validator=$(./hmy keys list | grep DSValidator | awk '/one/{print $2}')
delegator=$(./hmy keys list | grep DSDelegator | awk '/one/{print $2}')

Set the remaining variables:

fundingAddress=ONE_OF_YOUR_ADDRESSES_WITH_FUNDS

Fund these accounts:

./hmy transfer --from $fundingAddress --from-shard 0 --to $validatorAddress --to-shard 0 --amount 1.1 --chain-id testnet --timeout 60 --node https://api.s0.os.hmny.io

./hmy transfer --from $fundingAddress --from-shard 0 --to $delegatorAddress --to-shard 0 --amount 100.1 --chain-id testnet --timeout 60 --node https://api.s0.os.hmny.io

or use the faucet

curl -X GET https://faucet.os.hmny.io/fund?address=$validatorAddress
curl -X GET https://faucet.os.hmny.io/fund?address=$delegatorAddress

Both your validator accounts (DSValidator and DSDelegator) should now be funded and you can proceed with setting up the node.

A note on funding, delegations and median stake

Please note that you might have to adjust funding and delegations to correctly make it into the committee!

You can check the current median stake using:

./hmy blockchain median-stake --node https://api.s0.os.hmny.io | jq '.result | tonumber'

And then convert the Wei returned from that command using e.g: ETH-converter.com to see the current median stake on the network.

Node Setup

Generate a new BLS key:

blsKey=$(./hmy keys generate-bls-key | jq '.["public-key"]' | tr -d '"')

Configure webhooks.yml

Go to https://webhook.site/ and let it generate a backend url (copy the address below "Your randomly generated URL"), then set the two variables noticeEndpoint and doubleSignEndpoint to the URL/URL:s, e.g:

noticeEndpoint=https://webhook.site/ed18af8d-9dd5-42dc-a630-1d1ca1d68a30
doubleSignEndpoint=https://webhook.site/ed18af8d-9dd5-42dc-a630-1d1ca1d68a30

(You can use two separate endpoints to separate the notices from the actual double sign messages - but for simplicity's sake you can just point the hooks to the same endpoint)

Download the webhooks template and update it with your specific details:

curl -LO https://gist.githubusercontent.com/SebastianJ/e1bc2057faa99870452e60bd56abb576/raw/345fbc0aadf936da76e20fe4714f0225e989e22b/webhooks.yml
sed -i "s#ENTER_YOUR_BLS_KEY_HERE_WITHOUT_DOT_KEY#${blsKey}#g" webhooks.yml
sed -i "s#ENTER_DOUBLE_SIGN_NOTICE_ENDPOINT_HERE#${noticeEndpoint}#g" webhooks.yml
sed -i "s#ENTER_THIS_NODE_DOUBLE_SIGNED_ENDPOINT_HERE#${doubleSignEndpoint}#g" webhooks.yml

Make sure that your webhooks.yml file has the correct information:

$ cat webhooks.yml
---
malicious:
  trigger:
    double-sign: "http://localhost:7777/trigger-next-double-sign"
    list:
      - YOUR_BLS_KEY_SHOULD_BE_HERE
web-hooks:
  notice-double-sign: "THE_URL_YOU_ENTERED"
  this-node-double-signed: "THE_URL_YOU_ENTERED"

If sed somehow didn't work / didn't replace the values - please edit the file and switch out the placeholders with your own values.

Start the node

(If you want to run the node using tmux - now's the time when you launch the tmux session)

Start the node with the associated webhooks.yml file:

./node.sh -k YOUR_BLS_KEY.key -N staking -z -D -S -W webhooks.yml

(Exit the tmux session here if you use tmux: CTRL+B then press d)

Create your validator

If you've only performed the node startup part in tmux, both $validatorAddress and $blsKey should be available to be used in the create-validator command.

Otherwise, replace $validatorAddress and $blsKey below with your own details.

Create your validator (replace settings etc):

./hmy staking create-validator --validator-addr $validatorAddress --name "Bubzonian Institute of Staking (BIOS)" --identity bubz --website bubzonianinstituteofstaking.com --security-contact Bubz --details "Bubzonian Institute of Staking (BIOS)" --rate 0.01 --max-rate 0.25 --max-change-rate 0.05 --min-self-delegation 1 --max-total-delegation 99999999 --bls-pubkeys $blsKey --amount 1 --chain-id testnet --timeout 180 --node https://api.s0.os.hmny.io

Check that status == "0x1" and verify that your validator exists:

./hmy blockchain validator information $validatorAddress --node https://api.s0.os.hmny.io

You'll should also see - "banned": false (i.e. the validator hasn't been banned/slashed/penalized yet)

Delegate to your newly created validator

./hmy staking delegate --delegator-addr $delegatorAddress --validator-addr $validatorAddress --amount 100 --chain-id testnet --timeout 60 --node https://api.s0.os.hmny.io

You should now have two separate delegations to your validator:

./hmy blockchain validator information $validatorAddress --node https://api.s0.os.hmny.io | jq '.result.delegations | length'

(You should see "2" getting printed out if everything works as expected)

Wait for the validator to join the committee

Wait until your validator has been elected (now's the perfect time to go and get some more coffe or tea 🙃):

while true; do ./hmy utility committees --node https://api.s0.os.hmny.io | grep $validatorAddress >/dev/null 2>&1 && echo "Elected!" || echo "Not elected!"; sleep 30; done

When this command has switched from "Not Elected!" to "Elected!" then you can proceed with the rest of the instructions (use CTRL+C to stop the command).

Trigger double-signing

Ok, we're now ready for the real fun!

Just check the validator ban status one more time before starting:

./hmy blockchain validator information $validatorAddress --node https://api.s0.os.hmny.io | jq '.result.banned'

The response from this command should be "false"

Start double-signing (this will trigger double-signing events for around a minute):

for i in {1..60}; do curl http://localhost:7777/trigger-next-double-sign; sleep 1; done

You should see output similar to: {"result":"success","payload":"enabled double signing on [Duty:validator Pub:75e9680889fe332116daf48531e557a66d00a63fd5cd3194d367bdad3d3d6e33d14861c27775eebe63d525e923b7c683 Header: Num:3034 View:3034 Shard:3 Epoch:40 DoubleSign:true]"}

Shortly thereafter your validator should be banned:

./hmy blockchain validator information $validatorAddress --node https://api.s0.os.hmny.io | jq '.result.banned'

You should see "true" which means that your validator has been banned/slashed/penalized.

Wait a little bit and then finally also verify that your validator is no longer marked as "ELECTED" on the open staking explorer: https://staking.harmony.one/validators/YOUR_VALIDATOR_ADDRESS (the OSTN explorer is quite slow to reflect the status change - it seems it picks up the reduced stake amount faster, so you can also look for that)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment