Skip to content

Commit

Permalink
Merge pull request #1467 from o1-labs/feature/diverse-vk-regression-test
Browse files Browse the repository at this point in the history
Diverse vk regression test
  • Loading branch information
mitschabaude authored Mar 5, 2024
2 parents ccba6ed + f5b8693 commit fcf3080
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 7 deletions.
1 change: 1 addition & 0 deletions run-ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ case $TEST_TYPE in
./run src/examples/zkapps/reducer/reducer-composite.ts --bundle
./run src/examples/zkapps/composability.ts --bundle
./run src/tests/fake-proof.ts
./run tests/vk-regression/diverse-zk-program-run.ts --bundle
;;

"Voting integration tests")
Expand Down
14 changes: 7 additions & 7 deletions src/tests/transaction-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ await testLocalAndRemote(async () => {
console.log('');

console.log(
"Test calling successful 'update' method does not throw with throwOnFail is false"
"Test calling successful 'update' method does not throw with throwOnFail is true"
);
await testLocalAndRemote(async () => {
await assert.doesNotReject(async () => {
Expand All @@ -199,15 +199,18 @@ await testLocalAndRemote(async () => {
}
);
transaction.sign([senderKey, zkAppKey]);
const includedTransaction = await sendAndVerifyTransaction(transaction);
const includedTransaction = await sendAndVerifyTransaction(
transaction,
true
);
assert(includedTransaction.status === 'included');
await Mina.fetchEvents(zkAppAddress, TokenId.default);
});
});
console.log('');

console.log(
"Test calling successful 'update' method does not throw with throwOnFail is true"
"Test calling successful 'update' method does not throw with throwOnFail is false"
);
await testLocalAndRemote(async () => {
await assert.doesNotReject(async () => {
Expand All @@ -218,10 +221,7 @@ await testLocalAndRemote(async () => {
}
);
transaction.sign([senderKey, zkAppKey]);
const includedTransaction = await sendAndVerifyTransaction(
transaction,
true
);
const includedTransaction = await sendAndVerifyTransaction(transaction);
assert(includedTransaction.status === 'included');
await Mina.fetchEvents(zkAppAddress, TokenId.default);
});
Expand Down
11 changes: 11 additions & 0 deletions tests/vk-regression/diverse-zk-program-run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import assert from 'node:assert';
import { diverse, Bytes128 } from './diverse-zk-program.js';

console.log('testing proof generation for diverse program');
await diverse.compile();

let proof1 = await diverse.sha3(Bytes128.fromString('hello'));
assert(await diverse.verify(proof1), 'verifies');

let proof2 = await diverse.recursive(proof1);
assert(await diverse.verify(proof2), 'verifies');
97 changes: 97 additions & 0 deletions tests/vk-regression/diverse-zk-program.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import {
ZkProgram,
Crypto,
createEcdsa,
createForeignCurve,
Bytes,
assert,
Provable,
Field,
Hash,
MerkleWitness,
PublicKey,
PrivateKey,
Signature,
AccountUpdate,
SelfProof,
} from 'o1js';

export { diverse, Bytes128 };

class Secp256k1 extends createForeignCurve(Crypto.CurveParams.Secp256k1) {}
class Secp256k1Scalar extends Secp256k1.Scalar {}
class Secp256k1Signature extends createEcdsa(Secp256k1) {}

class Bytes128 extends Bytes(128) {}

class MerkleWitness30 extends MerkleWitness(30) {}

const diverse = ZkProgram({
name: 'diverse',

methods: {
// foreign field / curve ops, multi-range checks
ecdsa: {
privateInputs: [
Secp256k1Scalar.provable,
Secp256k1Signature.provable,
Secp256k1.provable,
],
method(
message: Secp256k1Scalar,
signature: Secp256k1Signature,
publicKey: Secp256k1
) {
assert(signature.verifySignedHash(message, publicKey));
},
},

// bitwise gadgets
sha3: {
privateInputs: [Bytes128.provable],
method(xs: Bytes128) {
Hash.SHA3_256.hash(xs);
},
},

// poseidon
poseidon: {
privateInputs: [AccountUpdate, MerkleWitness30],
method(accountUpdate: AccountUpdate, witness: MerkleWitness30) {
let leaf = accountUpdate.hash();
let root = witness.calculateRoot(leaf);
let index = witness.calculateIndex();
index.assertNotEquals(root);
},
},

// native EC ops
pallas: {
privateInputs: [PublicKey, PrivateKey, Signature],
method(pk: PublicKey, sk: PrivateKey, sig: Signature) {
let pk2 = sk.toPublicKey();
pk.assertEquals(pk2);

sig.verify(pk, [Field(1), Field(2)]).assertTrue();
},
},

// only generic gates
generic: {
privateInputs: [Field, Field],
method(x: Field, y: Field) {
x.square().equals(5).assertFalse();
let z = Provable.if(y.equals(0), x, y);
z.assertEquals(x);
},
},

// recursive proof
recursive: {
privateInputs: [SelfProof],
method(proof: SelfProof<undefined, void>) {
proof.verify();
},
},
},
});
33 changes: 33 additions & 0 deletions tests/vk-regression/vk-regression.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,38 @@
"data": "AACa0OPxg0UDEf5DBLZf/TtdB4TzIAMNQC467+/R1yGnL1tRXJnn0BDcLG0fGWdqFcWK1q2zKdAYfORKVOHgvKEwxtxZYv4CjM7SwlG09G52oNZmOgGCilD0ntmby4rzJTaoyCimx5ynQ/oYjslJgSM/1DTAkpW6IIdFjjkmjlOSHqRNRAMtNtl44D9lbhci4blHbDvzQnlYynwRh58jAzoDj3bCkPsByviAyFBoPhUx2M13h0/VPK1ND/69djzZgi9lQKaON74XvbnvJdSAYLQSIBbOE0yo7tS1vGTPqDqJGzc1f0+2QhZttE2UEUV4PPEGB6LUFEuQPXK8lXyXHVQTOU+omjpvKHLLs/dQZLTSvvZ3UFqxUvxjSEG9eTPo3Cyt4wXcPEi1b993ePSSxP6njj1SoPBA4BvLCCcvaxz5DegUu7nZDKkC8tuaoNbqYcayaf/8+oZ+dA+Ek1Xe08og1Hz9gB9cfPvgI9EiL2Na2cgiOF2klHHEAj3fORN8UQVzs0ioqLcQeq2tH2UMMtZS4JNcohHUah1T0jKmS3eZDqe+aMuf5qzKA5oKRF2ejRwmsxI161YlgXXpmHs+kCQGAPvX5+/WvgVyy1uIX6426oQoB+0Ni/lWEhFNY+MvNVUGIgPAyvpEafTl8DMfPQkUf0yQCPxRg7d/lRCRfYqHRT74U20AHCGYSahuSFbBO6dDhRCPGRCJJgxktY+CSO+3B9mLtCe2X23FeFsUnaAFlzmsWeKR1tMyPupNsUXPFugubYZYd1EwxUDeBIOLeahcqX78yDDMOdsr0QHNG8XteyXcRXGFUSzTTKNEXdD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nbgfhnjFf9HqS5bG1sR1Dh2mXGXpQ+ni+O3FvEYCEZY+UU9d9XCGwL2OZIhtMi6M6qcnrn11w2MyaZ8U6aZxVTMFvKQ2JLtwVGVnMDuSkNC+iN711acwssgbTpsgHLdVbtFR1oYcbpJHe6a9SFquG+q9qfzT15IzKpBzxn6BVXfhhFGpJRAbU0bXbjOpeceg7vaV7RykTzBoIzAe5aUVAdKNM6fzGlPw16xx7QeOW+LFlOm6HJyxYAZfbpB/BLza4ZhoqmVx+ALUXHFIztgGQK9rzm+jBwiuwuLqdD2W00cbTZcbgKTo48XD6NJ+8T4J9B3rPzht3qbgpN//TyYkfrzAercAa/HCvFeBNXl1slCj8cF/EO6iX/NnIxBkuqmXfQnGUfcFK0LZPsvd7RInaLEYTeA4ZDfChiuw+5nTmrJFOywwOYdIA+NiMfCh24dPYAAwEGb9KLEP9u7/Rp5uPi0S3tuTw67yg=",
"hash": "22296391645667701199385692837408020819294441951376164803693884547686842878882"
}
},
"diverse": {
"digest": "3822c67734f73c594779eab98899d2e4cc254b7b9d5261b2aada529f781c1234",
"methods": {
"ecdsa": {
"rows": 28186,
"digest": "962fef399c0999d49427817cbf35f34d"
},
"generic": {
"rows": 7,
"digest": "1496e5b8cc253c9909551a25c190ab85"
},
"pallas": {
"rows": 1616,
"digest": "8a9ee7267139d6280971f9750a610713"
},
"poseidon": {
"rows": 947,
"digest": "4ff5a55f56bca18bc4c12f0806e5efa4"
},
"recursive": {
"rows": 0,
"digest": "4f5ddea76d29cfcfd8c595f14e31f21b"
},
"sha3": {
"rows": 14919,
"digest": "cfc49005fe4a108be200834e064354c3"
}
},
"verificationKey": {
"data": "AQEHElJ4J2GXqlynto2scgv7djsefJT375LvY2AICls7FY7E/1pxwh+iD34lrpXyrWAWaUP3kvqv5MDU+UI/LXMJV+fTuOZVV1SbZaRobj6gkzICJF1QD74Cs46Qt9sEuB7jBY6IsMKdhpI8QHZeQn4ykxkQGx0/JtJWYbX34AzSOJJKdolQ4x6hfb+L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nnZhl6cehrkQW2UzlE5N2jPGEjhdZ0xxfOypnxRc=",
"hash": "20847658473027482795733452537216050272254432619335295432291623073949897032418"
}
}
}
2 changes: 2 additions & 0 deletions tests/vk-regression/vk-regression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../../src/examples/crypto/ecdsa/ecdsa.js';
import { SHA256Program } from '../../src/examples/crypto/sha256/sha256.js';
import { GroupCS, BitwiseCS, HashCS } from './plain-constraint-system.js';
import { diverse } from './diverse-zk-program.js';

// toggle this for quick iteration when debugging vk regressions
const skipVerificationKeys = false;
Expand Down Expand Up @@ -47,6 +48,7 @@ const ConstraintSystems: MinimumConstraintSystem[] = [
ecdsa,
keccakAndEcdsa,
SHA256Program,
diverse,
];

let filePath = jsonPath ? jsonPath : './tests/vk-regression/vk-regression.json';
Expand Down

0 comments on commit fcf3080

Please sign in to comment.