Skip to content
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

feat: Audit tooling | NPG-6520 #490

Merged
merged 61 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
75cb251
feat(barebones scaffold): audit tooling
cong-or Jun 25, 2023
59f4ab4
feat(fragment analysis): audit tooling
cong-or Jun 25, 2023
c935d9e
feat(fragment analysis): audit tooling
cong-or Jun 27, 2023
e1cc676
feat(fragment analysis): audit tooling
cong-or Jun 27, 2023
6397b75
feat(read official catalyst results ): parse active vote plans json
cong-or Jun 28, 2023
f54b963
feat(read official catalyst results ): parse active vote plans json
cong-or Jun 28, 2023
5549df4
docs(improve readme): improve readability
cong-or Jun 28, 2023
010ef0a
docs(improve readme): improve readability
cong-or Jun 28, 2023
af8da3f
docs(improve readme): improve readability
cong-or Jun 28, 2023
dde2710
docs(improve readme): improve readability
cong-or Jun 28, 2023
e33dad8
docs(improve readme): improve readability
cong-or Jun 29, 2023
9d24e36
docs(improve readme): improve readability
cong-or Jun 29, 2023
078fae0
refactor(working offline tally): audit tooling
cong-or Jul 1, 2023
5505f1e
feat(encrypted + decrypted tallies generation): audit tooling
cong-or Jul 2, 2023
afaeae0
refactor(working offline tally): audit tooling
cong-or Jul 2, 2023
607c0a7
refactor(working offline tally): audit tooling
cong-or Jul 2, 2023
b32e0d6
refactor(working offline tally): audit tooling
cong-or Jul 2, 2023
c9ced6c
refactor(working offline tally): audit tooling
cong-or Jul 2, 2023
223927a
feat(write decrypt shares and results): audit tooling
cong-or Jul 2, 2023
b6c65a3
feat(write decrypt shares and results): audit tooling
cong-or Jul 2, 2023
dbf8aba
feat(write decrypt shares and results): audit tooling
cong-or Jul 2, 2023
7109745
feat(write decrypt shares and results): audit tooling
cong-or Jul 2, 2023
4749fb2
feat(write decrypt shares and results): audit tooling
cong-or Jul 2, 2023
ee879ba
feat(write decrypt shares and results): audit tooling
cong-or Jul 2, 2023
dde5a9d
feat(write decrypt shares and results): audit tooling
cong-or Jul 2, 2023
ddc6dcf
feat(write decrypt shares and results): audit tooling
cong-or Jul 2, 2023
3a5f36c
feat(conditional ignore voting time checks for audit): audit tooling
cong-or Jul 4, 2023
f7f77a6
refactor(remove redundant spending counter logic): audit tooling
cong-or Jul 9, 2023
b65a056
refactor(housekeeping): audit tooling
cong-or Jul 9, 2023
2d8592a
feat(find my vote): audit tooling
cong-or Jul 22, 2023
867af9f
docs(improve docs): audit tooling
cong-or Jul 25, 2023
eedd943
Update README.md
cong-or Jul 25, 2023
e4be8ae
Update README.md
cong-or Jul 25, 2023
08d6f0e
feat(find my vote): audit tooling
cong-or Jul 25, 2023
5e60475
feat(find my vote): audit tooling
cong-or Jul 25, 2023
a8f29b9
refactor(find my vote): write vote history of voter given voting key
cong-or Jul 26, 2023
6e28e00
docs(user steps for audit): audit tooling
cong-or Jul 27, 2023
2a54700
Update README.md
cong-or Jul 27, 2023
de565c4
Update README.md
cong-or Jul 27, 2023
8c237c9
Merge branch 'main' into audit-tooling
cong-or Jul 27, 2023
c6cafb8
Update README.md
cong-or Jul 27, 2023
b667377
Update README.md
cong-or Jul 27, 2023
eb6d4b5
fix(conditional compilation): audit flag
cong-or Jul 27, 2023
ba6ef47
fix(conditional compilation): audit flag
cong-or Jul 27, 2023
6a17c87
fix(conditional compilation): audit flag
cong-or Jul 27, 2023
d1dc365
fix(conditional compilation): audit flag
cong-or Jul 27, 2023
5c5256b
docs(clearer description): audit tooling
cong-or Jul 28, 2023
1d7c3ea
fix(conditional tests): audit flag
cong-or Jul 28, 2023
d0e5483
Merge branch 'main' into audit-tooling
cong-or Jul 28, 2023
43df7ac
fix(conditional tests): audit flag
cong-or Jul 28, 2023
4a5a6fd
fix(conditional tests): audit flag only run in-vote-time tests when a…
cong-or Jul 28, 2023
e107ec3
Merge branch 'main' into audit-tooling
cong-or Jul 28, 2023
bdf7974
fix(conditional compilation): audit flag
cong-or Jul 28, 2023
2b9343f
fix(conditional tests): audit flag
cong-or Jul 28, 2023
383b2b2
fix(conditional tests): audit flag
cong-or Jul 28, 2023
d3b0966
fix(conditional tests): audit flag
cong-or Jul 29, 2023
26a26d8
fix(conditional tests): audit flag
cong-or Jul 29, 2023
a1def4f
fix(conditional tests): audit flag
cong-or Jul 29, 2023
cc4ac6f
Merge branch 'main' into audit-tooling
stevenj Aug 1, 2023
c70c439
Merge branch 'main' into audit-tooling
stevenj Aug 2, 2023
84fc96a
Merge branch 'main' into audit-tooling
minikin Aug 2, 2023
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
59 changes: 38 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ members = [
"src/vit-testing/scheduler-service-lib",
"src/voting-tools-rs",
"src/cat-data-service",
"src/tally",
"src/audit",
]

