generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpersist.sh
executable file
·122 lines (84 loc) · 4.09 KB
/
persist.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bash
set -eu # Exit immediately if a command exits with a non-zero status
# Get the directory of the currently executing script
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Source the file from the same directory
source "$THIS_DIR/fns.sh"
heading "Start the EVM node"
launch_evm
until curl -f -s "http://localhost:8545" > /dev/null; do
sleep 1
done
# Set the password for all ciphernodes
set_password cn1 "$CIPHERNODE_SECRET"
set_password cn2 "$CIPHERNODE_SECRET"
set_password cn3 "$CIPHERNODE_SECRET"
set_password cn4 "$CIPHERNODE_SECRET"
set_password ag "$CIPHERNODE_SECRET"
set_private_key ag "$PRIVATE_KEY"
# Launch 4 ciphernodes
launch_ciphernode cn1
launch_ciphernode cn2
launch_ciphernode cn3
launch_ciphernode cn4
launch_aggregator ag
waiton-files "$ROOT_DIR/packages/ciphernode/target/debug/enclave" "$ROOT_DIR/packages/ciphernode/target/debug/fake_encrypt"
heading "Add ciphernode $CIPHERNODE_ADDRESS_1"
yarn ciphernode:add --ciphernode-address $CIPHERNODE_ADDRESS_1 --network localhost
heading "Add ciphernode $CIPHERNODE_ADDRESS_2"
yarn ciphernode:add --ciphernode-address $CIPHERNODE_ADDRESS_2 --network localhost
heading "Add ciphernode $CIPHERNODE_ADDRESS_3"
yarn ciphernode:add --ciphernode-address $CIPHERNODE_ADDRESS_3 --network localhost
heading "Add ciphernode $CIPHERNODE_ADDRESS_4"
yarn ciphernode:add --ciphernode-address $CIPHERNODE_ADDRESS_4 --network localhost
heading "Request Committee"
ENCODED_PARAMS=0x$($SCRIPT_DIR/lib/pack_e3_params.sh --moduli 0x3FFFFFFF000001 --degree 2048 --plaintext-modulus 1032193)
yarn committee:new --network localhost --duration 4 --e3-params "$ENCODED_PARAMS"
waiton "$SCRIPT_DIR/output/pubkey.bin"
PUBLIC_KEY=$(xxd -p -c 10000000 "$SCRIPT_DIR/output/pubkey.bin")
# kill aggregator
kill_proc ag
sleep 2
# relaunch the aggregator
launch_aggregator ag
sleep 2
heading "Mock encrypted plaintext"
$SCRIPT_DIR/lib/fake_encrypt.sh --input "$SCRIPT_DIR/output/pubkey.bin" --output "$SCRIPT_DIR/output/output.bin" --plaintext $PLAINTEXT
heading "Mock activate e3-id"
# NOTE using -s to avoid key spaming the output
yarn -s e3:activate --e3-id 0 --public-key "0x$PUBLIC_KEY" --network localhost
heading "Mock publish input e3-id"
yarn e3:publishInput --network localhost --e3-id 0 --data 0x12345678
sleep 4 # wait for input deadline to pass
waiton "$SCRIPT_DIR/output/output.bin"
heading "Publish ciphertext to EVM"
yarn e3:publishCiphertext --e3-id 0 --network localhost --data-file "$SCRIPT_DIR/output/output.bin" --proof 0x12345678
waiton "$SCRIPT_DIR/output/plaintext.txt"
ACTUAL=$(cat $SCRIPT_DIR/output/plaintext.txt)
# Assume plaintext is shorter
if [[ "$ACTUAL" != "$PLAINTEXT"* ]]; then
echo "Invalid plaintext decrypted: actual='$ACTUAL' expected='$PLAINTEXT'"
echo "Test FAILED"
exit 1
fi
heading "Test PASSED !"
echo -e "\033[32m
██████
██████
██████
██████
██████
██████
██ ██████
████ ██████
██████ ██████
██████████
████████
██████
████
██
\033[0m"
pkill -15 -f "target/debug/enclave" || true
pkill -15 -f "target/debug/aggregator" || true
sleep 4
cleanup 0