@aztec/foundation 0.0.1-commit.fcb71a6 → 0.0.1-commit.fffb133c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/branded-types/block_number.d.ts +4 -1
- package/dest/branded-types/block_number.d.ts.map +1 -1
- package/dest/branded-types/block_number.js +3 -0
- package/dest/branded-types/checkpoint_number.d.ts +10 -2
- package/dest/branded-types/checkpoint_number.d.ts.map +1 -1
- package/dest/branded-types/checkpoint_number.js +17 -8
- package/dest/branded-types/index.d.ts +3 -2
- package/dest/branded-types/index.d.ts.map +1 -1
- package/dest/branded-types/index.js +2 -1
- package/dest/branded-types/index_within_checkpoint.d.ts +42 -0
- package/dest/branded-types/index_within_checkpoint.d.ts.map +1 -0
- package/dest/branded-types/index_within_checkpoint.js +59 -0
- package/dest/buffer/buffer16.d.ts +4 -1
- package/dest/buffer/buffer16.d.ts.map +1 -1
- package/dest/buffer/buffer16.js +3 -1
- package/dest/buffer/buffer32.d.ts +4 -1
- package/dest/buffer/buffer32.d.ts.map +1 -1
- package/dest/buffer/buffer32.js +3 -1
- package/dest/collection/array.d.ts +6 -1
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +27 -0
- package/dest/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +6 -3
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +16 -7
- package/dest/config/parse-env.d.ts +3 -0
- package/dest/config/parse-env.d.ts.map +1 -0
- package/dest/config/parse-env.js +7 -0
- package/dest/config/secret_value.js +3 -1
- package/dest/crypto/ecdsa/signature.d.ts +10 -1
- package/dest/crypto/ecdsa/signature.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.d.ts +1 -2
- package/dest/crypto/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/poseidon/index.js +0 -9
- package/dest/crypto/random/randomness_singleton.d.ts +2 -2
- package/dest/crypto/random/randomness_singleton.d.ts.map +1 -1
- package/dest/crypto/random/randomness_singleton.js +3 -3
- package/dest/crypto/sync/poseidon/index.d.ts +1 -2
- package/dest/crypto/sync/poseidon/index.d.ts.map +1 -1
- package/dest/crypto/sync/poseidon/index.js +0 -8
- package/dest/curves/bls12/field.js +6 -3
- package/dest/curves/bls12/point.d.ts +10 -1
- package/dest/curves/bls12/point.d.ts.map +1 -1
- package/dest/curves/bls12/point.js +3 -1
- package/dest/curves/bn254/field.js +5 -2
- package/dest/curves/grumpkin/point.d.ts +11 -2
- package/dest/curves/grumpkin/point.d.ts.map +1 -1
- package/dest/error/index.d.ts +4 -4
- package/dest/error/index.d.ts.map +1 -1
- package/dest/eth-address/index.js +4 -2
- package/dest/eth-signature/eth_signature.d.ts +4 -1
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/json-rpc/client/undici.d.ts +1 -1
- package/dest/json-rpc/client/undici.d.ts.map +1 -1
- package/dest/json-rpc/client/undici.js +21 -4
- package/dest/json-rpc/fixtures/class_a.d.ts +3 -3
- package/dest/json-rpc/fixtures/class_a.d.ts.map +1 -1
- package/dest/json-rpc/fixtures/class_b.d.ts +3 -3
- package/dest/json-rpc/fixtures/class_b.d.ts.map +1 -1
- package/dest/json-rpc/server/safe_json_rpc_server.js +1 -1
- package/dest/log/pino-logger.d.ts +1 -1
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +1 -1
- package/dest/retry/index.d.ts +11 -1
- package/dest/retry/index.d.ts.map +1 -1
- package/dest/retry/index.js +11 -0
- package/dest/serialize/buffer_reader.d.ts +7 -4
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +13 -4
- package/dest/trees/balanced_merkle_tree_root.d.ts +17 -0
- package/dest/trees/balanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/{balanced_merkle_tree.js → balanced_merkle_tree_root.js} +2 -17
- package/dest/trees/hasher.d.ts +3 -1
- package/dest/trees/hasher.d.ts.map +1 -1
- package/dest/trees/hasher.js +10 -5
- package/dest/trees/index.d.ts +4 -4
- package/dest/trees/index.d.ts.map +1 -1
- package/dest/trees/index.js +3 -3
- package/dest/trees/membership_witness.d.ts +11 -1
- package/dest/trees/membership_witness.d.ts.map +1 -1
- package/dest/trees/membership_witness.js +9 -0
- package/dest/trees/merkle_tree_calculator.d.ts +1 -1
- package/dest/trees/merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/merkle_tree_calculator.js +2 -2
- package/dest/trees/sibling_path.d.ts +2 -1
- package/dest/trees/sibling_path.d.ts.map +1 -1
- package/dest/trees/sibling_path.js +2 -2
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts +2 -3
- package/dest/trees/unbalanced_merkle_tree_calculator.d.ts.map +1 -1
- package/dest/trees/unbalanced_merkle_tree_calculator.js +1 -5
- package/dest/trees/{unbalanced_merkle_tree.d.ts → unbalanced_merkle_tree_root.d.ts} +3 -5
- package/dest/trees/unbalanced_merkle_tree_root.d.ts.map +1 -0
- package/dest/trees/{unbalanced_merkle_tree.js → unbalanced_merkle_tree_root.js} +11 -49
- package/dest/trees/unbalanced_tree_store.d.ts +5 -1
- package/dest/trees/unbalanced_tree_store.d.ts.map +1 -1
- package/dest/trees/unbalanced_tree_store.js +49 -1
- package/dest/types/index.d.ts +1 -1
- package/package.json +4 -4
- package/src/branded-types/block_number.ts +5 -0
- package/src/branded-types/checkpoint_number.ts +22 -7
- package/src/branded-types/index.ts +2 -1
- package/src/branded-types/index_within_checkpoint.ts +88 -0
- package/src/collection/array.ts +31 -0
- package/src/config/env_var.ts +18 -7
- package/src/config/index.ts +19 -4
- package/src/config/parse-env.ts +4 -0
- package/src/crypto/poseidon/index.ts +0 -10
- package/src/crypto/random/randomness_singleton.ts +2 -4
- package/src/crypto/sync/poseidon/index.ts +0 -9
- package/src/eth-address/index.ts +1 -1
- package/src/json-rpc/client/undici.ts +21 -3
- package/src/json-rpc/server/safe_json_rpc_server.ts +1 -1
- package/src/log/pino-logger.ts +2 -1
- package/src/retry/index.ts +18 -0
- package/src/serialize/buffer_reader.ts +21 -9
- package/src/trees/{balanced_merkle_tree.ts → balanced_merkle_tree_root.ts} +2 -18
- package/src/trees/hasher.ts +9 -0
- package/src/trees/index.ts +3 -3
- package/src/trees/membership_witness.ts +8 -0
- package/src/trees/merkle_tree_calculator.ts +2 -2
- package/src/trees/sibling_path.ts +2 -2
- package/src/trees/unbalanced_merkle_tree_calculator.ts +1 -12
- package/src/trees/{unbalanced_merkle_tree.ts → unbalanced_merkle_tree_root.ts} +17 -61
- package/src/trees/unbalanced_tree_store.ts +57 -2
- package/src/types/index.ts +1 -1
- package/dest/json-rpc/server/telemetry.d.ts +0 -2
- package/dest/json-rpc/server/telemetry.d.ts.map +0 -1
- package/dest/json-rpc/server/telemetry.js +0 -0
- package/dest/trees/balanced_merkle_tree.d.ts +0 -22
- package/dest/trees/balanced_merkle_tree.d.ts.map +0 -1
- package/dest/trees/unbalanced_merkle_tree.d.ts.map +0 -1
- package/src/json-rpc/server/telemetry.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unbalanced_merkle_tree_root.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_merkle_tree_root.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,wBAAwB,gEAA+E,CAAC;AAErH,eAAO,MAAM,6BAA6B,yEAC8B,CAAC;AAEzE,eAAO,MAAM,mBAAmB,gEAA2D,CAAC;AAE5F;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,8FAAgB,EACtB,SAAS,sBAAmB,GAC3B,MAAM,CA6BR;AAED,wBAAsB,oCAAoC,CACxD,MAAM,EAAE,MAAM,EAAE,EAChB,MAAM,uGAAqB,EAC3B,SAAS,sBAAmB,GAC3B,OAAO,CAAC,MAAM,CAAC,CA6BjB;AAMD,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EAAE,EAChB,eAAe,sBAAmB,EAClC,SAAS,sBAAmB,EAC5B,MAAM,8FAAgB,GACrB,MAAM,CAGR"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { computeBalancedMerkleTreeRoot, computeBalancedMerkleTreeRootAsync
|
|
1
|
+
import { computeBalancedMerkleTreeRoot, computeBalancedMerkleTreeRootAsync } from './balanced_merkle_tree_root.js';
|
|
2
|
+
import { poseidonMerkleHash, shaMerkleHash } from './hasher.js';
|
|
3
|
+
import { UnbalancedMerkleTreeCalculator } from './unbalanced_merkle_tree_calculator.js';
|
|
2
4
|
export const computeUnbalancedShaRoot = (leaves)=>computeUnbalancedMerkleTreeRoot(leaves, shaMerkleHash);
|
|
3
5
|
export const computeUnbalancedPoseidonRoot = async (leaves)=>await computeUnbalancedMerkleTreeRootAsync(leaves, poseidonMerkleHash);
|
|
6
|
+
export const computeWonkyShaRoot = (leaves)=>computeWonkyMerkleTreeRoot(leaves);
|
|
4
7
|
/**
|
|
5
8
|
* Computes the Merkle root of an unbalanced tree.
|
|
6
9
|
*
|
|
@@ -71,52 +74,11 @@ export async function computeUnbalancedMerkleTreeRootAsync(leaves, hasher = pose
|
|
|
71
74
|
}
|
|
72
75
|
return root;
|
|
73
76
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
/// Get the maximum depth of an unbalanced tree that can be created with the given number of leaves.
|
|
83
|
-
function getMaxUnbalancedTreeDepth(numLeaves) {
|
|
84
|
-
return Math.ceil(Math.log2(numLeaves));
|
|
85
|
-
}
|
|
86
|
-
function findPosition(rootLevel, leafLevel, numLeaves, indexOffset, targetIndex) {
|
|
87
|
-
if (numLeaves <= 1) {
|
|
88
|
-
// Single leaf.
|
|
89
|
-
return {
|
|
90
|
-
level: rootLevel,
|
|
91
|
-
indexAtLevel: indexOffset
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
// The largest balanced tree that can be created with the given number of leaves.
|
|
95
|
-
const maxBalancedTreeDepth = getMaxBalancedSubtreeDepth(numLeaves);
|
|
96
|
-
const numBalancedLeaves = 2 ** maxBalancedTreeDepth;
|
|
97
|
-
const numRemainingLeaves = numLeaves - numBalancedLeaves;
|
|
98
|
-
if (targetIndex < numBalancedLeaves) {
|
|
99
|
-
// Target is in the balanced tree.
|
|
100
|
-
// - If numRemainingLeaves is 0: this balanced tree is grown from the current root.
|
|
101
|
-
// - If numRemainingLeaves is not 0: the remaining leaves will form another tree, which will become the right child of the root.
|
|
102
|
-
// And the balanced tree will be the left child of the root.
|
|
103
|
-
// There will be an extra level between the root of the balanced tree and the current root.
|
|
104
|
-
const extraLevel = numRemainingLeaves ? 1 : 0;
|
|
105
|
-
return {
|
|
106
|
-
level: rootLevel + maxBalancedTreeDepth + extraLevel,
|
|
107
|
-
indexAtLevel: indexOffset + targetIndex
|
|
108
|
-
};
|
|
109
|
-
} else {
|
|
110
|
-
// Target is in the right branch.
|
|
111
|
-
const rightBranchMaxLevel = getMaxUnbalancedTreeDepth(numRemainingLeaves);
|
|
112
|
-
const shiftedUp = leafLevel - rootLevel - rightBranchMaxLevel - 1;
|
|
113
|
-
const nextLeafLevel = leafLevel - shiftedUp;
|
|
114
|
-
const newIndexOffset = indexOffset + numBalancedLeaves >> shiftedUp;
|
|
115
|
-
const shiftedTargetIndex = targetIndex - numBalancedLeaves;
|
|
116
|
-
return findPosition(rootLevel + 1, nextLeafLevel, numRemainingLeaves, newIndexOffset, shiftedTargetIndex);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
export function findLeafLevelAndIndex(numLeaves, leafIndex) {
|
|
120
|
-
const maxLevel = getMaxUnbalancedTreeDepth(numLeaves);
|
|
121
|
-
return findPosition(0, maxLevel, numLeaves, 0, leafIndex);
|
|
77
|
+
// A **wonky** tree is a "compressed" unbalanced Merkle tree.
|
|
78
|
+
// It is constructed in the same way as an unbalanced tree: by first creating the largest possible left subtree, with
|
|
79
|
+
// the remaining leaves forming a right subtree that follows the same process recursively.
|
|
80
|
+
// During construction, leaves equal to `valueToCompress` are skipped (compressed) and do not contribute to the tree.
|
|
81
|
+
export function computeWonkyMerkleTreeRoot(leaves, valueToCompress = Buffer.alloc(32), emptyRoot = Buffer.alloc(32), hasher = shaMerkleHash) {
|
|
82
|
+
const calculator = UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress, emptyRoot, hasher);
|
|
83
|
+
return calculator.getRoot();
|
|
122
84
|
}
|
|
@@ -17,4 +17,8 @@ export declare class UnbalancedTreeStore<T> {
|
|
|
17
17
|
getSibling(location: TreeNodeLocation): T | undefined;
|
|
18
18
|
getChildren(location: TreeNodeLocation): [T | undefined, T | undefined];
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
export declare function findLeafLevelAndIndex(numLeaves: number, leafIndex: number): {
|
|
21
|
+
level: number;
|
|
22
|
+
indexAtLevel: number;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5iYWxhbmNlZF90cmVlX3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdHJlZXMvdW5iYWxhbmNlZF90cmVlX3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE1BQU0sV0FBVyxnQkFBZ0I7SUFDL0IsS0FBSyxFQUFFLE1BQU0sQ0FBQztJQUNkLEtBQUssRUFBRSxNQUFNLENBQUM7Q0FDZjtBQU9ELHFCQUFhLG1CQUFtQixDQUFDLENBQUM7O0lBSWhDLFlBQVksU0FBUyxFQUFFLE1BQU0sRUFFNUI7SUFFRCxPQUFPLENBQUMsU0FBUyxFQUFFLE1BQU0sRUFBRSxLQUFLLEVBQUUsQ0FBQyxHQUFHLGdCQUFnQixDQWVyRDtJQUVELE9BQU8sQ0FBQyxFQUFFLEtBQUssRUFBRSxLQUFLLEVBQUUsRUFBRSxnQkFBZ0IsRUFBRSxLQUFLLEVBQUUsQ0FBQyxRQVNuRDtJQUVELGlCQUFpQixDQUFDLEVBQUUsS0FBSyxFQUFFLEtBQUssRUFBRSxFQUFFLGdCQUFnQixHQUFHLGdCQUFnQixDQU10RTtJQUVELGtCQUFrQixDQUFDLEVBQUUsS0FBSyxFQUFFLEtBQUssRUFBRSxFQUFFLGdCQUFnQixHQUFHLGdCQUFnQixDQU12RTtJQUVELGlCQUFpQixDQUFDLEVBQUUsS0FBSyxFQUFFLEtBQUssRUFBRSxFQUFFLGdCQUFnQixHQUFHLENBQUMsZ0JBQWdCLEVBQUUsZ0JBQWdCLENBQUMsQ0FJMUY7SUFFRCxPQUFPLENBQUMsU0FBUyxFQUFFLE1BQU0sR0FBRyxDQUFDLEdBQUcsU0FBUyxDQU94QztJQUVELE9BQU8sQ0FBQyxRQUFRLEVBQUUsZ0JBQWdCLEdBQUcsQ0FBQyxHQUFHLFNBQVMsQ0FFakQ7SUFFRCxPQUFPLElBQUksQ0FBQyxHQUFHLFNBQVMsQ0FFdkI7SUFFRCxTQUFTLENBQUMsUUFBUSxFQUFFLGdCQUFnQixHQUFHLENBQUMsR0FBRyxTQUFTLENBR25EO0lBRUQsVUFBVSxDQUFDLFFBQVEsRUFBRSxnQkFBZ0IsR0FBRyxDQUFDLEdBQUcsU0FBUyxDQUdwRDtJQUVELFdBQVcsQ0FBQyxRQUFRLEVBQUUsZ0JBQWdCLEdBQUcsQ0FBQyxDQUFDLEdBQUcsU0FBUyxFQUFFLENBQUMsR0FBRyxTQUFTLENBQUMsQ0FHdEU7Q0FLRjtBQXNERCx3QkFBZ0IscUJBQXFCLENBQUMsU0FBUyxFQUFFLE1BQU0sRUFBRSxTQUFTLEVBQUUsTUFBTTs7O0VBR3pFIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unbalanced_tree_store.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_tree_store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unbalanced_tree_store.d.ts","sourceRoot":"","sources":["../../src/trees/unbalanced_tree_store.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAOD,qBAAa,mBAAmB,CAAC,CAAC;;IAIhC,YAAY,SAAS,EAAE,MAAM,EAE5B;IAED,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,gBAAgB,CAerD;IAED,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,QASnD;IAED,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,gBAAgB,CAMtE;IAED,kBAAkB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,gBAAgB,CAMvE;IAED,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAI1F;IAED,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAOxC;IAED,OAAO,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS,CAEjD;IAED,OAAO,IAAI,CAAC,GAAG,SAAS,CAEvB;IAED,SAAS,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS,CAGnD;IAED,UAAU,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,GAAG,SAAS,CAGpD;IAED,WAAW,CAAC,QAAQ,EAAE,gBAAgB,GAAG,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,SAAS,CAAC,CAGtE;CAKF;AAsDD,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;;EAGzE"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { findLeafLevelAndIndex } from './unbalanced_merkle_tree.js';
|
|
2
1
|
export class UnbalancedTreeStore {
|
|
3
2
|
#nodeMapping = new Map();
|
|
4
3
|
#numLeaves;
|
|
@@ -98,3 +97,52 @@ export class UnbalancedTreeStore {
|
|
|
98
97
|
return `${location.level}-${location.index}`;
|
|
99
98
|
}
|
|
100
99
|
}
|
|
100
|
+
/// Get the depth of the maximum balanced tree that can be created with the given number of leaves. The subtree will be
|
|
101
|
+
/// the left most subtree of the unbalanced tree with a total of `numLeaves` leaves.
|
|
102
|
+
///
|
|
103
|
+
/// Note: All the leaves may not be used to form the tree. For example, if there are 5 leaves, the maximum depth is 2,
|
|
104
|
+
/// only 4 leaves are used to form a balanced tree.
|
|
105
|
+
function getMaxBalancedSubtreeDepth(numLeaves) {
|
|
106
|
+
return Math.floor(Math.log2(numLeaves));
|
|
107
|
+
}
|
|
108
|
+
/// Get the maximum depth of an unbalanced tree that can be created with the given number of leaves.
|
|
109
|
+
function getMaxUnbalancedTreeDepth(numLeaves) {
|
|
110
|
+
return Math.ceil(Math.log2(numLeaves));
|
|
111
|
+
}
|
|
112
|
+
function findPosition(rootLevel, leafLevel, numLeaves, indexOffset, targetIndex) {
|
|
113
|
+
if (numLeaves <= 1) {
|
|
114
|
+
// Single leaf.
|
|
115
|
+
return {
|
|
116
|
+
level: rootLevel,
|
|
117
|
+
indexAtLevel: indexOffset
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
// The largest balanced tree that can be created with the given number of leaves.
|
|
121
|
+
const maxBalancedTreeDepth = getMaxBalancedSubtreeDepth(numLeaves);
|
|
122
|
+
const numBalancedLeaves = 2 ** maxBalancedTreeDepth;
|
|
123
|
+
const numRemainingLeaves = numLeaves - numBalancedLeaves;
|
|
124
|
+
if (targetIndex < numBalancedLeaves) {
|
|
125
|
+
// Target is in the balanced tree.
|
|
126
|
+
// - If numRemainingLeaves is 0: this balanced tree is grown from the current root.
|
|
127
|
+
// - If numRemainingLeaves is not 0: the remaining leaves will form another tree, which will become the right child of the root.
|
|
128
|
+
// And the balanced tree will be the left child of the root.
|
|
129
|
+
// There will be an extra level between the root of the balanced tree and the current root.
|
|
130
|
+
const extraLevel = numRemainingLeaves ? 1 : 0;
|
|
131
|
+
return {
|
|
132
|
+
level: rootLevel + maxBalancedTreeDepth + extraLevel,
|
|
133
|
+
indexAtLevel: indexOffset + targetIndex
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
// Target is in the right branch.
|
|
137
|
+
const rightBranchMaxLevel = getMaxUnbalancedTreeDepth(numRemainingLeaves);
|
|
138
|
+
const shiftedUp = leafLevel - rootLevel - rightBranchMaxLevel - 1;
|
|
139
|
+
const nextLeafLevel = leafLevel - shiftedUp;
|
|
140
|
+
const newIndexOffset = indexOffset + numBalancedLeaves >> shiftedUp;
|
|
141
|
+
const shiftedTargetIndex = targetIndex - numBalancedLeaves;
|
|
142
|
+
return findPosition(rootLevel + 1, nextLeafLevel, numRemainingLeaves, newIndexOffset, shiftedTargetIndex);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function findLeafLevelAndIndex(numLeaves, leafIndex) {
|
|
146
|
+
const maxLevel = getMaxUnbalancedTreeDepth(numLeaves);
|
|
147
|
+
return findPosition(0, maxLevel, numLeaves, 0, leafIndex);
|
|
148
|
+
}
|
package/dest/types/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export type Prettify<T> = {
|
|
|
24
24
|
* Type-safe Event Emitter type
|
|
25
25
|
* @example
|
|
26
26
|
* export type ArchiverEmitter = TypedEventEmitter<{
|
|
27
|
-
* [L2BlockSourceEvents.
|
|
27
|
+
* [L2BlockSourceEvents.L2PruneUnproven]: (args: L2BlockSourceEvent) => void;
|
|
28
28
|
* [L2BlockSourceEvents.L2BlockProven]: (args: L2BlockSourceEvent) => void;
|
|
29
29
|
* }>;
|
|
30
30
|
* class Archiver extends (EventEmitter as new () => ArchiverEmitter) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/foundation",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.fffb133c",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dest/index.js",
|
|
6
6
|
"types": "./dest/index.d.ts",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"testEnvironment": "../../foundation/src/jest/env.mjs"
|
|
124
124
|
},
|
|
125
125
|
"dependencies": {
|
|
126
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
126
|
+
"@aztec/bb.js": "0.0.1-commit.fffb133c",
|
|
127
127
|
"@koa/cors": "^5.0.0",
|
|
128
128
|
"@noble/curves": "=1.7.0",
|
|
129
129
|
"@noble/hashes": "^1.6.1",
|
|
@@ -162,11 +162,11 @@
|
|
|
162
162
|
"@types/node": "^22.15.17",
|
|
163
163
|
"@types/pako": "^2.0.0",
|
|
164
164
|
"@types/supertest": "^2.0.12",
|
|
165
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
165
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
166
166
|
"comlink": "^4.4.1",
|
|
167
167
|
"eslint": "^9.26.0",
|
|
168
168
|
"eslint-config-prettier": "^10.1.5",
|
|
169
|
-
"eslint-plugin-import": "^
|
|
169
|
+
"eslint-plugin-import-x": "^4.6.1",
|
|
170
170
|
"eslint-plugin-jsdoc": "^50.6.14",
|
|
171
171
|
"eslint-plugin-no-only-tests": "^3.3.0",
|
|
172
172
|
"eslint-plugin-tsdoc": "^0.4.0",
|
|
@@ -87,6 +87,11 @@ BlockNumber.isValid = function (value: unknown): value is BlockNumber {
|
|
|
87
87
|
return typeof value === 'number' && Number.isInteger(value) && value >= 0;
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
+
/** Increments a BlockNumber by a given value. */
|
|
91
|
+
BlockNumber.add = function (bn: BlockNumber, increment: number): BlockNumber {
|
|
92
|
+
return BlockNumber(bn + increment);
|
|
93
|
+
};
|
|
94
|
+
|
|
90
95
|
/**
|
|
91
96
|
* The zero block value (genesis block).
|
|
92
97
|
*/
|
|
@@ -85,16 +85,31 @@ CheckpointNumber.isValid = function (value: unknown): value is CheckpointNumber
|
|
|
85
85
|
return typeof value === 'number' && Number.isInteger(value) && value >= 0;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
/**
|
|
89
|
-
* The zero checkpoint value.
|
|
90
|
-
*/
|
|
88
|
+
/** The zero checkpoint value. */
|
|
91
89
|
CheckpointNumber.ZERO = CheckpointNumber(0);
|
|
92
90
|
|
|
91
|
+
/** Initial checkpoint. */
|
|
92
|
+
CheckpointNumber.INITIAL = CheckpointNumber(1);
|
|
93
|
+
|
|
93
94
|
/**
|
|
94
95
|
* Zod schema for parsing and validating CheckpointNumber values.
|
|
95
96
|
* Accepts numbers, bigints, or strings and coerces them to CheckpointNumber.
|
|
96
97
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
function makeCheckpointNumberSchema(minValue: number) {
|
|
99
|
+
return z
|
|
100
|
+
.union([z.number(), z.bigint(), z.string()])
|
|
101
|
+
.pipe(z.coerce.number().int().min(minValue))
|
|
102
|
+
.transform(value => CheckpointNumber(value));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Zod schema for parsing and validating Checkpoint values.
|
|
107
|
+
* Accepts numbers, bigints, or strings and coerces them to CheckpointNumber.
|
|
108
|
+
*/
|
|
109
|
+
export const CheckpointNumberSchema = makeCheckpointNumberSchema(0);
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Zod schema for parsing and validating CheckpointNumber values that are strictly positive.
|
|
113
|
+
* Accepts numbers, bigints, or strings and coerces them to CheckpointNumber.
|
|
114
|
+
*/
|
|
115
|
+
export const CheckpointNumberPositiveSchema = makeCheckpointNumberSchema(1);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { BlockNumber, BlockNumberSchema, BlockNumberPositiveSchema } from './block_number.js';
|
|
2
|
-
export { CheckpointNumber, CheckpointNumberSchema } from './checkpoint_number.js';
|
|
2
|
+
export { CheckpointNumber, CheckpointNumberSchema, CheckpointNumberPositiveSchema } from './checkpoint_number.js';
|
|
3
3
|
export { EpochNumber, EpochNumberSchema } from './epoch.js';
|
|
4
|
+
export { IndexWithinCheckpoint, IndexWithinCheckpointSchema } from './index_within_checkpoint.js';
|
|
4
5
|
export { SlotNumber, SlotNumberSchema } from './slot.js';
|
|
5
6
|
|
|
6
7
|
export type { Branded } from './types.js';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
import type { Branded } from './types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A branded type representing the index of a block within a checkpoint.
|
|
7
|
+
* The first block in a checkpoint has index 0, the second has index 1, etc.
|
|
8
|
+
*
|
|
9
|
+
* This is a nominal type backed by a number, but TypeScript will treat it as
|
|
10
|
+
* incompatible with plain numbers and other branded numeric types.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const index = IndexWithinCheckpoint(0);
|
|
15
|
+
* const plainNumber: number = index; // OK - IndexWithinCheckpoint is assignable to number
|
|
16
|
+
* const indexFromNumber: IndexWithinCheckpoint = 0; // ERROR - number is not assignable to IndexWithinCheckpoint
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type IndexWithinCheckpoint = Branded<number, 'IndexWithinCheckpoint'>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates an IndexWithinCheckpoint from a number.
|
|
23
|
+
* @param value - The index (must be a non-negative integer)
|
|
24
|
+
* @returns The branded IndexWithinCheckpoint value
|
|
25
|
+
* @throws If the value is negative or not an integer
|
|
26
|
+
*/
|
|
27
|
+
export function IndexWithinCheckpoint(value: number): IndexWithinCheckpoint {
|
|
28
|
+
if (!Number.isInteger(value)) {
|
|
29
|
+
throw new Error(`IndexWithinCheckpoint must be an integer, got ${value}`);
|
|
30
|
+
}
|
|
31
|
+
if (value < 0) {
|
|
32
|
+
throw new Error(`IndexWithinCheckpoint must be non-negative, got ${value}`);
|
|
33
|
+
}
|
|
34
|
+
return value as IndexWithinCheckpoint;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates an IndexWithinCheckpoint from a bigint.
|
|
39
|
+
* @param value - The index as bigint (must be a non-negative integer within safe integer range)
|
|
40
|
+
* @returns The branded IndexWithinCheckpoint value
|
|
41
|
+
* @throws If the value is negative or exceeds Number.MAX_SAFE_INTEGER
|
|
42
|
+
*/
|
|
43
|
+
IndexWithinCheckpoint.fromBigInt = function (value: bigint): IndexWithinCheckpoint {
|
|
44
|
+
if (value < 0n) {
|
|
45
|
+
throw new Error(`IndexWithinCheckpoint must be non-negative, got ${value}`);
|
|
46
|
+
}
|
|
47
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
48
|
+
throw new Error(`IndexWithinCheckpoint ${value} exceeds MAX_SAFE_INTEGER`);
|
|
49
|
+
}
|
|
50
|
+
return Number(value) as IndexWithinCheckpoint;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Creates an IndexWithinCheckpoint from a string.
|
|
55
|
+
* @param value - The index as a string
|
|
56
|
+
* @returns The branded IndexWithinCheckpoint value
|
|
57
|
+
* @throws If the string cannot be parsed as a valid index
|
|
58
|
+
*/
|
|
59
|
+
IndexWithinCheckpoint.fromString = function (value: string): IndexWithinCheckpoint {
|
|
60
|
+
const parsed = parseInt(value, 10);
|
|
61
|
+
if (isNaN(parsed)) {
|
|
62
|
+
throw new Error(`Cannot parse IndexWithinCheckpoint from string: ${value}`);
|
|
63
|
+
}
|
|
64
|
+
return IndexWithinCheckpoint(parsed);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Type guard to check if a value is a valid IndexWithinCheckpoint.
|
|
69
|
+
* Note: At runtime, an IndexWithinCheckpoint is just a number, so this checks if the value
|
|
70
|
+
* is a non-negative integer.
|
|
71
|
+
*/
|
|
72
|
+
IndexWithinCheckpoint.isValid = function (value: unknown): value is IndexWithinCheckpoint {
|
|
73
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 0;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The zero index value (first block in checkpoint).
|
|
78
|
+
*/
|
|
79
|
+
IndexWithinCheckpoint.ZERO = IndexWithinCheckpoint(0);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Zod schema for parsing and validating IndexWithinCheckpoint values.
|
|
83
|
+
* Accepts numbers, bigints, or strings and coerces them to IndexWithinCheckpoint.
|
|
84
|
+
*/
|
|
85
|
+
export const IndexWithinCheckpointSchema = z
|
|
86
|
+
.union([z.number(), z.bigint(), z.string()])
|
|
87
|
+
.pipe(z.coerce.number().int().min(0))
|
|
88
|
+
.transform(value => IndexWithinCheckpoint(value));
|
package/src/collection/array.ts
CHANGED
|
@@ -250,6 +250,37 @@ export function chunk<T>(items: T[], chunkSize: number): T[][] {
|
|
|
250
250
|
return chunks;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
+
const UNINITIALIZED = Symbol('uninitialized');
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Splits the given iterable into chunks based on the key returned by the given function.
|
|
257
|
+
* Items must be contiguous to be included in the same chunk.
|
|
258
|
+
*/
|
|
259
|
+
export function chunkBy<T, U>(items: T[], fn: (item: T) => U): T[][] {
|
|
260
|
+
const chunks: T[][] = [];
|
|
261
|
+
let currentChunk: T[] = [];
|
|
262
|
+
let currentKey: U | typeof UNINITIALIZED = UNINITIALIZED;
|
|
263
|
+
|
|
264
|
+
for (const item of items) {
|
|
265
|
+
const key = fn(item);
|
|
266
|
+
if (currentKey === UNINITIALIZED || key !== currentKey) {
|
|
267
|
+
if (currentChunk.length > 0) {
|
|
268
|
+
chunks.push(currentChunk);
|
|
269
|
+
}
|
|
270
|
+
currentChunk = [item];
|
|
271
|
+
currentKey = key;
|
|
272
|
+
} else {
|
|
273
|
+
currentChunk.push(item);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (currentChunk.length > 0) {
|
|
278
|
+
chunks.push(currentChunk);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return chunks;
|
|
282
|
+
}
|
|
283
|
+
|
|
253
284
|
/** Partitions the given iterable into two arrays based on the predicate. */
|
|
254
285
|
export function partition<T>(items: T[], predicate: (item: T) => boolean): [T[], T[]] {
|
|
255
286
|
const pass: T[] = [];
|
package/src/config/env_var.ts
CHANGED
|
@@ -21,15 +21,13 @@ export type EnvVar =
|
|
|
21
21
|
| 'BB_NUM_IVC_VERIFIERS'
|
|
22
22
|
| 'BB_IVC_CONCURRENCY'
|
|
23
23
|
| 'BOOTSTRAP_NODES'
|
|
24
|
-
| '
|
|
25
|
-
| 'BLOB_SINK_PORT'
|
|
26
|
-
| 'BLOB_SINK_URL'
|
|
24
|
+
| 'BLOB_ARCHIVE_API_URL'
|
|
27
25
|
| 'BLOB_FILE_STORE_URLS'
|
|
28
26
|
| 'BLOB_FILE_STORE_UPLOAD_URL'
|
|
29
27
|
| 'BLOB_HEALTHCHECK_UPLOAD_INTERVAL_MINUTES'
|
|
30
28
|
| 'BOT_DA_GAS_LIMIT'
|
|
31
29
|
| 'BOT_FEE_PAYMENT_METHOD'
|
|
32
|
-
| '
|
|
30
|
+
| 'BOT_MIN_FEE_PADDING'
|
|
33
31
|
| 'BOT_FLUSH_SETUP_TRANSACTIONS'
|
|
34
32
|
| 'BOT_FOLLOW_CHAIN'
|
|
35
33
|
| 'BOT_L2_GAS_LIMIT'
|
|
@@ -153,6 +151,7 @@ export type EnvVar =
|
|
|
153
151
|
| 'PROVER_BROKER_BATCH_INTERVAL_MS'
|
|
154
152
|
| 'PROVER_BROKER_BATCH_SIZE'
|
|
155
153
|
| 'PROVER_BROKER_MAX_EPOCHS_TO_KEEP_RESULTS_FOR'
|
|
154
|
+
| 'PROVER_CANCEL_JOBS_ON_STOP'
|
|
156
155
|
| 'PROVER_COORDINATION_NODE_URLS'
|
|
157
156
|
| 'PROVER_FAILED_PROOF_STORE'
|
|
158
157
|
| 'PROVER_NODE_FAILED_EPOCH_STORE'
|
|
@@ -177,6 +176,7 @@ export type EnvVar =
|
|
|
177
176
|
| 'PROVER_TEST_VERIFICATION_DELAY_MS'
|
|
178
177
|
| 'PXE_L2_BLOCK_BATCH_SIZE'
|
|
179
178
|
| 'PXE_PROVER_ENABLED'
|
|
179
|
+
| 'PXE_SYNC_CHAIN_TIP'
|
|
180
180
|
| 'RPC_MAX_BATCH_SIZE'
|
|
181
181
|
| 'RPC_MAX_BODY_SIZE'
|
|
182
182
|
| 'RPC_SIMULATE_PUBLIC_MAX_GAS_LIMIT'
|
|
@@ -248,7 +248,6 @@ export type EnvVar =
|
|
|
248
248
|
| 'VALIDATOR_ADDRESSES'
|
|
249
249
|
| 'ROLLUP_VERSION'
|
|
250
250
|
| 'WS_BLOCK_CHECK_INTERVAL_MS'
|
|
251
|
-
| 'WS_PROVEN_BLOCKS_ONLY'
|
|
252
251
|
| 'WS_BLOCK_REQUEST_BATCH_SIZE'
|
|
253
252
|
| 'L1_READER_VIEM_POLLING_INTERVAL_MS'
|
|
254
253
|
| 'WS_DATA_DIRECTORY'
|
|
@@ -266,6 +265,7 @@ export type EnvVar =
|
|
|
266
265
|
| 'AZTEC_LOCAL_EJECTION_THRESHOLD'
|
|
267
266
|
| 'AZTEC_MANA_TARGET'
|
|
268
267
|
| 'AZTEC_PROVING_COST_PER_MANA'
|
|
268
|
+
| 'AZTEC_INITIAL_ETH_PER_FEE_ASSET'
|
|
269
269
|
| 'AZTEC_SLASHING_QUORUM'
|
|
270
270
|
| 'AZTEC_SLASHING_ROUND_SIZE_IN_EPOCHS'
|
|
271
271
|
| 'AZTEC_SLASHING_LIFETIME_IN_ROUNDS'
|
|
@@ -279,6 +279,7 @@ export type EnvVar =
|
|
|
279
279
|
| 'AZTEC_SLASHER_FLAVOR'
|
|
280
280
|
| 'AZTEC_GOVERNANCE_PROPOSER_QUORUM'
|
|
281
281
|
| 'AZTEC_GOVERNANCE_PROPOSER_ROUND_SIZE'
|
|
282
|
+
| 'AZTEC_GOVERNANCE_VOTING_DURATION'
|
|
282
283
|
| 'AZTEC_EXIT_DELAY_SECONDS'
|
|
283
284
|
| 'L1_GAS_LIMIT_BUFFER_PERCENTAGE'
|
|
284
285
|
| 'L1_GAS_PRICE_MAX'
|
|
@@ -305,7 +306,6 @@ export type EnvVar =
|
|
|
305
306
|
| 'K8S_POD_UID'
|
|
306
307
|
| 'K8S_NAMESPACE_NAME'
|
|
307
308
|
| 'VALIDATOR_REEXECUTE_DEADLINE_MS'
|
|
308
|
-
| 'ALWAYS_REEXECUTE_BLOCK_PROPOSALS'
|
|
309
309
|
| 'AUTO_UPDATE'
|
|
310
310
|
| 'AUTO_UPDATE_URL'
|
|
311
311
|
| 'WEB3_SIGNER_URL'
|
|
@@ -314,4 +314,15 @@ export type EnvVar =
|
|
|
314
314
|
| 'FISHERMAN_MODE'
|
|
315
315
|
| 'MAX_ALLOWED_ETH_CLIENT_DRIFT_SECONDS'
|
|
316
316
|
| 'LEGACY_BLS_CLI'
|
|
317
|
-
| 'DEBUG_FORCE_TX_PROOF_VERIFICATION'
|
|
317
|
+
| 'DEBUG_FORCE_TX_PROOF_VERIFICATION'
|
|
318
|
+
| 'VALIDATOR_HA_SIGNING_ENABLED'
|
|
319
|
+
| 'VALIDATOR_HA_NODE_ID'
|
|
320
|
+
| 'VALIDATOR_HA_POLLING_INTERVAL_MS'
|
|
321
|
+
| 'VALIDATOR_HA_SIGNING_TIMEOUT_MS'
|
|
322
|
+
| 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS'
|
|
323
|
+
| 'VALIDATOR_HA_DATABASE_URL'
|
|
324
|
+
| 'VALIDATOR_HA_RUN_MIGRATIONS'
|
|
325
|
+
| 'VALIDATOR_HA_POOL_MAX'
|
|
326
|
+
| 'VALIDATOR_HA_POOL_MIN'
|
|
327
|
+
| 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS'
|
|
328
|
+
| 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS';
|
package/src/config/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Fq, Fr } from '../curves/bn254/field.js';
|
|
|
2
2
|
import { createConsoleLogger } from '../log/console.js';
|
|
3
3
|
import type { EnvVar } from './env_var.js';
|
|
4
4
|
import { type NetworkNames, getActiveNetworkName } from './network_name.js';
|
|
5
|
+
import { parseBooleanEnv } from './parse-env.js';
|
|
5
6
|
import { SecretValue } from './secret_value.js';
|
|
6
7
|
|
|
7
8
|
export { SecretValue, getActiveNetworkName };
|
|
@@ -148,6 +149,23 @@ export function floatConfigHelper(
|
|
|
148
149
|
};
|
|
149
150
|
}
|
|
150
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Parses an environment variable to a 0-1 percentage value
|
|
154
|
+
*/
|
|
155
|
+
export function percentageConfigHelper(defaultVal: number): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
|
|
156
|
+
return {
|
|
157
|
+
parseEnv: (val: string): number => {
|
|
158
|
+
const parsed = safeParseFloat(val, defaultVal);
|
|
159
|
+
if (parsed < 0 || parsed > 1) {
|
|
160
|
+
throw new TypeError(`Invalid percentage value: ${parsed} should be between 0 and 1`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return parsed;
|
|
164
|
+
},
|
|
165
|
+
defaultValue: defaultVal,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
151
169
|
/**
|
|
152
170
|
* Generates parseEnv and default values for a numerical config value.
|
|
153
171
|
* @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
|
|
@@ -231,10 +249,7 @@ export function secretValueConfigHelper<T>(parse: (val: string | undefined) => T
|
|
|
231
249
|
};
|
|
232
250
|
}
|
|
233
251
|
|
|
234
|
-
|
|
235
|
-
export function parseBooleanEnv(val: string | undefined): boolean {
|
|
236
|
-
return val !== undefined && ['1', 'true', 'TRUE'].includes(val);
|
|
237
|
-
}
|
|
252
|
+
export { parseBooleanEnv } from './parse-env.js';
|
|
238
253
|
|
|
239
254
|
export function secretStringConfigHelper(): Required<
|
|
240
255
|
Pick<ConfigMapping, 'parseEnv' | 'defaultValue' | 'isBoolean'> & {
|
|
@@ -35,16 +35,6 @@ export async function poseidon2HashWithSeparator(input: Fieldable[], separator:
|
|
|
35
35
|
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export async function poseidon2HashAccumulate(input: Fieldable[]): Promise<Fr> {
|
|
39
|
-
const inputFields = serializeToFields(input);
|
|
40
|
-
await BarretenbergSync.initSingleton();
|
|
41
|
-
const api = BarretenbergSync.getSingleton();
|
|
42
|
-
const response = api.poseidon2HashAccumulate({
|
|
43
|
-
inputs: inputFields.map(i => i.toBuffer()),
|
|
44
|
-
});
|
|
45
|
-
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
38
|
/**
|
|
49
39
|
* Runs a Poseidon2 permutation.
|
|
50
40
|
* @param input the input state. Expected to be of size 4.
|
|
@@ -12,11 +12,9 @@ export class RandomnessSingleton {
|
|
|
12
12
|
private static instance: RandomnessSingleton;
|
|
13
13
|
|
|
14
14
|
private counter = 0;
|
|
15
|
+
private readonly log = createLogger('foundation:randomness_singleton');
|
|
15
16
|
|
|
16
|
-
private constructor(
|
|
17
|
-
private readonly seed?: number,
|
|
18
|
-
private readonly log = createLogger('foundation:randomness_singleton'),
|
|
19
|
-
) {
|
|
17
|
+
private constructor(private readonly seed?: number) {
|
|
20
18
|
if (seed !== undefined) {
|
|
21
19
|
this.log.debug(`Using pseudo-randomness with seed: ${seed}`);
|
|
22
20
|
this.counter = seed;
|
|
@@ -34,15 +34,6 @@ export function poseidon2HashWithSeparator(input: Fieldable[], separator: number
|
|
|
34
34
|
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export function poseidon2HashAccumulate(input: Fieldable[]): Fr {
|
|
38
|
-
const inputFields = serializeToFields(input);
|
|
39
|
-
const api = BarretenbergSync.getSingleton();
|
|
40
|
-
const response = api.poseidon2HashAccumulate({
|
|
41
|
-
inputs: inputFields.map(i => i.toBuffer()),
|
|
42
|
-
});
|
|
43
|
-
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
37
|
/**
|
|
47
38
|
* Runs a Poseidon2 permutation.
|
|
48
39
|
* @param input the input state. Expected to be of size 4.
|
package/src/eth-address/index.ts
CHANGED
|
@@ -249,7 +249,7 @@ export class EthAddress {
|
|
|
249
249
|
/** Converts a number into an address. Useful for testing. */
|
|
250
250
|
static fromNumber(num: bigint | number): EthAddress {
|
|
251
251
|
const buffer = Buffer.alloc(EthAddress.SIZE_IN_BYTES);
|
|
252
|
-
buffer.writeBigUInt64BE(BigInt(num),
|
|
252
|
+
buffer.writeBigUInt64BE(BigInt(num), EthAddress.SIZE_IN_BYTES - 8);
|
|
253
253
|
return new EthAddress(buffer);
|
|
254
254
|
}
|
|
255
255
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { promisify } from 'node:util';
|
|
2
|
+
import { gunzip as gunzipCb, gzip as gzipCb } from 'node:zlib';
|
|
1
3
|
import { Agent, type Dispatcher } from 'undici';
|
|
2
4
|
|
|
3
5
|
import { createLogger } from '../../log/pino-logger.js';
|
|
@@ -5,8 +7,14 @@ import { NoRetryError } from '../../retry/index.js';
|
|
|
5
7
|
import { jsonStringify } from '../convert.js';
|
|
6
8
|
import type { JsonRpcFetch } from './fetch.js';
|
|
7
9
|
|
|
10
|
+
const gzip = promisify(gzipCb);
|
|
11
|
+
const gunzip = promisify(gunzipCb);
|
|
12
|
+
|
|
8
13
|
const log = createLogger('json-rpc:json_rpc_client:undici');
|
|
9
14
|
|
|
15
|
+
/** Minimum request size in bytes to trigger compression. */
|
|
16
|
+
const COMPRESSION_THRESHOLD = 1024;
|
|
17
|
+
|
|
10
18
|
export { Agent };
|
|
11
19
|
|
|
12
20
|
export function makeUndiciFetch(client = new Agent()): JsonRpcFetch {
|
|
@@ -14,14 +22,18 @@ export function makeUndiciFetch(client = new Agent()): JsonRpcFetch {
|
|
|
14
22
|
log.trace(`JsonRpcClient.fetch: ${host}`, { host, body });
|
|
15
23
|
let resp: Dispatcher.ResponseData;
|
|
16
24
|
try {
|
|
25
|
+
const jsonBody = Buffer.from(jsonStringify(body));
|
|
26
|
+
const shouldCompress = jsonBody.length >= COMPRESSION_THRESHOLD;
|
|
17
27
|
resp = await client.request({
|
|
18
28
|
method: 'POST',
|
|
19
29
|
origin: new URL(host),
|
|
20
30
|
path: '/',
|
|
21
|
-
body:
|
|
31
|
+
body: shouldCompress ? await gzip(jsonBody) : jsonBody,
|
|
22
32
|
headers: {
|
|
23
33
|
...extraHeaders,
|
|
24
34
|
'content-type': 'application/json',
|
|
35
|
+
...(shouldCompress && { 'content-encoding': 'gzip' }),
|
|
36
|
+
'accept-encoding': 'gzip',
|
|
25
37
|
},
|
|
26
38
|
});
|
|
27
39
|
} catch (err) {
|
|
@@ -31,13 +43,19 @@ export function makeUndiciFetch(client = new Agent()): JsonRpcFetch {
|
|
|
31
43
|
|
|
32
44
|
let responseJson: any;
|
|
33
45
|
const responseOk = resp.statusCode >= 200 && resp.statusCode <= 299;
|
|
46
|
+
const contentEncoding = resp.headers['content-encoding'];
|
|
34
47
|
try {
|
|
35
|
-
|
|
48
|
+
if (contentEncoding === 'gzip') {
|
|
49
|
+
const jsonBuffer = await gunzip(await resp.body.arrayBuffer());
|
|
50
|
+
responseJson = JSON.parse(jsonBuffer.toString('utf-8'));
|
|
51
|
+
} else {
|
|
52
|
+
responseJson = await resp.body.json();
|
|
53
|
+
}
|
|
36
54
|
} catch {
|
|
37
55
|
if (!responseOk) {
|
|
38
56
|
throw new Error('HTTP ' + resp.statusCode);
|
|
39
57
|
}
|
|
40
|
-
throw new Error(`Failed to parse body as JSON: ${await resp.body.text()}`);
|
|
58
|
+
throw new Error(`Failed to parse body as JSON. encoding: ${contentEncoding}, body: ${await resp.body.text()}`);
|
|
41
59
|
}
|
|
42
60
|
|
|
43
61
|
if (!responseOk) {
|