Skip to content

Commit

Permalink
Merge pull request #1345 from o1-labs/perf/field-conv
Browse files Browse the repository at this point in the history
Faster fields to bytes conversion
  • Loading branch information
mitschabaude authored Dec 21, 2023
2 parents d389fee + 5655928 commit 235c80e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/bindings
8 changes: 0 additions & 8 deletions src/examples/crypto/ecdsa/ecdsa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ const keccakAndEcdsa = ZkProgram({
return signature.verify(message, publicKey);
},
},

sha3: {
privateInputs: [],
method(message: Bytes32) {
Keccak.nistSha3(256, message);
return Bool(true);
},
},
},
});

Expand Down
13 changes: 4 additions & 9 deletions src/examples/crypto/ecdsa/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@ let signature = Ecdsa.sign(message.toBytes(), privateKey.toBigInt());
// investigate the constraint system generated by ECDSA verify

console.time('ecdsa verify only (build constraint system)');
let csEcdsa = ecdsa.analyzeMethods().verifySignedHash;
let csEcdsa = ecdsa.analyzeMethods();
console.timeEnd('ecdsa verify only (build constraint system)');
console.log(csEcdsa.summary());

console.time('keccak only (build constraint system)');
let csKeccak = keccakAndEcdsa.analyzeMethods().sha3;
console.timeEnd('keccak only (build constraint system)');
console.log(csKeccak.summary());
console.log(csEcdsa.verifySignedHash.summary());

console.time('keccak + ecdsa verify (build constraint system)');
let cs = keccakAndEcdsa.analyzeMethods().verifyEcdsa;
let cs = keccakAndEcdsa.analyzeMethods();
console.timeEnd('keccak + ecdsa verify (build constraint system)');
console.log(cs.summary());
console.log(cs.verifyEcdsa.summary());

// compile and prove

Expand Down
4 changes: 2 additions & 2 deletions src/lib/provable-context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context } from './global-context.js';
import { Gate, GateType, JsonGate, Snarky } from '../snarky.js';
import { parseHexString } from '../bindings/crypto/bigint-helpers.js';
import { parseHexString32 } from '../bindings/crypto/bigint-helpers.js';
import { prettifyStacktrace } from './errors.js';
import { Fp } from '../bindings/crypto/finite_field.js';

Expand Down Expand Up @@ -126,7 +126,7 @@ function constraintSystem<T>(f: () => T) {

function gatesFromJson(cs: { gates: JsonGate[]; public_input_size: number }) {
let gates: Gate[] = cs.gates.map(({ typ, wires, coeffs: hexCoeffs }) => {
let coeffs = hexCoeffs.map((hex) => parseHexString(hex).toString());
let coeffs = hexCoeffs.map((hex) => parseHexString32(hex).toString());
return { type: typ, wires, coeffs };
});
return { publicInputSize: cs.public_input_size, gates };
Expand Down
10 changes: 3 additions & 7 deletions tests/vk-regression/vk-regression.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,16 @@
}
},
"ecdsa": {
"digest": "334c2efc6a82e87319cadb7f3e6f9edb55f8f2eab71e0bcf2451f3d5536de5fe",
"digest": "3e80a93d93a93f6152d70a9c21a2979ff0094c2d648a67c6d2daa4b2b0d18309",
"methods": {
"sha3": {
"rows": 14494,
"digest": "949539824d56622702d9ac048e8111e9"
},
"verifyEcdsa": {
"rows": 45178,
"digest": "0b6ce4cc658bcca79b1b1373569aa9b9"
}
},
"verificationKey": {
"data": "AAB/ZjMH6HxnifKVGWGw41mrmDWq4R7eG+tJRvszclriFqNFKZXi3LD9Z+2F/VSHlQD8mq3JCoD6tm3rlEQXheATALIHoglupcYB4X43h14qFKloG2kuKwLeDl6mRpeVwSmwE/Tv+P3K8KkyB9zmoT1eEt/ayPRm4EzrJb0EHzyrE0VhKfn6Xh48tBUpGk3JahLhsK+yOTjDBvwcZ/vsiNkGCtFbQv9rM7YZlpBk6NmFYzcnsfJOHyYyr6Xab+6UYjVt6aJGVLMgCv+qLekdsCsmVBwOWhEWwASVZ5WW5qWyOL613+zKXyQvqBcWWvg68CZk2rEjZvH64dPlVXV0hxYLb7p43WNgY+e8MR+RHA0/aGnvB4cwCKQw23n2B9bg+wxDwS7fK9/va/0HspgUvwGv8fNpdsYW1OgLnY1deUHhJc1+UaUFwHJVdB7Nx/W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8sFAjKLB5T9yIEgYpLcXXbtV5zfaBXzPUFeLUAonv4S/gUhMA1QgSwXyCffgLRBrIXgwwiYepCmu1RYWXkLkTBwvSuTtKj9z4QGNdp5tBHrXKCOrYYN0chiDKIhFAa+PtylRK2fGeVnOZQSMcy04VIC5T+e0KR3pIt9PdJ72SHEYjmdNL+W9JL/fjz+co5Vxpz6p6RCwE1pL+kw4B0v1/BhJJB+NIv+GXTxOYeGx8K/P/3B9KUsbBykBQOvjcM8kJFIx5yry9idrtEGh5Ejw7UZ1W2sWIpFdKIAGUm54ir07a5Txkhy7PBIiyp5PRacp6V6S9aI8liE5LRC1qguXcKnbBg3QudnY/wUFwB6rJf7EBA2otA8PgEG8ICOg86XltPUqpVKUMBiu30jIa0VFS3O8BtuJvzdmVa8xK4K3ZP3/T4s4SAMOtyi6L4pxTJB9NHI0WnvQQeVAxlizlIu6VMwDdZuVtRJa0wbKTIDmc7lF+d2pD5uYOSLakc5h5jKRz386Dt9pYA577NKP+ioED2m+iv9bLPDIhDo6X589HxFZX4oxrzDI7m85rUvWBgNWqjZ9MpQSuui9yr2F5P8xtBsHDEIRi+wqX7Sui56cRuLZYaWvMVOIwkplHDIz0afncgI5BcA8KM4mJfpKosF42cWAMhijdDVAG234RIP6ogJCAcQu3q+q8uG2sYf655WE3+70zh0aiLvgQa1odo9FdEXV5HWs6Gh4hUDhA0ULlZVbJ+Mxg/XacBb+AnBxBpuSrIjfHaEtCkFKlDdF48Ny+HFVojxE4ZYuoNlXDDVkBi58aj2oMFDfaPB+bEJjxF7wpqjbts703mEckhLhQWpnnhNVbEyBGED8N4gIiA=",
"hash": "18381574995221799963215366500837755447342811019610547066832598459350935665488"
"data": "AACzYt9qtBkn6y40KDH0lkzRSMBh3W41urWE6j0PSP2KB9GxsBAHAI3uzay1Vqyc+LMXeANSzNcoYSYnZts9Pk0nFNjCZ84EnGkie609NhFB8tU9k5Vkoqw3jihdsoJEUy6GK0H30dl/7H1rGxsx6Ec05aaFhiPw6t0jL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2o2OU4mO0q96pCueKjAttkXgz+NSIJzcwprvNyE9UtKWswmIQg=",
"hash": "25447212082831819715054236631079960883754611880602728284997977929479384060913"
}
}
}

0 comments on commit 235c80e

Please sign in to comment.