-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1467 from o1-labs/feature/diverse-vk-regression-test
Diverse vk regression test
- Loading branch information
Showing
6 changed files
with
151 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters