Skip to content

Commit

Permalink
[Hotfix] - Nonce not incrementing & [Feature] - keys transferability (#…
Browse files Browse the repository at this point in the history
…25)


Signed-off-by: Aditya <[email protected]>
Co-authored-by: Aditya <[email protected]>
Co-authored-by: Aditya K <[email protected]>
  • Loading branch information
3 people authored May 17, 2024
1 parent 45ef47f commit 5cf07a9
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 19 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ watchtower-operator is a command-line interface (CLI) tool for interacting with
## Installation
You can get the watchtower-operator cli prebuilt, or build from source

### Pre-requisite

gocryptfs should be installed on the machine you will use the CLI tool on. The installation and running of gocryptfs is easier and smoother on Unbuntu/Debian systems. So, to use the CLI, those would be the ideal systems

1. **Prebuilt**

You can run the following command in your terminal and follow instructions provided by the script to use the cli
Expand Down Expand Up @@ -68,6 +72,7 @@ Default file: config/l1-operator-config.json.template (reference file)
#### for commands - registerWatchtower, deRegisterWatchtower
Default file: config/l2-operator-config.json.template (reference file)
| Field | Description |
|----------|----------|
|watchtower_private_key | Private key of the watchtower |
Expand Down Expand Up @@ -100,7 +105,8 @@ After this command, two directories .encrypted_keys and .decrypted_keys are crea
2. `create` - This command will create a new key. This command will need a flag --key-name(-k). This will be the name of the key which will be referred in the future by the CLI. This name should be mentioned in the config file to extract the corresponding private key. When you run this command, it will ask for password to mount and then ask you to enter the private key
```
$ watchtower-operator keys create wt1
$ watchtower-operator keys create -k wt1


Enter password to mount: **********
Enter private key: ****************************************************************
Expand Down
14 changes: 5 additions & 9 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
## [0.2.0]
## [0.2.1]

This release includes several new features, security improvements, and bug fixes to enhance the overall CLI experience for an operator while registering their operator keys and watchtower keys with Witness Chain Operator Registry Smart Contracts.
This release includes new features, security improvements, and bug fixes to enhance the overall CLI experience for an operator while registering their operator keys and watchtower keys with Witness Chain Operator Registry Smart Contracts.

### Upgrade Steps
* Utilize the same procedure employed during the initial installation to execute the upgrade. Please refer [Readme | Installation](https://github.com/witnesschain-com/operator-cli/blob/main/README.md#installation)


### New Features
* Added support for encryption of private watchtower keys
* Added support for transferability of keys



### Other Changes
* Added support for waiting for Transaction receipts
* Offchain validation if the operator/watchtower are already registered to save gas costs due to on-chain reverts.
* Minor typos fixed
### Bug Fixes
* Fixed bug where the nonce wasn't incrementing



Expand Down
8 changes: 2 additions & 6 deletions common/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ func ListKeyCmd() {
}

func InitGocryptfs(insecure bool) {
initCmd := exec.Command("gocryptfs", "-init", EncryptedDir)
initCmd := exec.Command("gocryptfs", "-init", "-plaintextnames", EncryptedDir)

RunCommandWithPassword(initCmd, "init", insecure)
}

Expand Down Expand Up @@ -188,11 +189,6 @@ func CreateKeyFileAndStoreKey(keyFile string, privateKey string) {
func ValidEncryptedDir() bool {
_, err := os.Stat(GoCryptFSConfig)

if os.IsNotExist(err) {
return false
}

_, err = os.Stat(GoCryptFSDiriv)
return !os.IsNotExist(err)
}

Expand Down
10 changes: 7 additions & 3 deletions common/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
)

func PrepareTransactionOptions(client *ethclient.Client, chainId big.Int, gasLimit uint64, privateKey *ecdsa.PrivateKey) *bind.TransactOpts {
func GetLatestNonce(client *ethclient.Client, privateKey *ecdsa.PrivateKey) *big.Int {
senderAddress := GetPublicAddressFromPrivateKey(privateKey)

nonce, err := client.PendingNonceAt(context.Background(), senderAddress)
CheckError(err, "Pending nonce calculation failed")
nonceNew := big.NewInt(int64(nonce))
return nonceNew
}

func PrepareTransactionOptions(client *ethclient.Client, chainId big.Int, gasLimit uint64, privateKey *ecdsa.PrivateKey) *bind.TransactOpts {

gasPrice, err := client.SuggestGasPrice(context.Background())
CheckError(err, "Gas price calculation failed")

auth, err := bind.NewKeyedTransactorWithChainID(privateKey, &chainId)
CheckError(err, "Transactor creation failed")

auth.Nonce = big.NewInt(int64(nonce))

auth.Value = big.NewInt(0) // in wei
auth.GasLimit = gasLimit // in units
auth.GasPrice = gasPrice
Expand Down
1 change: 1 addition & 0 deletions watchtower-operator/commands/deregister_op_from_avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func DeRegisterOperatorFromAVS(config *operator_config.OperatorConfig) {
wc_common.CheckError(err, "Instantiating WitnessHub contract failed")

avsRegtransactOpts := wc_common.PrepareTransactionOptions(client, config.ChainId, config.GasLimit, operatorPrivateKey)
avsRegtransactOpts.Nonce = wc_common.GetLatestNonce(client, operatorPrivateKey)

tx, err := witnessHub.DeregisterOperatorFromAVS(avsRegtransactOpts, operatorAddress)
wc_common.CheckError(err, "Deregistering operator from AVS failed")
Expand Down
1 change: 1 addition & 0 deletions watchtower-operator/commands/deregister_watchtower.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func DeRegisterWatchtower(config *operator_config.OperatorConfig) {
fmt.Printf("Watchtower %s is not registered\n", watchtowerAddress.Hex())
continue
}
deRegTransactOpts.Nonce = wc_common.GetLatestNonce(client, operatorPrivateKey)

deRegTx, err := operatorRegistry.DeRegister(deRegTransactOpts, watchtowerAddress)
wc_common.CheckError(err, "Deregister failed")
Expand Down
1 change: 1 addition & 0 deletions watchtower-operator/commands/register_op_to_avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func RegisterOperatorToAVS(config *operator_config.OperatorConfig) {
operatorSignature := GetOpertorSignature(client, avsDirectory, config.WitnessHubAddress, operatorPrivateKey, operatorAddress, expiry)

avsRegtransactOpts := wc_common.PrepareTransactionOptions(client, config.ChainId, config.GasLimit, operatorPrivateKey)
avsRegtransactOpts.Nonce = wc_common.GetLatestNonce(client, operatorPrivateKey)

tx, err := witnessHub.RegisterOperatorToAVS(avsRegtransactOpts, operatorAddress, operatorSignature)
wc_common.CheckError(err, "Registering operator to AVS failed")
Expand Down
1 change: 1 addition & 0 deletions watchtower-operator/commands/register_watchtower.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func RegisterWatchtower(config *operator_config.OperatorConfig) {
}

signedMessage := SignOperatorAddress(client, watchtowerPrivateKey, operatorAddress, *expiry)
regTransactOpts.Nonce = wc_common.GetLatestNonce(client, operatorPrivateKey)

regTx, err := operatorRegistry.RegisterWatchtowerAsOperator(regTransactOpts, watchtowerAddress, expiry, signedMessage)
wc_common.CheckError(err, "Registering watchtower as operator failed")
Expand Down

0 comments on commit 5cf07a9

Please sign in to comment.