Skip to content

Commit 8ce5a50

Browse files
Merge pull request #1079 from ProvableHQ/rr-return-num-constraints-for-vk
[Feature] Return number of constraints for VerifyingKey
2 parents 732b5ad + 19072fc commit 8ce5a50

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

docs/api_reference/sdk-src_network-client.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,20 @@ __*return*__ | `Promise.<string>` | *The solution id of the submitted solution o
10171017
10181018
---
10191019
1020+
### `submitProvingRequest(provingRequest, url) ► Promise.<ProvingResponse>`
1021+
1022+
![modifier: public](images/badges/modifier-public.svg)
1023+
1024+
Submit a &#x60;ProvingRequest&#x60; to a remote proving service for delegated proving. If the broadcast flag of the &#x60;ProvingRequest&#x60; is set to &#x60;true&#x60; the remote service will attempt to broadcast the result &#x60;Transaction&#x60; on behalf of the requestor.
1025+
1026+
Parameters | Type | Description
1027+
--- | --- | ---
1028+
__provingRequest__ | [ProvingRequest](sdk-src_wasm.md) | *The &#x60;ProvingRequest&#x60; (generated by the ProgramManager) to submit.*
1029+
__url__ | `string` | *(Optional) The url of the proving service.*
1030+
__*return*__ | `Promise.<ProvingResponse>` | *The ProvingResponse containing the transaction result and the result of the broadcast if the &#x60;broadcast&#x60; flag was set to &#x60;true&#x60;.*
1031+
1032+
---
1033+
10201034
### `waitForTransactionConfirmation(transactionId, checkInterval, timeout) ► Promise.<Transaction>`
10211035
10221036
![modifier: public](images/badges/modifier-public.svg)
@@ -2053,6 +2067,20 @@ __*return*__ | `Promise.<string>` | *The solution id of the submitted solution o
20532067
20542068
---
20552069
2070+
### `submitProvingRequest(provingRequest, url) ► Promise.<ProvingResponse>`
2071+
2072+
![modifier: public](images/badges/modifier-public.svg)
2073+
2074+
Submit a &#x60;ProvingRequest&#x60; to a remote proving service for delegated proving. If the broadcast flag of the &#x60;ProvingRequest&#x60; is set to &#x60;true&#x60; the remote service will attempt to broadcast the result &#x60;Transaction&#x60; on behalf of the requestor.
2075+
2076+
Parameters | Type | Description
2077+
--- | --- | ---
2078+
__provingRequest__ | [ProvingRequest](sdk-src_wasm.md) | *The &#x60;ProvingRequest&#x60; (generated by the ProgramManager) to submit.*
2079+
__url__ | `string` | *(Optional) The url of the proving service.*
2080+
__*return*__ | `Promise.<ProvingResponse>` | *The ProvingResponse containing the transaction result and the result of the broadcast if the &#x60;broadcast&#x60; flag was set to &#x60;true&#x60;.*
2081+
2082+
---
2083+
20562084
### `waitForTransactionConfirmation(transactionId, checkInterval, timeout) ► Promise.<Transaction>`
20572085
20582086
![modifier: public](images/badges/modifier-public.svg)

docs/api_reference/sdk-src_wasm.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3277,6 +3277,18 @@ __*return*__ | [Plaintext](sdk-src_wasm.md) | **
32773277
32783278
---
32793279
3280+
### `toField() ► Field`
3281+
3282+
![modifier: public](images/badges/modifier-public.svg)
3283+
3284+
Cast the scalar element to a field element.
3285+
3286+
Parameters | Type | Description
3287+
--- | --- | ---
3288+
__*return*__ | [Field](sdk-src_wasm.md) | **
3289+
3290+
---
3291+
32803292
### `clone() ► Scalar`
32813293
32823294
![modifier: public](images/badges/modifier-public.svg)
@@ -4330,3 +4342,15 @@ Parameters | Type | Description
43304342
__*return*__ | `String` | *String representation of the verifying key*
43314343
43324344
---
4345+
4346+
### `numConstraints() ► number`
4347+
4348+
![modifier: public](images/badges/modifier-public.svg)
4349+
4350+
Get the number of constraints associated with the circuit
4351+
4352+
Parameters | Type | Description
4353+
--- | --- | ---
4354+
__*return*__ | `number` | *The number of constraints*
4355+
4356+
---

sdk/tests/wasm.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from "chai";
2-
import { Address, AleoNetworkClient, Field, PrivateKey, ViewKey, Signature, RecordCiphertext, RecordPlaintext, PrivateKeyCiphertext, EncryptionToolkit, Transition } from "../src/node.js";
2+
import { Address, AleoNetworkClient, CREDITS_PROGRAM_KEYS, Field, FunctionKeyPair, PrivateKey, ViewKey, Signature, RecordCiphertext, RecordPlaintext, PrivateKeyCiphertext, EncryptionToolkit, Transition, VerifyingKey, AleoKeyProvider} from "../src/node.js";
33
import {
44
seed,
55
message,
@@ -21,7 +21,6 @@ import {
2121
VIEW_KEY_STRING,
2222
} from "./data/records.js";
2323

24-
2524
describe('WASM Objects', () => {
2625
describe('Address', () => {
2726
it('can be constructed from a private key', () => {
@@ -485,4 +484,13 @@ describe('WASM Objects', () => {
485484
expect(decryptedRecords[0].toString()).equal(recordPlaintextCopy.toString());
486485
});
487486
});
488-
});
487+
describe('VerifyingKey', () => {
488+
it('can get the number of constraints', async () => {
489+
const keyProvider = new AleoKeyProvider();
490+
const [transferPublicProver, transferPublicVerifier] = <FunctionKeyPair>await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public);
491+
const numConstraints = transferPublicVerifier.numConstraints();
492+
expect(numConstraints).to.equal(12326);
493+
});
494+
});
495+
});
496+

wasm/src/programs/verifying_key/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ impl VerifyingKey {
8383
pub fn to_string(&self) -> String {
8484
self.0.to_string()
8585
}
86+
87+
/// Get the number of constraints associated with the circuit
88+
///
89+
/// @returns {number} The number of constraints
90+
#[wasm_bindgen(js_name = "numConstraints")]
91+
pub fn num_constraints(&self) -> u32 {
92+
self.0.circuit_info.num_constraints as u32
93+
}
8694
}
8795

8896
impl Deref for VerifyingKey {
@@ -238,4 +246,13 @@ mod tests {
238246

239247
assert_eq!(transfer_public_verifying_key_checksum, checksum);
240248
}
249+
250+
#[wasm_bindgen_test]
251+
async fn test_num_constraints() {
252+
let transfer_public_verifier_bytes =
253+
crate::types::native::parameters::TransferPublicVerifier::load_bytes().unwrap();
254+
let transfer_public_verifier = VerifyingKey::from_bytes(&transfer_public_verifier_bytes).unwrap();
255+
let num_constraints = transfer_public_verifier.num_constraints();
256+
assert_eq!(num_constraints, 12326);
257+
}
241258
}

0 commit comments

Comments
 (0)