Take part
You need Foundry for the contract and a language with integers of arbitrary size for the mathematics. SageMath is a good choice, because it knows about elliptic curves.
1. Get the files
Download challenge.zip, unpack it and run the tests from its folder.
forge test
All 23 tests should pass.
2. Deploy a copy
The contract runs on a local Anvil chain. Start one in a terminal and leave it open.
anvil
In a second terminal, deploy the contract. Anvil prints ten accounts with their private keys when it starts; use the first one here.
forge script script/DeployChallenge.s.sol --broadcast --slow \
--rpc-url http://localhost:8545 \
--private-key <key of account 0>
The script uploads the record in batches of 16 heartbeats and seals it. On a fresh chain the contract gets the address 0x5FbDB2315678afecb367f032d93F642f64180aa3, the one the record was made for.
3. Read the record
The same record is in data/heartbeats.json. Its integers have up to 256 bits. Python reads them exactly; JavaScript's JSON.parse rounds them.
import json
record = json.load(open("data/heartbeats.json"))
for signer in record["slots"]:
key = signer["pubkey"]
first = signer["heartbeats"][0]
print(signer["slot"], hex(key["x"]), first["epoch"], hex(first["r"]))
The index of a signer, from 0 to 6, is called its slot. The fields are described in the specification.
4. Recover four keys
This is the challenge. You can tell at once whether a candidate is right: d is the key of signer i exactly when dG = Qi. No guess has to be submitted to be checked.
5. Build the proof
Follow the protocol in section 4.2 of the specification, with the four signers whose keys you hold as the set S. The result is four polynomial coefficients and seven responses.
The root challenge is the keccak256 hash of these words, in this order, 32 bytes each, reduced modulo N:
| Word | Value |
|---|---|
| Tag | keccak256("MULTISIG_CHALLENGE_CDS") |
| Chain id | 31337 |
| Contract | The address, padded to 32 bytes |
| Caller | The address that will send the transaction, padded to 32 bytes |
| Counter | execNonce(), which is 0 until the first accepted proof |
| Threshold | 4 |
| Signers | 7 |
| Message | keccak256 of the message bytes |
| Keys | keccak256 of x and y of each public key, 32 bytes each |
| Commitments | keccak256 of the seven addresses addr(Ri), each padded to 32 bytes |
Padding is always on the left. test/utils/Secp256k1Prover.sol contains a complete prover to compare with.
6. Submit it
Send the proof from the address it was built for. The message can be any non-empty bytes that no accepted call has used before, as long as they are the ones you hashed; 0x65786563757465 is the word "execute".
cast send 0x5FbDB2315678afecb367f032d93F642f64180aa3 \
"verifyAndExecute((uint256[],uint256[]),bytes)" \
"([a0,a1,a2,a3],[z0,z1,z2,z3,z4,z5,z6])" \
0x65786563757465 \
--private-key <key of your account>
If the transaction succeeds, the contract has accepted the proof. Two calls confirm it.
cast call 0x5FbDB2315678afecb367f032d93F642f64180aa3 "solved()(bool)"
cast call 0x5FbDB2315678afecb367f032d93F642f64180aa3 "firstSolver()(address)"
A rejected proof reverts with InvalidThresholdProof(), which cast may show as custom error 0x431daf91. The other errors are listed in section 2.3.
If the proof is rejected
When the four keys are right, most often one of the words above differs: the caller is not the sender of the transaction, the contract has another address because it was not the first one deployed, or execNonce has moved on.