[workspace.dependencies]
Expand Down
60 changes: 60 additions & 0 deletions src/audit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[package]
name = "audit"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chain-crypto = { path = "../chain-libs/chain-crypto" }
chain-vote = { path = "../chain-libs/chain-vote" }
jormungandr-lib = { path = "../jormungandr/jormungandr-lib" }
chain-addr = { path = "../chain-libs/chain-addr" }
chain-core = { path = "../chain-libs/chain-core" }
chain-impl-mockchain = { path = "../chain-libs/chain-impl-mockchain" ,features= ["audit"]}
chain-ser = { path = "../chain-libs/chain-ser" }
chain-storage = { path = "../chain-libs/chain-storage" }
chain-time = { path = "../chain-libs/chain-time" }
wallet = { path = "../chain-wallet-libs/wallet" }

rand_core = "0.6"

base64 = "0.21.0"
bech32 = "0.8"

clap = { version = "4", features = ["derive", "cargo"] }
clap_complete_command = { version = "0.5" }

color-eyre = "0.6"
thiserror = "1.0.40"
csv = "1.1"
hex = "0.4"
serde = "1.0"
serde_json = "1.0"
serde_yaml = "0.8.17"
tracing.workspace = true
tracing-subscriber.workspace = true
rand = "0.8.3"


[dev-dependencies]
rand_chacha = "0.3"
smoke = "^0.2.1"
criterion = "0.3"
chain-crypto = { path = "../chain-libs/chain-crypto", features=["property-test-api"]}

[lib]
name = "lib"
path = "src/lib/mod.rs"

[[bin]]
name = "tally"
path = "src/tally/bin/main.rs"

[[bin]]
name = "offline"
path = "src/offline/bin/main.rs"

[[bin]]
name = "find"
path = "src/find/bin/main.rs"
42 changes: 42 additions & 0 deletions src/audit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Audit Tooling:

## Offline audit

