@aztec/stdlib 0.0.1-commit.9ef841308 → 0.0.1-commit.a89ec08
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/abi/abi.d.ts +26 -191
- package/dest/abi/abi.d.ts.map +1 -1
- package/dest/abi/abi.js +45 -4
- package/dest/abi/selector.d.ts +2 -2
- package/dest/abi/selector.d.ts.map +1 -1
- package/dest/abi/selector.js +1 -1
- package/dest/avm/avm.d.ts +300 -300
- package/dest/avm/avm_accumulated_data.js +2 -2
- package/dest/avm/avm_circuit_public_inputs.js +2 -2
- package/dest/avm/revert_code.d.ts +8 -18
- package/dest/avm/revert_code.d.ts.map +1 -1
- package/dest/avm/revert_code.js +15 -30
- package/dest/block/l2_block_stream/interfaces.d.ts +6 -3
- package/dest/block/l2_block_stream/interfaces.d.ts.map +1 -1
- package/dest/config/index.d.ts +1 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +0 -1
- package/dest/config/sequencer-config.d.ts +1 -3
- package/dest/config/sequencer-config.d.ts.map +1 -1
- package/dest/config/sequencer-config.js +0 -1
- package/dest/contract/contract_address.d.ts +3 -3
- package/dest/contract/contract_address.js +3 -3
- package/dest/contract/contract_class_id.d.ts +2 -2
- package/dest/contract/contract_class_id.js +2 -2
- package/dest/contract/index.d.ts +3 -1
- package/dest/contract/index.d.ts.map +1 -1
- package/dest/contract/index.js +2 -0
- package/dest/contract/interfaces/contract_class.d.ts +156 -3
- package/dest/contract/interfaces/contract_class.d.ts.map +1 -1
- package/dest/contract/interfaces/contract_class.js +28 -1
- package/dest/contract/private_function_membership_proof.d.ts +32 -0
- package/dest/contract/private_function_membership_proof.d.ts.map +1 -0
- package/dest/contract/private_function_membership_proof.js +124 -0
- package/dest/contract/utility_function_membership_proof.d.ts +27 -0
- package/dest/contract/utility_function_membership_proof.d.ts.map +1 -0
- package/dest/contract/utility_function_membership_proof.js +87 -0
- package/dest/file-store/factory.d.ts +3 -4
- package/dest/file-store/factory.d.ts.map +1 -1
- package/dest/file-store/factory.js +2 -2
- package/dest/file-store/http.d.ts +2 -9
- package/dest/file-store/http.d.ts.map +1 -1
- package/dest/file-store/http.js +9 -20
- package/dest/file-store/index.d.ts +1 -2
- package/dest/file-store/index.d.ts.map +1 -1
- package/dest/gas/gas_settings.d.ts +40 -3
- package/dest/gas/gas_settings.d.ts.map +1 -1
- package/dest/gas/gas_settings.js +50 -6
- package/dest/interfaces/aztec-node-admin.d.ts +7 -13
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-debug.d.ts +21 -0
- package/dest/interfaces/aztec-node-debug.d.ts.map +1 -0
- package/dest/interfaces/aztec-node-debug.js +18 -0
- package/dest/interfaces/client.d.ts +2 -1
- package/dest/interfaces/client.d.ts.map +1 -1
- package/dest/interfaces/client.js +1 -0
- package/dest/interfaces/l2_logs_source.d.ts +3 -5
- package/dest/interfaces/l2_logs_source.d.ts.map +1 -1
- package/dest/interfaces/proving-job.d.ts +200 -200
- package/dest/interfaces/validator.d.ts +26 -38
- package/dest/interfaces/validator.d.ts.map +1 -1
- package/dest/interfaces/validator.js +3 -2
- package/dest/kernel/claimed_length_array.js +1 -1
- package/dest/kernel/hints/private_kernel_reset_hints.d.ts +1 -1
- package/dest/kernel/hints/private_kernel_reset_hints.d.ts.map +1 -1
- package/dest/kernel/padded_side_effects.js +1 -1
- package/dest/kernel/private_to_avm_accumulated_data.js +2 -2
- package/dest/kernel/private_to_public_accumulated_data.js +2 -2
- package/dest/kernel/private_to_rollup_accumulated_data.js +1 -1
- package/dest/logs/extended_directional_app_tagging_secret.d.ts +4 -4
- package/dest/logs/extended_directional_app_tagging_secret.d.ts.map +1 -1
- package/dest/logs/extended_directional_app_tagging_secret.js +12 -5
- package/dest/logs/private_log.js +1 -1
- package/dest/logs/public_log.d.ts +1 -1
- package/dest/logs/public_log.d.ts.map +1 -1
- package/dest/logs/public_log.js +7 -1
- package/dest/messaging/l1_to_l2_message_source.d.ts +2 -4
- package/dest/messaging/l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/p2p/block_proposal.d.ts +2 -2
- package/dest/p2p/block_proposal.d.ts.map +1 -1
- package/dest/p2p/block_proposal.js +1 -1
- package/dest/p2p/checkpoint_proposal.d.ts +2 -2
- package/dest/p2p/checkpoint_proposal.d.ts.map +1 -1
- package/dest/p2p/checkpoint_proposal.js +1 -1
- package/dest/parity/parity_base_private_inputs.js +1 -1
- package/dest/proofs/chonk_proof.d.ts +2 -46
- package/dest/proofs/chonk_proof.d.ts.map +1 -1
- package/dest/proofs/chonk_proof.js +15 -84
- package/dest/rollup/base_rollup_hints.js +2 -2
- package/dest/rollup/block_root_rollup_private_inputs.js +5 -5
- package/dest/rollup/checkpoint_rollup_public_inputs.js +1 -1
- package/dest/rollup/checkpoint_root_rollup_private_inputs.js +3 -3
- package/dest/rollup/root_rollup_public_inputs.js +1 -1
- package/dest/rollup/tree_snapshot_diff_hints.js +2 -2
- package/dest/tests/factories.d.ts +4 -2
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +28 -1
- package/dest/tests/mocks.d.ts +1 -1
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +2 -2
- package/dest/tx/protocol_contracts.js +2 -2
- package/dest/tx/simulated_tx.d.ts +29 -154
- package/dest/tx/simulated_tx.d.ts.map +1 -1
- package/dest/tx/simulated_tx.js +3 -3
- package/dest/tx/tx_receipt.d.ts +8 -4
- package/dest/tx/tx_receipt.d.ts.map +1 -1
- package/dest/tx/tx_receipt.js +8 -15
- package/dest/vks/vk_data.js +1 -1
- package/package.json +10 -11
- package/src/abi/abi.ts +67 -14
- package/src/abi/selector.ts +1 -1
- package/src/avm/avm_accumulated_data.ts +6 -6
- package/src/avm/avm_circuit_public_inputs.ts +4 -4
- package/src/avm/revert_code.ts +25 -39
- package/src/block/l2_block_stream/interfaces.ts +6 -2
- package/src/config/index.ts +0 -1
- package/src/config/sequencer-config.ts +0 -3
- package/src/contract/contract_address.ts +3 -3
- package/src/contract/contract_class_id.ts +2 -2
- package/src/contract/index.ts +2 -0
- package/src/contract/interfaces/contract_class.ts +82 -2
- package/src/contract/private_function_membership_proof.ts +167 -0
- package/src/contract/utility_function_membership_proof.ts +118 -0
- package/src/file-store/factory.ts +4 -13
- package/src/file-store/http.ts +10 -29
- package/src/file-store/index.ts +0 -1
- package/src/gas/gas_settings.ts +65 -12
- package/src/interfaces/aztec-node-debug.ts +40 -0
- package/src/interfaces/client.ts +1 -0
- package/src/interfaces/l2_logs_source.ts +1 -4
- package/src/interfaces/validator.ts +36 -38
- package/src/kernel/claimed_length_array.ts +2 -2
- package/src/kernel/hints/private_kernel_reset_hints.ts +5 -2
- package/src/kernel/hints/read_request_hints.ts +3 -3
- package/src/kernel/padded_side_effects.ts +3 -3
- package/src/kernel/private_to_avm_accumulated_data.ts +4 -4
- package/src/kernel/private_to_public_accumulated_data.ts +10 -10
- package/src/kernel/private_to_rollup_accumulated_data.ts +5 -5
- package/src/logs/extended_directional_app_tagging_secret.ts +19 -8
- package/src/logs/private_log.ts +1 -1
- package/src/logs/public_log.ts +11 -1
- package/src/messaging/l1_to_l2_message_source.ts +1 -3
- package/src/p2p/block_proposal.ts +1 -1
- package/src/p2p/checkpoint_proposal.ts +1 -1
- package/src/parity/parity_base_private_inputs.ts +1 -1
- package/src/proofs/chonk_proof.ts +12 -90
- package/src/rollup/base_rollup_hints.ts +2 -2
- package/src/rollup/block_root_rollup_private_inputs.ts +8 -8
- package/src/rollup/checkpoint_rollup_public_inputs.ts +2 -2
- package/src/rollup/checkpoint_root_rollup_private_inputs.ts +4 -4
- package/src/rollup/root_rollup_public_inputs.ts +2 -2
- package/src/rollup/tree_snapshot_diff_hints.ts +5 -5
- package/src/tests/factories.ts +34 -1
- package/src/tests/mocks.ts +2 -2
- package/src/tx/protocol_contracts.ts +2 -2
- package/src/tx/simulated_tx.ts +6 -2
- package/src/tx/tx_receipt.ts +11 -14
- package/src/vks/vk_data.ts +1 -1
- package/dest/config/pipelining-config.d.ts +0 -19
- package/dest/config/pipelining-config.d.ts.map +0 -1
- package/dest/config/pipelining-config.js +0 -18
- package/dest/ha-signing/config.d.ts +0 -136
- package/dest/ha-signing/config.d.ts.map +0 -1
- package/dest/ha-signing/config.js +0 -97
- package/dest/ha-signing/index.d.ts +0 -4
- package/dest/ha-signing/index.d.ts.map +0 -1
- package/dest/ha-signing/index.js +0 -3
- package/dest/ha-signing/local_config.d.ts +0 -63
- package/dest/ha-signing/local_config.d.ts.map +0 -1
- package/dest/ha-signing/local_config.js +0 -24
- package/dest/ha-signing/types.d.ts +0 -85
- package/dest/ha-signing/types.d.ts.map +0 -1
- package/dest/ha-signing/types.js +0 -32
- package/dest/kv-store/config.d.ts +0 -17
- package/dest/kv-store/config.d.ts.map +0 -1
- package/dest/kv-store/config.js +0 -26
- package/dest/kv-store/index.d.ts +0 -2
- package/dest/kv-store/index.d.ts.map +0 -1
- package/dest/kv-store/index.js +0 -1
- package/src/config/pipelining-config.ts +0 -31
- package/src/ha-signing/config.ts +0 -156
- package/src/ha-signing/index.ts +0 -27
- package/src/ha-signing/local_config.ts +0 -46
- package/src/ha-signing/types.ts +0 -112
- package/src/kv-store/config.ts +0 -36
- package/src/kv-store/index.ts +0 -1
|
@@ -7,6 +7,29 @@ const PrivateFunctionSchema = zodFor()(z.object({
|
|
|
7
7
|
selector: FunctionSelector.schema,
|
|
8
8
|
vkHash: schemas.Fr
|
|
9
9
|
}));
|
|
10
|
+
const ExecutablePrivateFunctionSchema = zodFor()(PrivateFunctionSchema.and(z.object({
|
|
11
|
+
bytecode: schemas.Buffer
|
|
12
|
+
})));
|
|
13
|
+
const UtilityFunctionSchema = zodFor()(z.object({
|
|
14
|
+
selector: FunctionSelector.schema,
|
|
15
|
+
bytecode: schemas.Buffer
|
|
16
|
+
}));
|
|
17
|
+
const PrivateFunctionMembershipProofSchema = zodFor()(z.object({
|
|
18
|
+
artifactMetadataHash: schemas.Fr,
|
|
19
|
+
functionMetadataHash: schemas.Fr,
|
|
20
|
+
utilityFunctionsTreeRoot: schemas.Fr,
|
|
21
|
+
privateFunctionTreeSiblingPath: z.array(schemas.Fr),
|
|
22
|
+
privateFunctionTreeLeafIndex: schemas.Integer,
|
|
23
|
+
artifactTreeSiblingPath: z.array(schemas.Fr),
|
|
24
|
+
artifactTreeLeafIndex: schemas.Integer
|
|
25
|
+
}));
|
|
26
|
+
const UtilityFunctionMembershipProofSchema = zodFor()(z.object({
|
|
27
|
+
artifactMetadataHash: schemas.Fr,
|
|
28
|
+
functionMetadataHash: schemas.Fr,
|
|
29
|
+
privateFunctionsArtifactTreeRoot: schemas.Fr,
|
|
30
|
+
artifactTreeSiblingPath: z.array(schemas.Fr),
|
|
31
|
+
artifactTreeLeafIndex: schemas.Integer
|
|
32
|
+
}));
|
|
10
33
|
export const ContractClassSchema = zodFor()(z.object({
|
|
11
34
|
version: z.literal(VERSION),
|
|
12
35
|
artifactHash: schemas.Fr,
|
|
@@ -18,7 +41,9 @@ export const ContractClassWithIdSchema = zodFor()(ContractClassSchema.extend({
|
|
|
18
41
|
}));
|
|
19
42
|
export const ContractClassPublicSchema = zodFor()(z.object({
|
|
20
43
|
id: schemas.Fr,
|
|
21
|
-
privateFunctionsRoot: schemas.Fr
|
|
44
|
+
privateFunctionsRoot: schemas.Fr,
|
|
45
|
+
privateFunctions: z.array(ExecutablePrivateFunctionSchema.and(PrivateFunctionMembershipProofSchema)),
|
|
46
|
+
utilityFunctions: z.array(UtilityFunctionSchema.and(UtilityFunctionMembershipProofSchema))
|
|
22
47
|
}).and(ContractClassSchema.omit({
|
|
23
48
|
privateFunctions: true
|
|
24
49
|
})));
|
|
@@ -33,6 +58,8 @@ export const ContractClassPublicSchema = zodFor()(z.object({
|
|
|
33
58
|
version: 1,
|
|
34
59
|
artifactHash: Fr.fromPlainObject(obj.artifactHash),
|
|
35
60
|
privateFunctionsRoot: Fr.fromPlainObject(obj.privateFunctionsRoot),
|
|
61
|
+
privateFunctions: [],
|
|
62
|
+
utilityFunctions: [],
|
|
36
63
|
packedBytecode: obj.packedBytecode instanceof Buffer ? obj.packedBytecode : Buffer.from(obj.packedBytecode)
|
|
37
64
|
};
|
|
38
65
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ContractArtifact, FunctionSelector } from '../abi/index.js';
|
|
2
|
+
import type { ContractClassPublic, ExecutablePrivateFunctionWithMembershipProof, PrivateFunctionMembershipProof } from './interfaces/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a membership proof for a private function in a contract class, to be verified via `isValidPrivateFunctionMembershipProof`.
|
|
5
|
+
* @param selector - Selector of the function to create the proof for.
|
|
6
|
+
* @param artifact - Artifact of the contract class where the function is defined.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createPrivateFunctionMembershipProof(selector: FunctionSelector, artifact: ContractArtifact): Promise<PrivateFunctionMembershipProof>;
|
|
9
|
+
/**
|
|
10
|
+
* Verifies that a private function with a membership proof as emitted by the ClassRegistry contract is valid,
|
|
11
|
+
* as defined in the protocol specs at contract-deployment/classes:
|
|
12
|
+
*
|
|
13
|
+
* ```
|
|
14
|
+
* // Load contract class from local db
|
|
15
|
+
* contract_class = db.get_contract_class(contract_class_id)
|
|
16
|
+
*
|
|
17
|
+
* // Compute function leaf and assert it belongs to the private functions tree
|
|
18
|
+
* function_leaf = pedersen([selector as Field, vk_hash], GENERATOR__PRIVATE_FUNCTION_LEAF)
|
|
19
|
+
* computed_private_function_tree_root = compute_root(function_leaf, private_function_tree_sibling_path)
|
|
20
|
+
* assert computed_private_function_tree_root == contract_class.private_functions_root
|
|
21
|
+
*
|
|
22
|
+
* // Compute artifact leaf and assert it belongs to the artifact
|
|
23
|
+
* artifact_function_leaf = sha256(selector, metadata_hash, sha256(bytecode))
|
|
24
|
+
* computed_artifact_private_function_tree_root = compute_root(artifact_function_leaf, artifact_function_tree_sibling_path)
|
|
25
|
+
* computed_artifact_hash = sha256(computed_artifact_private_function_tree_root, utility_functions_artifact_tree_root, artifact_metadata_hash)
|
|
26
|
+
* assert computed_artifact_hash == contract_class.artifact_hash
|
|
27
|
+
* ```
|
|
28
|
+
* @param fn - Function to check membership proof for.
|
|
29
|
+
* @param contractClass - In which contract class the function is expected to be.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isValidPrivateFunctionMembershipProof(fn: ExecutablePrivateFunctionWithMembershipProof, contractClass: Pick<ContractClassPublic, 'privateFunctionsRoot' | 'artifactHash'>): Promise<boolean>;
|
|
32
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJpdmF0ZV9mdW5jdGlvbl9tZW1iZXJzaGlwX3Byb29mLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3QvcHJpdmF0ZV9mdW5jdGlvbl9tZW1iZXJzaGlwX3Byb29mLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUtBLE9BQU8sRUFBRSxLQUFLLGdCQUFnQixFQUFFLGdCQUFnQixFQUFnQixNQUFNLGlCQUFpQixDQUFDO0FBVXhGLE9BQU8sS0FBSyxFQUNWLG1CQUFtQixFQUNuQiw0Q0FBNEMsRUFDNUMsOEJBQThCLEVBQy9CLE1BQU0sdUJBQXVCLENBQUM7QUFHL0I7Ozs7R0FJRztBQUNILHdCQUFzQixvQ0FBb0MsQ0FDeEQsUUFBUSxFQUFFLGdCQUFnQixFQUMxQixRQUFRLEVBQUUsZ0JBQWdCLEdBQ3pCLE9BQU8sQ0FBQyw4QkFBOEIsQ0FBQyxDQTREekM7QUFFRDs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBcUJHO0FBQ0gsd0JBQXNCLHFDQUFxQyxDQUN6RCxFQUFFLEVBQUUsNENBQTRDLEVBQ2hELGFBQWEsRUFBRSxJQUFJLENBQUMsbUJBQW1CLEVBQUUsc0JBQXNCLEdBQUcsY0FBYyxDQUFDLG9CQWtEbEYifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private_function_membership_proof.d.ts","sourceRoot":"","sources":["../../src/contract/private_function_membership_proof.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAgB,MAAM,iBAAiB,CAAC;AAUxF,OAAO,KAAK,EACV,mBAAmB,EACnB,4CAA4C,EAC5C,8BAA8B,EAC/B,MAAM,uBAAuB,CAAC;AAG/B;;;;GAIG;AACH,wBAAsB,oCAAoC,CACxD,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,8BAA8B,CAAC,CA4DzC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,qCAAqC,CACzD,EAAE,EAAE,4CAA4C,EAChD,aAAa,EAAE,IAAI,CAAC,mBAAmB,EAAE,sBAAsB,GAAG,cAAc,CAAC,oBAkDlF"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { computeRootFromSiblingPath } from '@aztec/foundation/trees';
|
|
5
|
+
import { FunctionSelector, FunctionType } from '../abi/index.js';
|
|
6
|
+
import { computeArtifactFunctionTree, computeArtifactHash, computeArtifactHashPreimage, computeFunctionArtifactHash, computeFunctionMetadataHash, getArtifactMerkleTreeHasher } from './artifact_hash.js';
|
|
7
|
+
import { getContractClassPrivateFunctionFromArtifact } from './contract_class.js';
|
|
8
|
+
import { computePrivateFunctionLeaf, computePrivateFunctionsTree } from './private_function.js';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a membership proof for a private function in a contract class, to be verified via `isValidPrivateFunctionMembershipProof`.
|
|
11
|
+
* @param selector - Selector of the function to create the proof for.
|
|
12
|
+
* @param artifact - Artifact of the contract class where the function is defined.
|
|
13
|
+
*/ export async function createPrivateFunctionMembershipProof(selector, artifact) {
|
|
14
|
+
const log = createLogger('circuits:function_membership_proof');
|
|
15
|
+
// Locate private function definition and artifact
|
|
16
|
+
const privateFunctions = artifact.functions.filter((fn)=>fn.functionType === FunctionType.PRIVATE);
|
|
17
|
+
const privateFunctionsFromArtifact = await Promise.all(privateFunctions.map(getContractClassPrivateFunctionFromArtifact));
|
|
18
|
+
const privateFunction = privateFunctionsFromArtifact.find((fn)=>fn.selector.equals(selector));
|
|
19
|
+
const privateFunctionsAndSelectors = await Promise.all(privateFunctions.map(async (fn)=>({
|
|
20
|
+
fn,
|
|
21
|
+
selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters)
|
|
22
|
+
})));
|
|
23
|
+
const privateFunctionArtifact = privateFunctionsAndSelectors.find((fnAndSelector)=>selector.equals(fnAndSelector.selector))?.fn;
|
|
24
|
+
if (!privateFunction || !privateFunctionArtifact) {
|
|
25
|
+
throw new Error(`Private function with selector ${selector.toString()} not found`);
|
|
26
|
+
}
|
|
27
|
+
// Compute preimage for the artifact hash
|
|
28
|
+
const { utilityFunctionRoot: utilityFunctionsTreeRoot, metadataHash: artifactMetadataHash } = await computeArtifactHashPreimage(artifact);
|
|
29
|
+
// We need two sibling paths because private function information is split across two trees:
|
|
30
|
+
// The "private function tree" captures the selectors and verification keys, and is used in the kernel circuit for verifying the proof generated by the app circuit.
|
|
31
|
+
const functionLeaf = await computePrivateFunctionLeaf(privateFunction);
|
|
32
|
+
const functionsTree = await computePrivateFunctionsTree(privateFunctionsFromArtifact);
|
|
33
|
+
const functionsTreeLeafIndex = functionsTree.getIndex(functionLeaf);
|
|
34
|
+
const functionsTreeSiblingPath = functionsTree.getSiblingPath(functionsTreeLeafIndex).map(Fr.fromBuffer);
|
|
35
|
+
// And the "artifact tree" captures function bytecode and metadata, and is used by the pxe to check that its executing the code it's supposed to be executing, but it never goes into circuits.
|
|
36
|
+
const functionMetadataHash = computeFunctionMetadataHash(privateFunctionArtifact);
|
|
37
|
+
const functionArtifactHash = await computeFunctionArtifactHash({
|
|
38
|
+
...privateFunctionArtifact,
|
|
39
|
+
functionMetadataHash
|
|
40
|
+
});
|
|
41
|
+
const artifactTree = await computeArtifactFunctionTree(artifact, FunctionType.PRIVATE);
|
|
42
|
+
const artifactTreeLeafIndex = artifactTree.getIndex(functionArtifactHash.toBuffer());
|
|
43
|
+
const artifactTreeSiblingPath = artifactTree.getSiblingPath(artifactTreeLeafIndex).map(Fr.fromBuffer);
|
|
44
|
+
log.debug(`Computed proof for private function with selector ${selector.toString()}`, {
|
|
45
|
+
functionArtifactHash,
|
|
46
|
+
functionMetadataHash,
|
|
47
|
+
functionLeaf: '0x' + functionLeaf.toString('hex'),
|
|
48
|
+
artifactMetadataHash,
|
|
49
|
+
privateFunctionsTreeRoot: '0x' + functionsTree.root.toString('hex'),
|
|
50
|
+
utilityFunctionsTreeRoot,
|
|
51
|
+
artifactFunctionTreeSiblingPath: artifactTreeSiblingPath.map((fr)=>fr.toString()).join(','),
|
|
52
|
+
privateFunctionTreeSiblingPath: functionsTreeSiblingPath.map((fr)=>fr.toString()).join(',')
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
artifactTreeSiblingPath,
|
|
56
|
+
artifactTreeLeafIndex,
|
|
57
|
+
artifactMetadataHash,
|
|
58
|
+
functionMetadataHash,
|
|
59
|
+
utilityFunctionsTreeRoot,
|
|
60
|
+
privateFunctionTreeSiblingPath: functionsTreeSiblingPath,
|
|
61
|
+
privateFunctionTreeLeafIndex: functionsTreeLeafIndex
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Verifies that a private function with a membership proof as emitted by the ClassRegistry contract is valid,
|
|
66
|
+
* as defined in the protocol specs at contract-deployment/classes:
|
|
67
|
+
*
|
|
68
|
+
* ```
|
|
69
|
+
* // Load contract class from local db
|
|
70
|
+
* contract_class = db.get_contract_class(contract_class_id)
|
|
71
|
+
*
|
|
72
|
+
* // Compute function leaf and assert it belongs to the private functions tree
|
|
73
|
+
* function_leaf = pedersen([selector as Field, vk_hash], GENERATOR__PRIVATE_FUNCTION_LEAF)
|
|
74
|
+
* computed_private_function_tree_root = compute_root(function_leaf, private_function_tree_sibling_path)
|
|
75
|
+
* assert computed_private_function_tree_root == contract_class.private_functions_root
|
|
76
|
+
*
|
|
77
|
+
* // Compute artifact leaf and assert it belongs to the artifact
|
|
78
|
+
* artifact_function_leaf = sha256(selector, metadata_hash, sha256(bytecode))
|
|
79
|
+
* computed_artifact_private_function_tree_root = compute_root(artifact_function_leaf, artifact_function_tree_sibling_path)
|
|
80
|
+
* computed_artifact_hash = sha256(computed_artifact_private_function_tree_root, utility_functions_artifact_tree_root, artifact_metadata_hash)
|
|
81
|
+
* assert computed_artifact_hash == contract_class.artifact_hash
|
|
82
|
+
* ```
|
|
83
|
+
* @param fn - Function to check membership proof for.
|
|
84
|
+
* @param contractClass - In which contract class the function is expected to be.
|
|
85
|
+
*/ export async function isValidPrivateFunctionMembershipProof(fn, contractClass) {
|
|
86
|
+
const log = createLogger('circuits:function_membership_proof');
|
|
87
|
+
// Check private function tree membership
|
|
88
|
+
const functionLeaf = await computePrivateFunctionLeaf(fn);
|
|
89
|
+
const rootBuffer = await computeRootFromSiblingPath(functionLeaf, fn.privateFunctionTreeSiblingPath.map((fr)=>fr.toBuffer()), fn.privateFunctionTreeLeafIndex, async (left, right)=>(await poseidon2Hash([
|
|
90
|
+
left,
|
|
91
|
+
right
|
|
92
|
+
])).toBuffer());
|
|
93
|
+
const computedPrivateFunctionTreeRoot = Fr.fromBuffer(rootBuffer);
|
|
94
|
+
if (!contractClass.privateFunctionsRoot.equals(computedPrivateFunctionTreeRoot)) {
|
|
95
|
+
log.debug(`Private function tree root mismatch`, {
|
|
96
|
+
expectedPrivateFunctionTreeRoot: contractClass.privateFunctionsRoot,
|
|
97
|
+
computedPrivateFunctionTreeRoot: computedPrivateFunctionTreeRoot,
|
|
98
|
+
computedFunctionLeaf: '0x' + functionLeaf.toString('hex')
|
|
99
|
+
});
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
// Check artifact hash
|
|
103
|
+
const functionArtifactHash = await computeFunctionArtifactHash(fn);
|
|
104
|
+
const computedArtifactPrivateFunctionTreeRootBuffer = await computeRootFromSiblingPath(functionArtifactHash.toBuffer(), fn.artifactTreeSiblingPath.map((fr)=>fr.toBuffer()), fn.artifactTreeLeafIndex, getArtifactMerkleTreeHasher());
|
|
105
|
+
const computedArtifactPrivateFunctionTreeRoot = Fr.fromBuffer(computedArtifactPrivateFunctionTreeRootBuffer);
|
|
106
|
+
const computedArtifactHash = await computeArtifactHash({
|
|
107
|
+
privateFunctionRoot: computedArtifactPrivateFunctionTreeRoot,
|
|
108
|
+
utilityFunctionRoot: fn.utilityFunctionsTreeRoot,
|
|
109
|
+
metadataHash: fn.artifactMetadataHash
|
|
110
|
+
});
|
|
111
|
+
if (!contractClass.artifactHash.equals(computedArtifactHash)) {
|
|
112
|
+
log.debug(`Artifact hash mismatch`, {
|
|
113
|
+
expected: contractClass.artifactHash,
|
|
114
|
+
computedArtifactHash,
|
|
115
|
+
computedFunctionArtifactHash: functionArtifactHash,
|
|
116
|
+
computedArtifactPrivateFunctionTreeRoot,
|
|
117
|
+
utilityFunctionRoot: fn.utilityFunctionsTreeRoot,
|
|
118
|
+
metadataHash: fn.artifactMetadataHash,
|
|
119
|
+
artifactFunctionTreeSiblingPath: fn.artifactTreeSiblingPath.map((fr)=>fr.toString()).join(',')
|
|
120
|
+
});
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ContractArtifact, FunctionSelector } from '../abi/index.js';
|
|
2
|
+
import type { ContractClassPublic, UtilityFunctionMembershipProof, UtilityFunctionWithMembershipProof } from './interfaces/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a membership proof for a utility function in a contract class, to be verified via `isValidUtilityFunctionMembershipProof`.
|
|
5
|
+
* @param selector - Selector of the function to create the proof for.
|
|
6
|
+
* @param artifact - Artifact of the contract class where the function is defined.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createUtilityFunctionMembershipProof(selector: FunctionSelector, artifact: ContractArtifact): Promise<UtilityFunctionMembershipProof>;
|
|
9
|
+
/**
|
|
10
|
+
* Verifies that a utility function with a membership proof as emitted by the ClassRegistry contract is valid,
|
|
11
|
+
* as defined in the protocol specs at contract-deployment/classes:
|
|
12
|
+
*
|
|
13
|
+
* ```
|
|
14
|
+
* // Load contract class from local db
|
|
15
|
+
* contract_class = db.get_contract_class(contract_class_id)
|
|
16
|
+
*
|
|
17
|
+
* // Compute artifact leaf and assert it belongs to the artifact
|
|
18
|
+
* artifact_function_leaf = sha256(selector, metadata_hash, sha256(bytecode))
|
|
19
|
+
* computed_artifact_utility_function_tree_root = compute_root(artifact_function_leaf, artifact_function_tree_sibling_path, artifact_function_tree_leaf_index)
|
|
20
|
+
* computed_artifact_hash = sha256(private_functions_artifact_tree_root, computed_artifact_utility_function_tree_root, artifact_metadata_hash)
|
|
21
|
+
* assert computed_artifact_hash == contract_class.artifact_hash
|
|
22
|
+
* ```
|
|
23
|
+
* @param fn - Function to check membership proof for.
|
|
24
|
+
* @param contractClass - In which contract class the function is expected to be.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isValidUtilityFunctionMembershipProof(fn: UtilityFunctionWithMembershipProof, contractClass: Pick<ContractClassPublic, 'artifactHash'>): Promise<boolean>;
|
|
27
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbGl0eV9mdW5jdGlvbl9tZW1iZXJzaGlwX3Byb29mLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3QvdXRpbGl0eV9mdW5jdGlvbl9tZW1iZXJzaGlwX3Byb29mLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUlBLE9BQU8sRUFBRSxLQUFLLGdCQUFnQixFQUFFLGdCQUFnQixFQUFnQixNQUFNLGlCQUFpQixDQUFDO0FBU3hGLE9BQU8sS0FBSyxFQUNWLG1CQUFtQixFQUNuQiw4QkFBOEIsRUFDOUIsa0NBQWtDLEVBQ25DLE1BQU0sdUJBQXVCLENBQUM7QUFFL0I7Ozs7R0FJRztBQUNILHdCQUFzQixvQ0FBb0MsQ0FDeEQsUUFBUSxFQUFFLGdCQUFnQixFQUMxQixRQUFRLEVBQUUsZ0JBQWdCLEdBQ3pCLE9BQU8sQ0FBQyw4QkFBOEIsQ0FBQyxDQXNDekM7QUFFRDs7Ozs7Ozs7Ozs7Ozs7OztHQWdCRztBQUNILHdCQUFzQixxQ0FBcUMsQ0FDekQsRUFBRSxFQUFFLGtDQUFrQyxFQUN0QyxhQUFhLEVBQUUsSUFBSSxDQUFDLG1CQUFtQixFQUFFLGNBQWMsQ0FBQyxvQkErQnpEIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utility_function_membership_proof.d.ts","sourceRoot":"","sources":["../../src/contract/utility_function_membership_proof.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAgB,MAAM,iBAAiB,CAAC;AASxF,OAAO,KAAK,EACV,mBAAmB,EACnB,8BAA8B,EAC9B,kCAAkC,EACnC,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,wBAAsB,oCAAoC,CACxD,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,8BAA8B,CAAC,CAsCzC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,qCAAqC,CACzD,EAAE,EAAE,kCAAkC,EACtC,aAAa,EAAE,IAAI,CAAC,mBAAmB,EAAE,cAAc,CAAC,oBA+BzD"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { computeRootFromSiblingPath } from '@aztec/foundation/trees';
|
|
4
|
+
import { FunctionSelector, FunctionType } from '../abi/index.js';
|
|
5
|
+
import { computeArtifactFunctionTree, computeArtifactHash, computeArtifactHashPreimage, computeFunctionArtifactHash, computeFunctionMetadataHash, getArtifactMerkleTreeHasher } from './artifact_hash.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a membership proof for a utility function in a contract class, to be verified via `isValidUtilityFunctionMembershipProof`.
|
|
8
|
+
* @param selector - Selector of the function to create the proof for.
|
|
9
|
+
* @param artifact - Artifact of the contract class where the function is defined.
|
|
10
|
+
*/ export async function createUtilityFunctionMembershipProof(selector, artifact) {
|
|
11
|
+
const log = createLogger('circuits:function_membership_proof');
|
|
12
|
+
// Locate function artifact
|
|
13
|
+
const utilityFunctions = artifact.functions.filter((fn)=>fn.functionType === FunctionType.UTILITY);
|
|
14
|
+
const utilityFunctionsAndSelectors = await Promise.all(utilityFunctions.map(async (fn)=>({
|
|
15
|
+
fn,
|
|
16
|
+
selector: await FunctionSelector.fromNameAndParameters(fn)
|
|
17
|
+
})));
|
|
18
|
+
const fn = utilityFunctionsAndSelectors.find((fnAndSelector)=>selector.equals(fnAndSelector.selector))?.fn;
|
|
19
|
+
if (!fn) {
|
|
20
|
+
throw new Error(`Utility function with selector ${selector.toString()} not found`);
|
|
21
|
+
}
|
|
22
|
+
// Compute preimage for the artifact hash
|
|
23
|
+
const { privateFunctionRoot: privateFunctionsArtifactTreeRoot, metadataHash: artifactMetadataHash } = await computeArtifactHashPreimage(artifact);
|
|
24
|
+
// Compute the sibling path for the "artifact tree"
|
|
25
|
+
const functionMetadataHash = computeFunctionMetadataHash(fn);
|
|
26
|
+
const functionArtifactHash = await computeFunctionArtifactHash({
|
|
27
|
+
...fn,
|
|
28
|
+
functionMetadataHash
|
|
29
|
+
});
|
|
30
|
+
const artifactTree = await computeArtifactFunctionTree(artifact, FunctionType.UTILITY);
|
|
31
|
+
const artifactTreeLeafIndex = artifactTree.getIndex(functionArtifactHash.toBuffer());
|
|
32
|
+
const artifactTreeSiblingPath = artifactTree.getSiblingPath(artifactTreeLeafIndex).map(Fr.fromBuffer);
|
|
33
|
+
log.debug(`Computed proof for utility function with selector ${selector.toString()}`, {
|
|
34
|
+
functionArtifactHash,
|
|
35
|
+
functionMetadataHash,
|
|
36
|
+
artifactMetadataHash,
|
|
37
|
+
artifactFunctionTreeSiblingPath: artifactTreeSiblingPath.map((fr)=>fr.toString()).join(','),
|
|
38
|
+
privateFunctionsArtifactTreeRoot
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
artifactTreeSiblingPath,
|
|
42
|
+
artifactTreeLeafIndex,
|
|
43
|
+
artifactMetadataHash,
|
|
44
|
+
functionMetadataHash,
|
|
45
|
+
privateFunctionsArtifactTreeRoot
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Verifies that a utility function with a membership proof as emitted by the ClassRegistry contract is valid,
|
|
50
|
+
* as defined in the protocol specs at contract-deployment/classes:
|
|
51
|
+
*
|
|
52
|
+
* ```
|
|
53
|
+
* // Load contract class from local db
|
|
54
|
+
* contract_class = db.get_contract_class(contract_class_id)
|
|
55
|
+
*
|
|
56
|
+
* // Compute artifact leaf and assert it belongs to the artifact
|
|
57
|
+
* artifact_function_leaf = sha256(selector, metadata_hash, sha256(bytecode))
|
|
58
|
+
* computed_artifact_utility_function_tree_root = compute_root(artifact_function_leaf, artifact_function_tree_sibling_path, artifact_function_tree_leaf_index)
|
|
59
|
+
* computed_artifact_hash = sha256(private_functions_artifact_tree_root, computed_artifact_utility_function_tree_root, artifact_metadata_hash)
|
|
60
|
+
* assert computed_artifact_hash == contract_class.artifact_hash
|
|
61
|
+
* ```
|
|
62
|
+
* @param fn - Function to check membership proof for.
|
|
63
|
+
* @param contractClass - In which contract class the function is expected to be.
|
|
64
|
+
*/ export async function isValidUtilityFunctionMembershipProof(fn, contractClass) {
|
|
65
|
+
const log = createLogger('circuits:function_membership_proof');
|
|
66
|
+
const functionArtifactHash = await computeFunctionArtifactHash(fn);
|
|
67
|
+
const computedArtifactFunctionTreeRootBuffer = await computeRootFromSiblingPath(functionArtifactHash.toBuffer(), fn.artifactTreeSiblingPath.map((fr)=>fr.toBuffer()), fn.artifactTreeLeafIndex, getArtifactMerkleTreeHasher());
|
|
68
|
+
const computedArtifactFunctionTreeRoot = Fr.fromBuffer(computedArtifactFunctionTreeRootBuffer);
|
|
69
|
+
const computedArtifactHash = await computeArtifactHash({
|
|
70
|
+
privateFunctionRoot: fn.privateFunctionsArtifactTreeRoot,
|
|
71
|
+
utilityFunctionRoot: computedArtifactFunctionTreeRoot,
|
|
72
|
+
metadataHash: fn.artifactMetadataHash
|
|
73
|
+
});
|
|
74
|
+
if (!contractClass.artifactHash.equals(computedArtifactHash)) {
|
|
75
|
+
log.debug(`Artifact hash mismatch`, {
|
|
76
|
+
expected: contractClass.artifactHash,
|
|
77
|
+
computedArtifactHash,
|
|
78
|
+
computedFunctionArtifactHash: functionArtifactHash,
|
|
79
|
+
computedArtifactFunctionTreeRoot,
|
|
80
|
+
privateFunctionsArtifactTreeRoot: fn.privateFunctionsArtifactTreeRoot,
|
|
81
|
+
metadataHash: fn.artifactMetadataHash,
|
|
82
|
+
artifactFunctionTreeSiblingPath: fn.artifactTreeSiblingPath.map((fr)=>fr.toString()).join(',')
|
|
83
|
+
});
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type Logger } from '@aztec/foundation/log';
|
|
2
|
-
import { type HttpFileStoreOptions } from './http.js';
|
|
3
2
|
import type { FileStore, ReadOnlyFileStore } from './interface.js';
|
|
4
3
|
export declare function createFileStore(config: string, logger?: Logger): Promise<FileStore>;
|
|
5
4
|
export declare function createFileStore(config: undefined, logger?: Logger): Promise<undefined>;
|
|
6
|
-
export declare function createReadOnlyFileStore(config: string, logger?: Logger
|
|
7
|
-
export declare function createReadOnlyFileStore(config: undefined, logger?: Logger
|
|
8
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
5
|
+
export declare function createReadOnlyFileStore(config: string, logger?: Logger): Promise<ReadOnlyFileStore>;
|
|
6
|
+
export declare function createReadOnlyFileStore(config: undefined, logger?: Logger): Promise<undefined>;
|
|
7
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2ZpbGUtc3RvcmUvZmFjdG9yeS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFJbEUsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFXbkUsd0JBQXNCLGVBQWUsQ0FBQyxNQUFNLEVBQUUsTUFBTSxFQUFFLE1BQU0sQ0FBQyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7QUFDM0Ysd0JBQXNCLGVBQWUsQ0FBQyxNQUFNLEVBQUUsU0FBUyxFQUFFLE1BQU0sQ0FBQyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7QUE2QzlGLHdCQUFzQix1QkFBdUIsQ0FBQyxNQUFNLEVBQUUsTUFBTSxFQUFFLE1BQU0sQ0FBQyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsaUJBQWlCLENBQUMsQ0FBQztBQUMzRyx3QkFBc0IsdUJBQXVCLENBQUMsTUFBTSxFQUFFLFNBQVMsRUFBRSxNQUFNLENBQUMsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQUFDIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/file-store/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/file-store/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAIlE,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAWnE,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAC3F,wBAAsB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AA6C9F,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC3G,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -52,12 +52,12 @@ export async function createFileStore(config, logger = createLogger('stdlib:file
|
|
|
52
52
|
throw new Error(`Unknown file store config: '${config}'. Supported values are ${supportedExamples.join(', ')}.`);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
export async function createReadOnlyFileStore(config, logger = createLogger('stdlib:file-store')
|
|
55
|
+
export async function createReadOnlyFileStore(config, logger = createLogger('stdlib:file-store')) {
|
|
56
56
|
if (config === undefined) {
|
|
57
57
|
return undefined;
|
|
58
58
|
} else if (config.startsWith('http://') || config.startsWith('https://')) {
|
|
59
59
|
logger.info(`Creating read-only HTTP file store at ${config}`);
|
|
60
|
-
return new HttpFileStore(config, logger
|
|
60
|
+
return new HttpFileStore(config, logger);
|
|
61
61
|
} else {
|
|
62
62
|
return await createFileStore(config, logger);
|
|
63
63
|
}
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import { type Logger } from '@aztec/foundation/log';
|
|
2
2
|
import type { ReadOnlyFileStore } from './interface.js';
|
|
3
|
-
/** Options for configuring HttpFileStore behavior. */
|
|
4
|
-
export interface HttpFileStoreOptions {
|
|
5
|
-
/** Retry backoff intervals in seconds. Empty array disables retries. Default: [1, 1, 3]. */
|
|
6
|
-
retryBackoff?: number[];
|
|
7
|
-
/** Request timeout in milliseconds. Default: no timeout (axios default). */
|
|
8
|
-
timeoutMs?: number;
|
|
9
|
-
}
|
|
10
3
|
export declare class HttpFileStore implements ReadOnlyFileStore {
|
|
11
4
|
private readonly baseUrl;
|
|
12
5
|
private readonly log;
|
|
13
6
|
private readonly axiosInstance;
|
|
14
7
|
private readonly fetch;
|
|
15
|
-
constructor(baseUrl: string, log?: Logger
|
|
8
|
+
constructor(baseUrl: string, log?: Logger);
|
|
16
9
|
read(pathOrUrl: string): Promise<Buffer>;
|
|
17
10
|
download(pathOrUrl: string, destPath: string): Promise<void>;
|
|
18
11
|
exists(pathOrUrl: string): Promise<boolean>;
|
|
19
12
|
private getUrl;
|
|
20
13
|
}
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaHR0cC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2ZpbGUtc3RvcmUvaHR0cC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFVbEUsT0FBTyxLQUFLLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUV4RCxxQkFBYSxhQUFjLFlBQVcsaUJBQWlCO0lBS25ELE9BQU8sQ0FBQyxRQUFRLENBQUMsT0FBTztJQUN4QixPQUFPLENBQUMsUUFBUSxDQUFDLEdBQUc7SUFMdEIsT0FBTyxDQUFDLFFBQVEsQ0FBQyxhQUFhLENBQWdCO0lBQzlDLE9BQU8sQ0FBQyxRQUFRLENBQUMsS0FBSyxDQUErRDtJQUVyRixZQUNtQixPQUFPLEVBQUUsTUFBTSxFQUNmLEdBQUcsR0FBRSxNQUErQyxFQVl0RTtJQUVZLElBQUksQ0FBQyxTQUFTLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FRcEQ7SUFFWSxRQUFRLENBQUMsU0FBUyxFQUFFLE1BQU0sRUFBRSxRQUFRLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FZeEU7SUFFWSxNQUFNLENBQUMsU0FBUyxFQUFFLE1BQU0sR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBUXZEO0lBRUQsT0FBTyxDQUFDLE1BQU07Q0FHZiJ9
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/file-store/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAUlE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/file-store/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAUlE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,qBAAa,aAAc,YAAW,iBAAiB;IAKnD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG;IALtB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+D;IAErF,YACmB,OAAO,EAAE,MAAM,EACf,GAAG,GAAE,MAA+C,EAYtE;IAEY,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAQpD;IAEY,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAYxE;IAEY,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAQvD;IAED,OAAO,CAAC,MAAM;CAGf"}
|
package/dest/file-store/http.js
CHANGED
|
@@ -10,28 +10,17 @@ export class HttpFileStore {
|
|
|
10
10
|
log;
|
|
11
11
|
axiosInstance;
|
|
12
12
|
fetch;
|
|
13
|
-
constructor(baseUrl, log = createLogger('stdlib:http-file-store')
|
|
13
|
+
constructor(baseUrl, log = createLogger('stdlib:http-file-store')){
|
|
14
14
|
this.baseUrl = baseUrl;
|
|
15
15
|
this.log = log;
|
|
16
|
-
this.axiosInstance = axios.create(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
3
|
|
25
|
-
];
|
|
26
|
-
if (retryBackoff.length > 0) {
|
|
27
|
-
this.fetch = async (config)=>{
|
|
28
|
-
return await retry(()=>this.axiosInstance.request(config), `Fetching ${config.url}`, makeBackoff(retryBackoff), this.log, /*failSilently=*/ true);
|
|
29
|
-
};
|
|
30
|
-
} else {
|
|
31
|
-
this.fetch = async (config)=>{
|
|
32
|
-
return await this.axiosInstance.request(config);
|
|
33
|
-
};
|
|
34
|
-
}
|
|
16
|
+
this.axiosInstance = axios.create();
|
|
17
|
+
this.fetch = async (config)=>{
|
|
18
|
+
return await retry(()=>this.axiosInstance.request(config), `Fetching ${config.url}`, makeBackoff([
|
|
19
|
+
1,
|
|
20
|
+
1,
|
|
21
|
+
3
|
|
22
|
+
]), this.log, /*failSilently=*/ true);
|
|
23
|
+
};
|
|
35
24
|
}
|
|
36
25
|
async read(pathOrUrl) {
|
|
37
26
|
const url = this.getUrl(pathOrUrl);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export * from './interface.js';
|
|
2
2
|
export * from './factory.js';
|
|
3
|
-
|
|
4
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9maWxlLXN0b3JlL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsZ0JBQWdCLENBQUM7QUFDL0IsY0FBYyxjQUFjLENBQUM7QUFDN0IsT0FBTyxFQUFFLEtBQUssb0JBQW9CLEVBQUUsTUFBTSxXQUFXLENBQUMifQ==
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9maWxlLXN0b3JlL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsZ0JBQWdCLENBQUM7QUFDL0IsY0FBYyxjQUFjLENBQUMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file-store/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file-store/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
|
|
@@ -4,6 +4,16 @@ import type { FieldsOf } from '@aztec/foundation/types';
|
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { Gas } from './gas.js';
|
|
6
6
|
import { GasFees } from './gas_fees.js';
|
|
7
|
+
/** Approximate max DA gas limit. Arbitrary, assuming 4 blocks per checkpoint — users should use gas estimation. */
|
|
8
|
+
export declare const APPROXIMATE_MAX_DA_GAS_PER_BLOCK: number;
|
|
9
|
+
/** Fallback teardown L2 gas limit. Arbitrary — users should use gas estimation. */
|
|
10
|
+
export declare const FALLBACK_TEARDOWN_L2_GAS_LIMIT: number;
|
|
11
|
+
/** Fallback teardown DA gas limit. Arbitrary — users should use gas estimation. */
|
|
12
|
+
export declare const FALLBACK_TEARDOWN_DA_GAS_LIMIT: number;
|
|
13
|
+
export declare const GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT = 6540000;
|
|
14
|
+
export declare const GAS_ESTIMATION_L2_GAS_LIMIT: number;
|
|
15
|
+
export declare const GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT = 786432;
|
|
16
|
+
export declare const GAS_ESTIMATION_DA_GAS_LIMIT: number;
|
|
7
17
|
/** Gas usage and fees limits set by the transaction sender for different dimensions and phases. */
|
|
8
18
|
export declare class GasSettings {
|
|
9
19
|
readonly gasLimits: Gas;
|
|
@@ -124,8 +134,35 @@ export declare class GasSettings {
|
|
|
124
134
|
getFeeLimit(): Fr;
|
|
125
135
|
/** Zero-value gas settings. */
|
|
126
136
|
static empty(): GasSettings;
|
|
127
|
-
/**
|
|
128
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Fills in gas limits high enough for transactions to be included in most cases.
|
|
139
|
+
* gasLimits is set to the maximum the protocol allows; since teardown gas is reserved
|
|
140
|
+
* from gasLimits during private execution (see gas_meter.nr), the effective gas available
|
|
141
|
+
* for app logic will be gasLimits - teardownGasLimits - privateOverhead.
|
|
142
|
+
* The DA gas limit is set to an approximate max per block assuming 4 blocks per checkpoint,
|
|
143
|
+
* since using the maximum per checkpoint would cause nodes to reject transactions.
|
|
144
|
+
* These values won't work if:
|
|
145
|
+
* - Teardown consumes more than the arbitrarily assigned fallback limits
|
|
146
|
+
* - The rest of the transaction consumes more than the remaining gas after teardown
|
|
147
|
+
* - The DA gas limit is too low for the transaction, while still within the checkpoint limit
|
|
148
|
+
*/
|
|
149
|
+
static fallback(overrides: {
|
|
150
|
+
gasLimits?: Gas;
|
|
151
|
+
teardownGasLimits?: Gas;
|
|
152
|
+
maxFeesPerGas: GasFees;
|
|
153
|
+
maxPriorityFeesPerGas?: GasFees;
|
|
154
|
+
}): GasSettings;
|
|
155
|
+
/**
|
|
156
|
+
* Gas settings for simulation/estimation only.
|
|
157
|
+
* Since teardown gas is reserved upfront from gasLimits during private execution (see gas_meter.nr),
|
|
158
|
+
* the effective gas available for app logic is gasLimits - teardownGasLimits - privateOverhead.
|
|
159
|
+
* To ensure estimation never hits gas caps, we set both limits above what the protocol allows:
|
|
160
|
+
* teardown gets MAX_PROCESSABLE and gasLimits gets teardown + MAX_PROCESSABLE, so the full
|
|
161
|
+
* processable amount remains available for each phase independently. To be used in conjunction
|
|
162
|
+
* with skipTxValidation: true during public simulation, or the node would reject the transaction
|
|
163
|
+
* outright due to gas limits being above protocol max.
|
|
164
|
+
*/
|
|
165
|
+
static forEstimation(overrides: {
|
|
129
166
|
gasLimits?: Gas;
|
|
130
167
|
teardownGasLimits?: Gas;
|
|
131
168
|
maxFeesPerGas: GasFees;
|
|
@@ -139,4 +176,4 @@ export declare class GasSettings {
|
|
|
139
176
|
toFields(): Fr[];
|
|
140
177
|
static getFields(fields: FieldsOf<GasSettings>): readonly [Gas, Gas, GasFees, GasFees];
|
|
141
178
|
}
|
|
142
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
179
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2FzX3NldHRpbmdzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZ2FzL2dhc19zZXR0aW5ncy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDcEQsT0FBTyxFQUFFLFlBQVksRUFBRSxXQUFXLEVBQXdDLE1BQU0sNkJBQTZCLENBQUM7QUFDOUcsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFFeEQsT0FBTyxFQUFFLENBQUMsRUFBRSxNQUFNLEtBQUssQ0FBQztBQUV4QixPQUFPLEVBQUUsR0FBRyxFQUFpQixNQUFNLFVBQVUsQ0FBQztBQUM5QyxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBRXhDLHFIQUFtSDtBQUNuSCxlQUFPLE1BQU0sZ0NBQWdDLFFBQXdELENBQUM7QUFDdEcscUZBQW1GO0FBQ25GLGVBQU8sTUFBTSw4QkFBOEIsUUFBeUMsQ0FBQztBQUNyRixxRkFBbUY7QUFDbkYsZUFBTyxNQUFNLDhCQUE4QixRQUFtRCxDQUFDO0FBSy9GLGVBQU8sTUFBTSxvQ0FBb0MsVUFBeUIsQ0FBQztBQUMzRSxlQUFPLE1BQU0sMkJBQTJCLFFBQWdFLENBQUM7QUFDekcsZUFBTyxNQUFNLG9DQUFvQyxTQUF3QyxDQUFDO0FBQzFGLGVBQU8sTUFBTSwyQkFBMkIsUUFBK0UsQ0FBQztBQUd4SCxtR0FBbUc7QUFDbkcscUJBQWEsV0FBVzthQUVKLFNBQVMsRUFBRSxHQUFHO2FBQ2QsaUJBQWlCLEVBQUUsR0FBRzthQUN0QixhQUFhLEVBQUUsT0FBTzthQUN0QixxQkFBcUIsRUFBRSxPQUFPO0lBSmhELFlBQ2tCLFNBQVMsRUFBRSxHQUFHLEVBQ2QsaUJBQWlCLEVBQUUsR0FBRyxFQUN0QixhQUFhLEVBQUUsT0FBTyxFQUN0QixxQkFBcUIsRUFBRSxPQUFPLEVBQzVDO0lBR0osTUFBTSxLQUFLLE1BQU07Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O09BU2hCO0lBRUQsT0FBTyxJQUFJLE1BQU0sQ0FFaEI7SUFFRCxNQUFNLENBQUMsSUFBSSxDQUFDLElBQUksRUFBRTtRQUNoQixTQUFTLEVBQUUsUUFBUSxDQUFDLEdBQUcsQ0FBQyxDQUFDO1FBQ3pCLGlCQUFpQixFQUFFLFFBQVEsQ0FBQyxHQUFHLENBQUMsQ0FBQztRQUNqQyxhQUFhLEVBQUUsUUFBUSxDQUFDLE9BQU8sQ0FBQyxDQUFDO1FBQ2pDLHFCQUFxQixFQUFFLFFBQVEsQ0FBQyxPQUFPLENBQUMsQ0FBQztLQUMxQyxlQU9BO0lBRUQ7Ozs7OztPQU1HO0lBQ0gsTUFBTSxDQUFDLGVBQWUsQ0FBQyxHQUFHLEVBQUUsR0FBRyxHQUFHLFdBQVcsQ0FVNUM7SUFFRCxLQUFLLGdCQU9KO0lBRUQsbUZBQW1GO0lBQ25GLFdBQVcsT0FLVjtJQUVELCtCQUErQjtJQUMvQixNQUFNLENBQUMsS0FBSyxnQkFFWDtJQUVEOzs7Ozs7Ozs7OztPQVdHO0lBQ0gsTUFBTSxDQUFDLFFBQVEsQ0FBQyxTQUFTLEVBQUU7UUFDekIsU0FBUyxDQUFDLEVBQUUsR0FBRyxDQUFDO1FBQ2hCLGlCQUFpQixDQUFDLEVBQUUsR0FBRyxDQUFDO1FBQ3hCLGFBQWEsRUFBRSxPQUFPLENBQUM7UUFDdkIscUJBQXFCLENBQUMsRUFBRSxPQUFPLENBQUM7S0FDakMsZUFhQTtJQUVEOzs7Ozs7Ozs7T0FTRztJQUNILE1BQU0sQ0FBQyxhQUFhLENBQUMsU0FBUyxFQUFFO1FBQzlCLFNBQVMsQ0FBQyxFQUFFLEdBQUcsQ0FBQztRQUNoQixpQkFBaUIsQ0FBQyxFQUFFLEdBQUcsQ0FBQztRQUN4QixhQUFhLEVBQUUsT0FBTyxDQUFDO1FBQ3ZCLHFCQUFxQixDQUFDLEVBQUUsT0FBTyxDQUFDO0tBQ2pDLGVBYUE7SUFFRCxPQUFPLFlBT047SUFFRCxNQUFNLENBQUMsS0FBSyxFQUFFLFdBQVcsV0FPeEI7SUFFRCxNQUFNLENBQUMsVUFBVSxDQUFDLE1BQU0sRUFBRSxNQUFNLEdBQUcsWUFBWSxHQUFHLFdBQVcsQ0FRNUQ7SUFFRCxRQUFRLDRCQUVQO0lBRUQsTUFBTSxDQUFDLFVBQVUsQ0FBQyxNQUFNLEVBQUUsRUFBRSxFQUFFLEdBQUcsV0FBVyxHQUFHLFdBQVcsQ0FRekQ7SUFFRCxRQUFRLElBQUksRUFBRSxFQUFFLENBUWY7SUFFRCxNQUFNLENBQUMsU0FBUyxDQUFDLE1BQU0sRUFBRSxRQUFRLENBQUMsV0FBVyxDQUFDLHlDQUU3QztDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas_settings.d.ts","sourceRoot":"","sources":["../../src/gas/gas_settings.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gas_settings.d.ts","sourceRoot":"","sources":["../../src/gas/gas_settings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAwC,MAAM,6BAA6B,CAAC;AAC9G,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,GAAG,EAAiB,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,qHAAmH;AACnH,eAAO,MAAM,gCAAgC,QAAwD,CAAC;AACtG,qFAAmF;AACnF,eAAO,MAAM,8BAA8B,QAAyC,CAAC;AACrF,qFAAmF;AACnF,eAAO,MAAM,8BAA8B,QAAmD,CAAC;AAK/F,eAAO,MAAM,oCAAoC,UAAyB,CAAC;AAC3E,eAAO,MAAM,2BAA2B,QAAgE,CAAC;AACzG,eAAO,MAAM,oCAAoC,SAAwC,CAAC;AAC1F,eAAO,MAAM,2BAA2B,QAA+E,CAAC;AAGxH,mGAAmG;AACnG,qBAAa,WAAW;aAEJ,SAAS,EAAE,GAAG;aACd,iBAAiB,EAAE,GAAG;aACtB,aAAa,EAAE,OAAO;aACtB,qBAAqB,EAAE,OAAO;IAJhD,YACkB,SAAS,EAAE,GAAG,EACd,iBAAiB,EAAE,GAAG,EACtB,aAAa,EAAE,OAAO,EACtB,qBAAqB,EAAE,OAAO,EAC5C;IAGJ,MAAM,KAAK,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAShB;IAED,OAAO,IAAI,MAAM,CAEhB;IAED,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;QAChB,SAAS,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;QACzB,iBAAiB,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;QACjC,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QACjC,qBAAqB,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;KAC1C,eAOA;IAED;;;;;;OAMG;IACH,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,WAAW,CAU5C;IAED,KAAK,gBAOJ;IAED,mFAAmF;IACnF,WAAW,OAKV;IAED,+BAA+B;IAC/B,MAAM,CAAC,KAAK,gBAEX;IAED;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE;QACzB,SAAS,CAAC,EAAE,GAAG,CAAC;QAChB,iBAAiB,CAAC,EAAE,GAAG,CAAC;QACxB,aAAa,EAAE,OAAO,CAAC;QACvB,qBAAqB,CAAC,EAAE,OAAO,CAAC;KACjC,eAaA;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE;QAC9B,SAAS,CAAC,EAAE,GAAG,CAAC;QAChB,iBAAiB,CAAC,EAAE,GAAG,CAAC;QACxB,aAAa,EAAE,OAAO,CAAC;QACvB,qBAAqB,CAAC,EAAE,OAAO,CAAC;KACjC,eAaA;IAED,OAAO,YAON;IAED,MAAM,CAAC,KAAK,EAAE,WAAW,WAOxB;IAED,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,WAAW,CAQ5D;IAED,QAAQ,4BAEP;IAED,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,GAAG,WAAW,CAQzD;IAED,QAAQ,IAAI,EAAE,EAAE,CAQf;IAED,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,yCAE7C;CACF"}
|
package/dest/gas/gas_settings.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GAS_SETTINGS_LENGTH, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS } from '@aztec/constants';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { Gas, GasDimensions } from './gas.js';
|
|
6
6
|
import { GasFees } from './gas_fees.js';
|
|
7
|
+
/** Approximate max DA gas limit. Arbitrary, assuming 4 blocks per checkpoint — users should use gas estimation. */ export const APPROXIMATE_MAX_DA_GAS_PER_BLOCK = Math.floor(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT / 4);
|
|
8
|
+
/** Fallback teardown L2 gas limit. Arbitrary — users should use gas estimation. */ export const FALLBACK_TEARDOWN_L2_GAS_LIMIT = Math.floor(MAX_PROCESSABLE_L2_GAS / 8);
|
|
9
|
+
/** Fallback teardown DA gas limit. Arbitrary — users should use gas estimation. */ export const FALLBACK_TEARDOWN_DA_GAS_LIMIT = Math.floor(APPROXIMATE_MAX_DA_GAS_PER_BLOCK / 2);
|
|
10
|
+
// For gas estimation, we use intentionally high limits above what the network can process,
|
|
11
|
+
// so the simulation runs without hitting gas caps. Since teardown gas is counted towards total,
|
|
12
|
+
// the total estimation limit is teardown + max processable.
|
|
13
|
+
export const GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT = MAX_PROCESSABLE_L2_GAS;
|
|
14
|
+
export const GAS_ESTIMATION_L2_GAS_LIMIT = GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT + MAX_PROCESSABLE_L2_GAS;
|
|
15
|
+
export const GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT;
|
|
16
|
+
export const GAS_ESTIMATION_DA_GAS_LIMIT = GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT + MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT;
|
|
7
17
|
// docs:start:gas_settings_vars
|
|
8
18
|
/** Gas usage and fees limits set by the transaction sender for different dimensions and phases. */ export class GasSettings {
|
|
9
19
|
gasLimits;
|
|
@@ -52,15 +62,49 @@ import { GasFees } from './gas_fees.js';
|
|
|
52
62
|
/** Zero-value gas settings. */ static empty() {
|
|
53
63
|
return new GasSettings(Gas.empty(), Gas.empty(), GasFees.empty(), GasFees.empty());
|
|
54
64
|
}
|
|
55
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Fills in gas limits high enough for transactions to be included in most cases.
|
|
67
|
+
* gasLimits is set to the maximum the protocol allows; since teardown gas is reserved
|
|
68
|
+
* from gasLimits during private execution (see gas_meter.nr), the effective gas available
|
|
69
|
+
* for app logic will be gasLimits - teardownGasLimits - privateOverhead.
|
|
70
|
+
* The DA gas limit is set to an approximate max per block assuming 4 blocks per checkpoint,
|
|
71
|
+
* since using the maximum per checkpoint would cause nodes to reject transactions.
|
|
72
|
+
* These values won't work if:
|
|
73
|
+
* - Teardown consumes more than the arbitrarily assigned fallback limits
|
|
74
|
+
* - The rest of the transaction consumes more than the remaining gas after teardown
|
|
75
|
+
* - The DA gas limit is too low for the transaction, while still within the checkpoint limit
|
|
76
|
+
*/ static fallback(overrides) {
|
|
77
|
+
return GasSettings.from({
|
|
78
|
+
gasLimits: overrides.gasLimits ?? {
|
|
79
|
+
l2Gas: MAX_PROCESSABLE_L2_GAS,
|
|
80
|
+
daGas: APPROXIMATE_MAX_DA_GAS_PER_BLOCK
|
|
81
|
+
},
|
|
82
|
+
teardownGasLimits: overrides.teardownGasLimits ?? {
|
|
83
|
+
l2Gas: FALLBACK_TEARDOWN_L2_GAS_LIMIT,
|
|
84
|
+
daGas: FALLBACK_TEARDOWN_DA_GAS_LIMIT
|
|
85
|
+
},
|
|
86
|
+
maxFeesPerGas: overrides.maxFeesPerGas,
|
|
87
|
+
maxPriorityFeesPerGas: overrides.maxPriorityFeesPerGas ?? GasFees.empty()
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Gas settings for simulation/estimation only.
|
|
92
|
+
* Since teardown gas is reserved upfront from gasLimits during private execution (see gas_meter.nr),
|
|
93
|
+
* the effective gas available for app logic is gasLimits - teardownGasLimits - privateOverhead.
|
|
94
|
+
* To ensure estimation never hits gas caps, we set both limits above what the protocol allows:
|
|
95
|
+
* teardown gets MAX_PROCESSABLE and gasLimits gets teardown + MAX_PROCESSABLE, so the full
|
|
96
|
+
* processable amount remains available for each phase independently. To be used in conjunction
|
|
97
|
+
* with skipTxValidation: true during public simulation, or the node would reject the transaction
|
|
98
|
+
* outright due to gas limits being above protocol max.
|
|
99
|
+
*/ static forEstimation(overrides) {
|
|
56
100
|
return GasSettings.from({
|
|
57
101
|
gasLimits: overrides.gasLimits ?? {
|
|
58
|
-
l2Gas:
|
|
59
|
-
daGas:
|
|
102
|
+
l2Gas: GAS_ESTIMATION_L2_GAS_LIMIT,
|
|
103
|
+
daGas: GAS_ESTIMATION_DA_GAS_LIMIT
|
|
60
104
|
},
|
|
61
105
|
teardownGasLimits: overrides.teardownGasLimits ?? {
|
|
62
|
-
l2Gas:
|
|
63
|
-
daGas:
|
|
106
|
+
l2Gas: GAS_ESTIMATION_TEARDOWN_L2_GAS_LIMIT,
|
|
107
|
+
daGas: GAS_ESTIMATION_TEARDOWN_DA_GAS_LIMIT
|
|
64
108
|
},
|
|
65
109
|
maxFeesPerGas: overrides.maxFeesPerGas,
|
|
66
110
|
maxPriorityFeesPerGas: overrides.maxPriorityFeesPerGas ?? GasFees.empty()
|