Skip to content

Commit

Permalink
Merge pull request #1634 from rpanic/feature/sideloaded-keys-smartcon…
Browse files Browse the repository at this point in the history
…tract-fix

Fixed bug when using sideloaded keys in SmartContracts
  • Loading branch information
mitschabaude committed May 6, 2024
2 parents 1ed4125 + c325b99 commit 4578b7d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export { state, State, declareState } from './lib/mina/state.js';

export type { JsonProof } from './lib/proof-system/zkprogram.js';
export {
type ProofBase,
Proof,
DynamicProof,
SelfProof,
Expand Down
17 changes: 16 additions & 1 deletion src/lib/proof-system/sideloaded.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Void,
ZkProgram,
} from './zkprogram.js';
import { Field, Struct } from '../../index.js';
import { Field, SmartContract, Struct, method } from '../../index.js';
import { it, describe, before } from 'node:test';
import { expect } from 'expect';

Expand Down Expand Up @@ -124,6 +124,17 @@ const sideloadedProgram2 = ZkProgram({
},
});

export class SideloadedSmartContract extends SmartContract {
@method async setValue(
value: Field,
proof: SampleSideloadedProof,
vk: VerificationKey
) {
proof.verify(vk);
proof.publicInput.assertEquals(value);
}
}

describe('sideloaded', async () => {
let program1Vk = (await program1.compile()).verificationKey;
let program2Vk = (await program2.compile()).verificationKey;
Expand Down Expand Up @@ -211,4 +222,8 @@ describe('sideloaded', async () => {

expect(tag1).not.toStrictEqual(tag2);
});

it('should compile with SmartContracts', async () => {
await SideloadedSmartContract.compile();
});
});
1 change: 1 addition & 0 deletions src/lib/proof-system/zkprogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { prefixes } from '../../bindings/crypto/constants.js';

// public API
export {
ProofBase,
Proof,
DynamicProof,
SelfProof,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/provable/types/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
IsPure,
} from './provable-derivers.js';
import { Provable } from '../provable.js';
import { Proof } from '../../proof-system/zkprogram.js';
import { DynamicProof, Proof } from '../../proof-system/zkprogram.js';
import { ProvablePure } from './provable-intf.js';
import { From, InferValue } from '../../../bindings/lib/provable-generic.js';

Expand Down Expand Up @@ -310,7 +310,7 @@ function cloneCircuitValue<T>(obj: T): T {
if (isPrimitive(obj)) {
return obj;
}
if (obj instanceof Proof) {
if (obj instanceof Proof || obj instanceof DynamicProof) {
return obj;
}

Expand Down

0 comments on commit 4578b7d

Please sign in to comment.