Skip to content

Commit 3143b39

Browse files
committed
cast usize to u32
1 parent 5c85cf9 commit 3143b39

File tree

3 files changed

+10
-38
lines changed

3 files changed

+10
-38
lines changed
Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
import {Account, initThreadPool, ProgramManager, AleoKeyProvider, AleoKeyProviderParams} from "@provablehq/sdk";
1+
import {Account, initThreadPool, ProgramManager, AleoKeyProvider, OfflineKeyProvider, CREDITS_PROGRAM_KEYS} from "@provablehq/sdk";
22

33
await initThreadPool();
44

5-
const programName = "hello_hello.aleo"
65

7-
const hello_hello_program =`
8-
program ${programName};
96

10-
function hello:
11-
input r0 as u32.public;
12-
input r1 as u32.private;
13-
add r0 r1 into r2;
14-
output r2 as u32.private;`
15-
16-
async function localProgramExecution(program, programName, aleoFunction, inputs) {
7+
async function localProgramExecution() {
178
const programManager = new ProgramManager();
189

1910
// Create a temporary account for the execution of the program
@@ -22,38 +13,19 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
2213

2314
// Create a key provider in order to re-use the same key for each execution
2415
const keyProvider = new AleoKeyProvider();
16+
const offlineKeyProvider = new OfflineKeyProvider();
2517
keyProvider.useCache(true);
2618
programManager.setKeyProvider(keyProvider);
2719

28-
// Pre-synthesize the program keys and then cache them in memory using key provider
29-
const keyPair = await programManager.synthesizeKeys(hello_hello_program, aleoFunction, inputs);
30-
programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);
20+
const [transferPublicProver, transferPublicVerifier] =await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public);
21+
console.log(transferPublicVerifier.toString());
3122

3223
// Specify parameters for the key provider to use search for program keys. In particular specify the cache key
3324
// that was used to cache the keys in the previous step.
34-
const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${aleoFunction}`});
35-
36-
// Execute once using the key provider params defined above. This will use the cached proving keys and make
37-
// execution significantly faster.
38-
let executionResponse = await programManager.run(
39-
program,
40-
aleoFunction,
41-
inputs,
42-
true,
43-
undefined,
44-
keyProviderParams,
45-
);
46-
console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());
47-
48-
// Verify the execution using the verifying key that was generated earlier.
49-
if (programManager.verifyExecution(executionResponse, 9_000_000)) {
50-
console.log("hello_hello/hello execution verified!");
51-
} else {
52-
throw("Execution failed verification!");
53-
}
25+
5426
}
5527

5628
const start = Date.now();
5729
console.log("Starting execute!");
58-
await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
30+
await localProgramExecution();
5931
console.log("Execute finished!", Date.now() - start);

sdk/tests/wasm.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ describe('WASM Objects', () => {
490490
it('can get the number of constraints', () => {
491491
const transferPublicVerifier = VerifyingKey.fromString(TRANSFER_PUBLIC_VERIFYING_KEY);
492492
const numConstraints = transferPublicVerifier.numConstraints();
493-
expect(numConstraints).equal(12326);
493+
expect(numConstraints).to.equal(12326);
494494
});
495495
});
496496
});

wasm/src/programs/verifying_key/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ impl VerifyingKey {
8888
///
8989
/// @returns {number} The number of constraints
9090
#[wasm_bindgen(js_name = "numConstraints")]
91-
pub fn num_constraints(&self) -> usize {
92-
self.0.circuit_info.num_constraints
91+
pub fn num_constraints(&self) -> u32 {
92+
self.0.circuit_info.num_constraints as u32
9393
}
9494
}
9595

0 commit comments

Comments
 (0)