Skip to content

Commit b22591f

Browse files
Update SnarkVM to working rev 3e94245569ab77724ebde670d7d2685f040e42b8, add tests to REST methods + snapshot query, and fix snapshot query
1 parent de99340 commit b22591f

File tree

10 files changed

+230
-95
lines changed

10 files changed

+230
-95
lines changed

create-leo-app/template-node/index.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import {Account, initThreadPool, ProgramManager, AleoKeyProvider, AleoKeyProviderParams} from "@provablehq/sdk";
1+
import {Account, AleoKeyProvider, AleoKeyProviderParams, initThreadPool, ProgramManager, PrivateKey} from "@provablehq/sdk";
2+
3+
import * as process from "node:process";
24

35
await initThreadPool();
46

@@ -13,7 +15,7 @@ function hello:
1315
add r0 r1 into r2;
1416
output r2 as u32.private;`
1517

16-
async function localProgramExecution(program, programName, aleoFunction, inputs) {
18+
async function localProgramExecution(program, programName, functionName, inputs) {
1719
const programManager = new ProgramManager();
1820

1921
// Create a temporary account for the execution of the program
@@ -25,19 +27,21 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
2527
keyProvider.useCache(true);
2628
programManager.setKeyProvider(keyProvider);
2729

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);
30+
// Pre-synthesize the program keys and then cache them in memory using key provider.
31+
console.log("Synthesizing hello_hello/hello keys");
32+
const keyPair = await programManager.synthesizeKeys(hello_hello_program, functionName, inputs);
33+
programManager.keyProvider.cacheKeys(`${programName}:${functionName}`, keyPair);
3134

3235
// Specify parameters for the key provider to use search for program keys. In particular specify the cache key
3336
// that was used to cache the keys in the previous step.
34-
const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${aleoFunction}`});
37+
const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${functionName}`});
3538

3639
// Execute once using the key provider params defined above. This will use the cached proving keys and make
3740
// execution significantly faster.
41+
console.log("Executing hello_hello/hello");
3842
let executionResponse = await programManager.run(
3943
program,
40-
aleoFunction,
44+
functionName,
4145
inputs,
4246
true,
4347
undefined,
@@ -53,7 +57,33 @@ async function localProgramExecution(program, programName, aleoFunction, inputs)
5357
}
5458
}
5559

60+
// Create a remote program execution transaction.
61+
async function remoteProgramExecution(programName, functionName, inputs) {
62+
// Create a key provider in order to re-use the same key for each execution
63+
const keyProvider = new AleoKeyProvider();
64+
keyProvider.useCache(true);
65+
66+
const programManager = new ProgramManager("http://34.168.156.3:3030", keyProvider);
67+
68+
const tx = await programManager.buildExecutionTransaction(
69+
{
70+
programName,
71+
functionName,
72+
priorityFee: 0,
73+
privateFee: false,
74+
inputs,
75+
privateKey: PrivateKey.from_string(process.env["PUZZLE_PK"])
76+
}
77+
);
78+
console.log("Resulting transaction")
79+
}
80+
5681
const start = Date.now();
57-
console.log("Starting execute!");
58-
await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
59-
console.log("Execute finished!", Date.now() - start);
82+
// console.log("Starting local execute!");
83+
// await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
84+
// console.log("Local execute finished!", Date.now() - start);
85+
86+
console.log("Starting remote execute");
87+
const auctionTicket = "{\n owner: aleo12a4wll9ax6w5355jph0dr5wt2vla5sss2t4cnch0tc3vzh643v8qcfvc7a.private,\n auction: {\n starting_bid: 1000u64.private,\n name: 35399035103896773146887283777field.private,\n item: {\n id: 2711777270856651361584090827715149911900945757872672230578290769243507539617field.private,\n offchain_data: [\n 988474637487226873250021955104421895943605632761729320744454284792013483886field.private,\n 1018595503607749325560812785092303652308909717269501712857428145700763090203field.private,\n 1866354748676879328546224733327549476838379876255164483333908854380501015560field.private,\n 17649382157field.private\n ]\n }\n },\n auction_id: 4494702806735512695876583707511065751304542460719196393147692059573188109243field.private,\n settings: {\n auction_privacy: 1field.private,\n bid_types_accepted: 2field.private\n },\n _nonce: 3369967065799891136255379173673996324404175734426175774361522329924029135340group.public,\n _version: 0u8.public\n}";
88+
const privateBid = "{\n owner: aleo12a4wll9ax6w5355jph0dr5wt2vla5sss2t4cnch0tc3vzh643v8qcfvc7a.private,\n bid: {\n amount: 50000u64.private,\n auction_id: 4494702806735512695876583707511065751304542460719196393147692059573188109243field.private,\n bid_public_key: 7957235921075215080384898776027711008106448988910535634014947882222019778701group.private\n },\n bid_id: 7560059211950188901208146469854635725646381155467709838136796808753178551929field.private,\n _nonce: 6603986437928263590097393830337419611438422585243442121397081002092267314422group.public,\n _version: 0u8.public\n}";
89+
await remoteProgramExecution("private_auction_test_3.aleo", "select_winner_private", [auctionTicket, privateBid]);

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "nightly-2025-07-20"
2+
channel = "nightly-2025-08-28"
33
components = [ "rust-std", "rust-src" ]
44
targets = [ "wasm32-unknown-unknown" ]

sdk/src/program-manager.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ class ProgramManager {
519519
): Promise<Transaction> {
520520
// Destructure the options object to access the parameters
521521
const {
522-
programName,
523522
functionName,
524523
priorityFee,
525524
privateFee,
@@ -534,6 +533,7 @@ class ProgramManager {
534533
let provingKey = options.provingKey;
535534
let verifyingKey = options.verifyingKey;
536535
let program = options.program;
536+
let programName = options.programName;
537537
let imports = options.imports;
538538
let edition = options.edition;
539539

@@ -552,8 +552,14 @@ class ProgramManager {
552552
program = program.toString();
553553
}
554554

555+
// Get the program name if it is not provided in the parameters.
556+
if (programName === undefined) {
557+
programName = Program.fromString(program).id();
558+
}
559+
555560
if (edition == undefined) {
556561
try {
562+
557563
edition = await this.networkClient.getLatestProgramEdition(programName);
558564
} catch (e: any) {
559565
console.warn(`Error finding edition for ${programName}. Network response: '${e.message}'. Assuming edition 1.`);
@@ -684,13 +690,13 @@ class ProgramManager {
684690
): Promise<Authorization> {
685691
// Destructure the options object to access the parameters.
686692
const {
687-
programName,
688693
functionName,
689694
inputs,
690695
} = options;
691696

692697
const privateKey = options.privateKey;
693698
let program = options.programSource;
699+
let programName = options.programName;
694700
let imports = options.programImports;
695701
let edition = options.edition;
696702

@@ -709,6 +715,11 @@ class ProgramManager {
709715
program = program.toString();
710716
}
711717

718+
// Get the program name if it is not provided in the parameters.
719+
if (programName === undefined) {
720+
programName = Program.fromString(program).id();
721+
}
722+
712723
// Get the private key from the account if it is not provided in the parameters.
713724
let executionPrivateKey = privateKey;
714725
if (
@@ -789,13 +800,13 @@ class ProgramManager {
789800
): Promise<Authorization> {
790801
// Destructure the options object to access the parameters.
791802
const {
792-
programName,
793803
functionName,
794804
inputs,
795805
} = options;
796806

797807
const privateKey = options.privateKey;
798808
let program = options.programSource;
809+
let programName = options.programName;
799810
let imports = options.programImports;
800811
let edition = options.edition;
801812

@@ -814,6 +825,11 @@ class ProgramManager {
814825
program = program.toString();
815826
}
816827

828+
// Get the program name if it is not provided in the parameters.
829+
if (programName === undefined) {
830+
programName = Program.fromString(program).id();
831+
}
832+
817833
// Get the private key from the account if it is not provided in the parameters.
818834
let executionPrivateKey = privateKey;
819835
if (
@@ -898,7 +914,6 @@ class ProgramManager {
898914
): Promise<ProvingRequest> {
899915
// Destructure the options object to access the parameters.
900916
const {
901-
programName,
902917
functionName,
903918
baseFee,
904919
priorityFee,
@@ -911,6 +926,7 @@ class ProgramManager {
911926

912927
const privateKey = options.privateKey;
913928
let program = options.programSource;
929+
let programName = options.programName;
914930
let feeRecord = options.feeRecord;
915931
let imports = options.programImports;
916932
let edition = options.edition;
@@ -930,6 +946,11 @@ class ProgramManager {
930946
program = program.toString();
931947
}
932948

949+
// Get the program name if it is not provided in the parameters.
950+
if (programName === undefined) {
951+
programName = Program.fromString(program).id();
952+
}
953+
933954
if (edition == undefined) {
934955
try {
935956
edition = await this.networkClient.getLatestProgramEdition(programName);

sdk/tests/program-manager.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('Program Manager', async () => {
6868
it.skip('Program manager should execute offline and verify the resulting proof correctly', async () => {
6969
const execution_result = <ExecutionResponse>await programManager.run(helloProgram, "hello", ["5u32", "5u32"], true, undefined, undefined, undefined, undefined, undefined, undefined)
7070
expect(execution_result.getOutputs()[0]).equal("10u32");
71-
programManager.verifyExecution(execution_result, 9_000_000);
71+
programManager.verifyExecution(execution_result, 10_300_000);
7272
});
7373
});
7474

@@ -102,7 +102,7 @@ describe('Program Manager', async () => {
102102

103103
describe('Offline query', () => {
104104
it.skip('The offline query should work as expected', async () => {
105-
const offlineQuery = new OfflineQuery(1, stateRootv0);
105+
const offlineQuery = new OfflineQuery(10_300_000, stateRootv0);
106106
const record_plaintext = RecordPlaintext.fromString(statePathRecordv0);
107107
const pk = PrivateKey.from_string("APrivateKey1zkpAZAjaJJvPS7EJ7zvk5fb3QcZDCDxMSHSN5ap7ep4FAD7");
108108
const vk = ViewKey.from_private_key(pk);
@@ -112,7 +112,7 @@ describe('Program Manager', async () => {
112112
const credits = <string>await programManager.networkClient.getProgram("credits.aleo");
113113

114114
const execution_result = <ExecutionResponse>await programManager.run(credits, "transfer_private", [statePathRecordv0, beaconAddressString, "5u64"], true, undefined, undefined, undefined, undefined, undefined, offlineQuery);
115-
const verified = programManager.verifyExecution(execution_result, 9_000_000);
115+
const verified = programManager.verifyExecution(execution_result, 10_300_000);
116116
expect(verified).equal(true);
117117
});
118118
});

0 commit comments

Comments
 (0)