-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathverify-ucmt.ts
More file actions
48 lines (43 loc) · 1.77 KB
/
verify-ucmt.ts
File metadata and controls
48 lines (43 loc) · 1.77 KB
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
/**
* Minimal script to generate a User Configuration Merkle Tree (UCMT) and verify
* its root and proofs.
*
* By design, the Keystore holds only the Merkle tree root hash onchain while the
* actual configuration is stored offchain. Consequently, all stakeholders of an
* account MUST have access to the UCMT in order to verify that the onchain root
* hash exactly matches the expected configuration. This prevents a bad actor from
* attempting to hide a malicious configuration within the Merkle tree.
*/
import { SimpleMerkleTree } from "@openzeppelin/merkle-tree";
import { AbiParameters, Hash } from "ox";
/**
* An example UCMT stored as an array of nodes. Each node is a tuple of the verifier
* address and the node configuration. When building the Merkle tree, each node is
* packed and hashed using `keccak256`.
*/
const USER_CONFIGURATION_MERKLE_TREE = [
["0x000000000000000000000000000000000000dEaD", "0xdeadbeef"],
["0x000000000000000000000000000000000000bEEF", "0x"],
["0x000000000000000000000000000000000000cafE", "0x0000000ff1ce"],
["0x000000000000000000000000000000000000F00D", "0xc0ffee"],
] as const;
function main() {
const merkleTree = SimpleMerkleTree.of(
USER_CONFIGURATION_MERKLE_TREE.map((node) =>
Hash.keccak256(AbiParameters.encodePacked(["address", "bytes"], node))
)
);
console.log("UCMT:", USER_CONFIGURATION_MERKLE_TREE);
console.log("UCMT root:", merkleTree.root);
console.log("UCMT proofs...");
USER_CONFIGURATION_MERKLE_TREE.forEach((_, i) =>
console.log(`node ${i + 1}:`, merkleTree.getProof(i))
);
console.log(
"\nVerify different configurations by changing the merkle tree in examples/verify-ucmt.ts."
);
console.log(
"Always check that your UCMT aligns with your account's onchain root hash."
);
}
main();