### Download Fund State
Download historical fund state from [*here*](https://github.com/input-output-hk/catalyst-core) in order to replay and audit the voting event.

The official published results can be found in this file in the form of **activevoteplans.json**.

**activevoteplans.json** = FINAL RESULTS.

If you would like to re-generate **activevoteplans.json** yourself, via a live node and historical fragments - [*see here for instructions*](./balance/README.md)

If not, you can begin the audit with the following steps.

*Example usage:*

```
cargo build --release -p audit
```

*Cross reference offline tallies with published catalyst tallies.*

```bash

OFFICIAL_RESULTS=/tmp/activevoteplans.json
BLOCK0=/tmp/fund9-leader-1/artifacts/block0.bin
FRAGMENTS_STORAGE=/tmp/fund9-leader-1/persist/leader-1

./target/release/offline --fragments $FRAGMENTS_STORAGE --block0 $BLOCK0 --official-results $OFFICIAL_RESULTS

```

This will create three files:
- *ledger_after_tally.json* **(decrypted ledger state after tally)** *should match official results!*
- *ledger_before_tally.json* **(encrypted ledger state before tally)**
- *decryption_shares.json* **(decryption shares for each proposal)**

[*See here for next steps of audit process*](src/tally/README.md)

### Find my vote
[*See here for instructions on how to find your voting history*](src/find/README.md)
26 changes: 26 additions & 0 deletions src/audit/balance/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
VERSION 0.7
build:
FROM ../../../+builder
RUN pwd
RUN cargo build --locked --release --bin jormungandr

# Store the artifact
SAVE ARTIFACT target/release/jormungandr jormungandr
SAVE IMAGE --cache-hint

docker:
FROM ../../../+deployment
WORKDIR /app
ARG tag="latest"
ARG registry

COPY +build/jormungandr .
COPY entry.sh .

COPY node_config.yaml .
RUN chmod +x entry.sh
RUN pwd
ENV NODE_CONFIG_PATH=/app/node_config.yaml
ENV BIN_PATH=/app/jormungandr
ENTRYPOINT ["/app/entry.sh"]
SAVE IMAGE --push ${registry}jormungandr:$tag
40 changes: 40 additions & 0 deletions src/audit/balance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
### Reproduce published results
### Start and load live node with historical state

Pre-requisites
- Install [Earthly CLI](https://earthly.dev/get-earthly)
- Docker or Podman
- Git

```bash
cd balance

# Mount local path as a volume in the container
MOUNT_PATH=/tmp/fund9-leader-1:/leader1stuff

HISTORICAL_STATE=/leader1stuff/persist/leader-1
BLOCK_0=/leader1stuff/artifacts/block0.bin

earthly +build && earthly +docker
docker run --net=host -v $MOUNT_PATH --env STORAGE_PATH=$HISTORICAL_STATE --env GENESIS_PATH=$BLOCK_0 jormungandr
```

### Spin up node to retrieve vote results

Takes several minutes to replay state and stabilize before it is possible to retrieve vote results ⌛

Try after ~5 mins, if it has not replayed and stabilized.
The following error will be shown - `Internal server error: Blockchain tip not set in REST/RPC context`.


```bash
curl http://127.0.0.1:10000/api/v0/vote/active/plans > activevoteplans.json
```

**activevoteplans.json** = FINAL RESULTS.

##### Make sure the jormungandr container has been stopped once you have successfully retrieved the results.
```bash
sudo docker docker stop $JORMUNGANDR_CONTAINER_ID
```
73 changes: 73 additions & 0 deletions src/audit/balance/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

# Enable strict mode
set +x
set -o errexit
set -o pipefail
set -o nounset
set -o functrace
set -o errtrace
set -o monitor
set -o posix
shopt -s dotglob

echo ">>> Entering entrypoint script..."
# Verify the storage path exists
if [[ ! -d "$STORAGE_PATH" ]]; then
echo "ERROR: storage path does not exist at: $STORAGE_PATH";
echo ">>> Aborting..."
exit 1
fi
# Verify config is present
if [[ ! -f "$NODE_CONFIG_PATH" ]]; then
echo "ERROR: node configuration is absent at: $NODE_CONFIG_PATH"
echo ">>> Aborting..."TH"
exit 1
fi
# Verify genesis block is present
if [[ ! -f "$GENESIS_PATH" ]]; then
echo "ERROR: genesis block is absent at: $GENESIS_PA
echo ">>> Aborting..."
exit 1
fi
# Allow overriding jormungandr binary
if [[ ! -f "$BIN_PATH" ]]; then
echo "ERROR: path to jormungandr binary is absent at: $BIN_PATH"
echo ">>> Aborting..."
exit 1
fi
echo ">>> Using the following parameters:"
echo "Storage path: $STORAGE_PATH"
echo "Node config: $NODE_CONFIG_PATH"
echo "Genesis block: $GENESIS_PATH"
echo "Binary path: $BIN_PATH"
args=()
args+=("--storage" "$STORAGE_PATH")
args+=("--config" "$NODE_CONFIG_PATH")
args+=("--genesis-block" "$GENESIS_PATH")

# Define the command to be executed
ARGS="${args[*]}"
EXTRA_ARGS=$*
CMD="$BIN_PATH $ARGS $EXTRA_ARGS"
echo ">>> Executing command: $CMD"

# Wait for DEBUG_SLEEP seconds if the DEBUG_SLEEP environment variable is set
if [ -n "${DEBUG_SLEEP:-}" ]; then
echo "DEBUG_SLEEP is set to $DEBUG_SLEEP. Sleeping..."
sleep "$DEBUG_SLEEP"
fi

echo "Starting node..."
# Expand the command with arguments and capture the exit code
set +e
eval "$CMD"
EXIT_CODE=$?
set -e

# If the exit code is 0, the executable returned successfully
if [ $EXIT_CODE -ne 0 ]; then
echo "Error: jormungandr returned with exit code $EXIT_CODE"
exit 1
fi

29 changes: 29 additions & 0 deletions src/audit/balance/node_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
rest:
listen: "127.0.0.1:10000"
jrpc:
listen: "127.0.0.1:10002"
p2p:
bootstrap:
trusted_peers: []
connection:
public_address: /ip4/127.0.0.1/tcp/10001
allow_private_addresses: true
whitelist: ~
policy:
quarantine_duration: 1s
layers:
topics_of_interest:
messages: high
blocks: high
log:
format: json
level: TRACE
output: stdout
mempool:
pool_max_entries: 10000
log_max_entries: 100000
persistent_log: ~
bootstrap_from_trusted_peers: false
skip_bootstrap: true

22 changes: 22 additions & 0 deletions src/audit/src/find/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Find my vote

Retrieve voting key history and metadata via offline fragment analysis replay.

*Example usage:*

```
cargo build --release -p audit
```

Voting key is present in the first field as per defined in [CIP-36](https://cips.cardano.org/cips/cip36/); user is given a link to cardanoscan after they vote, their voting key is present in the [metadata, e.g](https://cardanoscan.io/transaction/9f3706e8b26bc0c88ef74e0b020bf148dc90301e3a1e3c465db1f4d206729b7b?tab=metadata)


```bash

VOTING_KEY='e5b0a5c250f78b574b8b17283bcc6c7692f72fc58090f4a0a2362497d28d1a85'
FRAGMENTS_STORAGE=/tmp/fund9-leader-1/persist/leader-1

./target/release/find --fragments $FRAGMENTS_STORAGE --voting-key $VOTING_KEY

```

Loading
Loading