Skip to content

Add Scribe's extended proof of possession #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ export INITIAL_AUTHED=
# Management Configurations
export VALIDATOR_REGISTRY=
## IValidatorRegistry::lift single
export VALIDATOR=
export VALIDATOR_PUBLIC_KEY_X=
export VALIDATOR_PUBLIC_KEY_Y=
export VALIDATOR_SIG_V=
export VALIDATOR_SIG_R=
export VALIDATOR_SIG_S=
## IValidatorRegistry::lift multiple
export VALIDATORS="[]"
export VALIDATOR_PUBLIC_KEY_XS="[]"
export VALIDATOR_PUBLIC_KEY_YS="[]"
export VALIDATOR_SIG_VS="[]"
export VALIDATOR_SIG_RS="[]"
export VALIDATOR_SIG_SS="[]"
## IValidatorRegistry::drop single
export VALIDATOR_ID=
## IValidatorRegistry::drop multiple
Expand Down
21 changes: 0 additions & 21 deletions .gas-snapshot

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "CI"

on:
push:
branches:
- "main"
pull_request:

jobs:
lint:
runs-on: "ubuntu-latest"
steps:
- name: "Check out repo"
uses: "actions/checkout@v3"
with:
submodules: "recursive"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"
with:
version: "nightly"

- name: "Check formatting"
run: "forge fmt --check"

test:
runs-on: "ubuntu-latest"
steps:
- name: "Check out repo"
uses: "actions/checkout@v3"
with:
submodules: "recursive"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"
with:
version: "nightly"

- name: "Run Forge build"
run: "forge build"
id: "build"

- name: "Run Forge test"
run: "FOUNDRY_PROFILE=ci forge test -vvv"
id: "test"
24 changes: 0 additions & 24 deletions .github/workflows/gas.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/lint.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/non-via-ir-compilation.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/solc-version-tests.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .github/workflows/unit-tests.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
path = lib/chronicle-std
url = https://github.com/chronicleprotocol/chronicle-std
branch = v2
[submodule "lib/scribe"]
path = lib/scribe
url = https://github.com/chronicleprotocol/scribe
branch = v2
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ValidatorRegistry • [![Unit Tests](https://github.com/chronicleprotocol/validator-registry/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/chronicleprotocol/validator-registry/actions/workflows/unit-tests.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
# ValidatorRegistry • [![CI](https://github.com/chronicleprotocol/validator-registry/actions/workflows/ci.yml/badge.svg)](https://github.com/chronicleprotocol/validator-registry/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

This contract provides an onchain registry for _Chronicle Protocol_ validators via 1-byte validators ids.

Expand Down Expand Up @@ -42,12 +42,7 @@ Lint:
$ forge fmt [--check]
```

Update gas snapshots:

```bash
$ forge snapshot --nmt "Fuzz" [--check]
```

## Dependencies

- [chronicleprotocol/chronicle-std@v2](https://github.com/chronicleprotocol/chronicle-std/tree/v2)
- [chronicleprotocol/scribe@v2](https://github.com/chronicleprotocol/scribe/tree/v2)
20 changes: 16 additions & 4 deletions docs/Management.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ $ env | grep -e "RPC_URL" -e "KEYSTORE" -e "KEYSTORE_PASSWORD" -e "VALIDATOR_REG

Set the following environment variables:

- `VALIDATOR`: The validator's address
- `VALIDATOR_PUBLIC_KEY_X`: The validator's public key's x coordinate
- `VALIDATOR_PUBLIC_KEY_Y`: The validator's public key's y coordinate
- `VALIDATOR_SIG_V`: The validator's registration signature's v value
- `VALIDATOR_SIG_R`: The validator's registration signature's r value
- `VALIDATOR_SIG_S`: The validator's registration signature's s value

Run:

Expand All @@ -49,7 +53,7 @@ $ forge script \
--password "$KEYSTORE_PASSWORD" \
--broadcast \
--rpc-url $RPC_URL \
--sig $(cast calldata "lift(address,address)" "$VALIDATOR_REGISTRY" "$VALIDATOR")\
--sig $(cast calldata "lift(address,uint,uint,uint8,bytes32,bytes32)" "$VALIDATOR_REGISTRY" "$VALIDATOR_PUBLIC_KEY_X" "$VALIDATOR_PUBLIC_KEY_Y" "$VALIDATOR_SIG_V" "$VALIDATOR_SIG_R" "$VALIDATOR_SIG_S")\
-vvv \
script/ValidatorRegistry.s.sol:ValidatorRegistryScript
```
Expand All @@ -58,7 +62,15 @@ $ forge script \

Set the following environment variables:

- `VALIDATORS`: The validators' addresses
- `VALIDATOR_PUBLIC_KEY_XS`: The validators' public key's x coordinate
- Note to use the following format: `"[<elem>,<elem>]"`
- `VALIDATOR_PUBLIC_KEY_YS`: The validators' public key's y coordinate
- Note to use the following format: `"[<elem>,<elem>]"`
- `VALIDATOR_SIG_VS`: The validators' registration signature's v value
- Note to use the following format: `"[<elem>,<elem>]"`
- `VALIDATOR_SIG_RS`: The validators' registration signature's r value
- Note to use the following format: `"[<elem>,<elem>]"`
- `VALIDATOR_SIG_SS`: The validators' registration signature's s value
- Note to use the following format: `"[<elem>,<elem>]"`

Run:
Expand All @@ -69,7 +81,7 @@ $ forge script \
--password "$KEYSTORE_PASSWORD" \
--broadcast \
--rpc-url $RPC_URL \
--sig $(cast calldata "lift(address,address[])" "$VALIDATOR_REGISTRY" "$VALIDATORS")\
--sig $(cast calldata "lift(address,uint[],uint[],uint8[],bytes32[],bytes32[])" "$VALIDATOR_REGISTRY" "$VALIDATOR_PUBLIC_KEY_XS" "$VALIDATOR_PUBLIC_KEY_YS" "$VALIDATOR_SIG_VS" "$VALIDATOR_SIG_RS" "$VALIDATOR_SIG_SS")\
-vvv \
script/ValidatorRegistry.s.sol:ValidatorRegistryScript
```
Expand Down
1 change: 1 addition & 0 deletions lib/scribe
Submodule scribe added at 41f25a
2 changes: 2 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ forge-std/=lib/forge-std/src/

chronicle-std/=lib/chronicle-std/src/
@script/chronicle-std/=lib/chronicle-std/script/

scribe/=lib/scribe/src/
55 changes: 49 additions & 6 deletions script/ValidatorRegistry.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {console2 as console} from "forge-std/console2.sol";

import {IAuth} from "chronicle-std/auth/IAuth.sol";

import {IScribe} from "scribe/IScribe.sol";
import {LibSecp256k1} from "scribe/libs/LibSecp256k1.sol";

import {IValidatorRegistry} from "src/IValidatorRegistry.sol";
import {ValidatorRegistry_COUNTER as ValidatorRegistry} from
"src/ValidatorRegistry.sol";
Expand All @@ -15,6 +18,8 @@ import {ValidatorRegistry_COUNTER as ValidatorRegistry} from
* @notice ValidatorRegistry Management Script
*/
contract ValidatorRegistryScript is Script {
using LibSecp256k1 for LibSecp256k1.Point;

/// @dev Deploys a new ValidatorRegistry instance with `initialAuthed` being the
/// address initially auth'ed.
function deploy(address initialAuthed) public {
Expand All @@ -28,23 +33,61 @@ contract ValidatorRegistryScript is Script {
// -- IValidatorRegistry Functions --

/// @dev Lifts validator `validator`.
function lift(address self, address validator) public {
function lift(
address self,
uint pubKeyCoordinateX,
uint pubKeyCoordinateY,
uint8 sigV,
bytes32 sigR,
bytes32 sigS
) public {
LibSecp256k1.Point memory pubKey =
LibSecp256k1.Point(pubKeyCoordinateX, pubKeyCoordinateY);
IScribe.ECDSAData memory sig = IScribe.ECDSAData(sigV, sigR, sigS);

address validator = pubKey.toAddress();
assert(validator != address(0));

vm.startBroadcast();
IValidatorRegistry(self).lift(validator);
IValidatorRegistry(self).lift(pubKey, sig);
vm.stopBroadcast();

console.log("Lifted", validator);
}

/// @dev Lifts validators `validators`.
function lift(address self, address[] memory validators) public {
function lift(
address self,
uint[] memory pubKeyCoordinateXs,
uint[] memory pubKeyCoordinateYs,
uint8[] memory sigVs,
bytes32[] memory sigRs,
bytes32[] memory sigSs
) public {
uint len = pubKeyCoordinateXs.length;
require(len == pubKeyCoordinateYs.length, "Length mismatch");
require(len == sigVs.length, "Length mismatch");
require(len == sigRs.length, "Length mismatch");
require(len == sigSs.length, "Length mismatch");

LibSecp256k1.Point[] memory pubKeys = new LibSecp256k1.Point[](len);
IScribe.ECDSAData[] memory sigs = new IScribe.ECDSAData[](len);
for (uint i; i < len; i++) {
pubKeys[i] =
LibSecp256k1.Point(pubKeyCoordinateXs[i], pubKeyCoordinateYs[i]);
sigs[i] = IScribe.ECDSAData(sigVs[i], sigRs[i], sigSs[i]);
}

vm.startBroadcast();
IValidatorRegistry(self).lift(validators);
IValidatorRegistry(self).lift(pubKeys, sigs);
vm.stopBroadcast();

console.log("Lifted:");
for (uint i; i < validators.length; i++) {
console.log(" ", validators[i]);
for (uint i; i < pubKeys.length; i++) {
address validator = pubKeys[i].toAddress();
assert(validator != address(0));

console.log(" ", validator);
}
}

Expand Down
Loading
Loading