Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TS Risc0 journal parsing #5

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
300eef0
changing node target
luiz-lvj Sep 13, 2024
2523403
updating to garaga_ts
luiz-lvj Sep 13, 2024
9f4f8b3
groth 16 parser
luiz-lvj Sep 25, 2024
2258a43
parsing groth 16 ready
luiz-lvj Sep 25, 2024
4181b89
parser working for groth 16 proof
luiz-lvj Sep 26, 2024
fc38e4a
tests for verifying key proof running
luiz-lvj Sep 26, 2024
47f9d11
tests for verifying key working
luiz-lvj Sep 26, 2024
d94a443
tests for verifying key working
luiz-lvj Sep 26, 2024
ef7fceb
Merge branch 'main' of github.com:luiz-lvj/garaga into groth16_parser
luiz-lvj Sep 27, 2024
c19b8e9
refactoring parsing to add object parser on groth16 Proof
luiz-lvj Sep 27, 2024
80a680f
refactoring parsing to add object parser on verifying key groth16 Proof
luiz-lvj Sep 27, 2024
d5ccc83
creating serializeGroth16ProofToCallData and necessary functions
luiz-lvj Sep 27, 2024
de75807
changing rootDir to ./ in order to build with tests
luiz-lvj Sep 27, 2024
3152615
changing wasm build workflow due to pre-commit
luiz-lvj Sep 27, 2024
9df8350
Merge pull request #1 from luiz-lvj/groth16_parser
luiz-lvj Sep 27, 2024
a7de86e
removing unnecessary functions and adding node workflow
luiz-lvj Sep 28, 2024
1551d25
removing bypass on build github workflow
luiz-lvj Sep 28, 2024
8c47e43
removing wasm pkg from end-of-file-fixer pre-commit script
luiz-lvj Sep 28, 2024
5fbdfd8
excluding wasm pkg from trailing whistespace pre-commit
luiz-lvj Sep 28, 2024
56181c5
updating wasm build
luiz-lvj Sep 29, 2024
cf05bbe
updating wasm after build
luiz-lvj Sep 29, 2024
c11bea6
wasm build from docker
luiz-lvj Sep 29, 2024
494f45a
files generated by docker
luiz-lvj Sep 29, 2024
612429f
files generated by npm build
luiz-lvj Sep 29, 2024
3a12b45
files generated by node build
luiz-lvj Sep 29, 2024
d4d7d79
updating .wasm.js file
luiz-lvj Sep 30, 2024
dac43d7
Merge pull request #2 from luiz-lvj/groth16_parser
luiz-lvj Sep 30, 2024
0bdea5e
Merge branch 'main' into main
feltroidprime Sep 30, 2024
cb0b681
Merge branch 'keep-starknet-strange:main' into main
luiz-lvj Oct 1, 2024
1c27f6a
adding to_weirstrass and to_twistededwards to wasm binding
luiz-lvj Oct 3, 2024
f09c3fe
adding functions to api.ts
luiz-lvj Oct 3, 2024
a969ddc
new pkg generated
luiz-lvj Oct 3, 2024
79d442c
cargo fmt
luiz-lvj Oct 3, 2024
d82beae
test git diff on generated pkg
luiz-lvj Oct 3, 2024
8fa9918
fixing .wasm.js file
luiz-lvj Oct 3, 2024
c8ee1c9
removing git diff from workflow
luiz-lvj Oct 3, 2024
51cfa1c
Merge pull request #4 from luiz-lvj/twisted_edwards
luiz-lvj Oct 3, 2024
9b20cc3
solving conflicts
luiz-lvj Oct 17, 2024
b7e8a41
changing journalDigest to journal
luiz-lvj Oct 18, 2024
1c85ee9
Merge branch 'main' of github.com:luiz-lvj/garaga into update_journal
luiz-lvj Oct 23, 2024
fb984e9
updating parseUtils.ts and adding test to risc0 proof
luiz-lvj Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface Groth16Proof {
publicInputs: bigint[],
curveId?: CurveId,
imageId?: Uint8Array,
journalDigest?: Uint8Array
journal?: Uint8Array
}

export interface Groth16VerifyingKey {
Expand Down Expand Up @@ -51,6 +51,12 @@ interface ReceiptClaim {
tagDigest?: Uint8Array;
}

export class KeyPatternNotFoundError extends Error {
constructor(message: string) {
super(message);
this.name = "KeyPatternNotFoundError";
}
}



Expand Down Expand Up @@ -188,17 +194,24 @@ export const parseGroth16ProofFromObject = (data: any, publicInputsData?: bigint

try{

console.log("AQUI BEFORE")

const sealHex = toHexStr(findItemFromKeyPatterns(proof, ['seal']));
const imageIdHex = toHexStr(findItemFromKeyPatterns(proof, [ 'image_id']));
const journalHex = toHexStr(findItemFromKeyPatterns(proof, ['journal']));

console.log("journalHex: ", journalHex);

console.log("LATER: ", journalHex);

const sealBytes = hexStringToBytes(sealHex);
const imageIdBytes = hexStringToBytes(imageIdHex);
const journalBytes = hexStringToBytes(journalHex);

return createGroth16ProofFromRisc0(sealBytes, imageIdBytes, journalBytes)

} catch(err){
console.log("ERROR AQUI: ", err);

}

Expand All @@ -217,7 +230,12 @@ export const parseGroth16ProofFromObject = (data: any, publicInputsData?: bigint
throw new Error(`Invalid public inputs format: ${publicInputsData}`);
}
} else{
publicInputs = findItemFromKeyPatterns(data, ['public']);

try {
publicInputs = findItemFromKeyPatterns(data, ['public']);
} catch(err){
throw new Error(`Error: ${err}`);
}
}
const a = tryParseG1PointFromKey(proof, ['a'], curveId);
const b = tryParseG2PointFromKey(proof, ['b'], curveId);
Expand All @@ -243,18 +261,21 @@ export const parseGroth16ProofFromObject = (data: any, publicInputsData?: bigint
}


export const createGroth16ProofFromRisc0 = (seal: Uint8Array, imageId: Uint8Array, journal: Uint8Array,
export const createGroth16ProofFromRisc0 = (seal: Uint8Array, imageId: Uint8Array, journalBytes: Uint8Array,
controlRoot: bigint = RISC0_CONTROL_ROOT, bn254ControlId: bigint = RISC0_BN254_CONTROL_ID): Groth16Proof => {

if(imageId.length <= 32){
if(imageId.length > 32){
throw new Error("imageId must be 32 bytes")
}

const [constrolRoot0, controlRoot1] = splitDigest(controlRoot);

const proof = seal.slice(4);
const journalDigest = createHash("sha256").update(journal).digest();
const claimDigest = digestReceiptClaim(ok(imageId, journalDigest));


const journal = createHash("sha256").update(journalBytes).digest();

const claimDigest = digestReceiptClaim(ok(imageId, journal));

const [claim0, claim1] = splitDigest(claimDigest);

Expand Down Expand Up @@ -288,7 +309,7 @@ export const createGroth16ProofFromRisc0 = (seal: Uint8Array, imageId: Uint8Arra
bn254ControlId
],
imageId,
journalDigest
journal
}
if(checkGroth16Proof(groth16Proof)){
return groth16Proof;
Expand Down Expand Up @@ -330,6 +351,11 @@ export const checkGroth16VerifyingKey = (vk: Groth16VerifyingKey): boolean => {
const digestReceiptClaim = (receipt: ReceiptClaim): Uint8Array => {
const { tagDigest, input, preStateDigest, postStateDigest, output, exitCode } = receipt;

console.log("receipt: ", receipt);
console.log("tagDigest: ", tagDigest);



// Concatenating all parts into one Buffer
const data = Buffer.concat([
tagDigest!,
Expand Down Expand Up @@ -362,6 +388,7 @@ function ok(imageId: Uint8Array, journalDigest: Uint8Array): ReceiptClaim {

// Create and return the ReceiptClaim object
return {
tagDigest: createHash('sha256').update(Buffer.from("risc0.ReceiptClaim")).digest(),
preStateDigest: imageId,
postStateDigest: SYSTEM_STATE_ZERO_DIGEST,
exitCode,
Expand Down Expand Up @@ -494,7 +521,7 @@ const findItemFromKeyPatterns = (data: { [key: string]: any }, keyPatterns: stri
if(bestMatch){
return bestMatch;
}
throw new Error(`No key found with patterns ${keyPatterns}`);
throw new KeyPatternNotFoundError(`No key found with patterns ${keyPatterns}`);
}

export const getPFromCurveId = (curveId: CurveId): bigint => {
Expand Down
3 changes: 3 additions & 0 deletions tools/npm/garaga_ts/src/wasm/pkg/garaga_rs.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ function __wbg_get_imports() {
const ret = getObject(arg0) + getObject(arg1);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
const obj = getObject(arg1);
const ret = typeof(obj) === 'string' ? obj : undefined;
Expand Down
2 changes: 1 addition & 1 deletion tools/npm/garaga_ts/src/wasm/pkg/garaga_rs_bg.wasm.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseGroth16ProofFromJson, parseGroth16VerifyingKeyFromJson } from "../../src/node/starknet/groth16ContractGenerator/parsingUtils";
import { parseGroth16VerifyingKeyFromJson, parseGroth16ProofFromJson } from "../../src/node/starknet/groth16ContractGenerator/parsingUtils";

const PATH = '../../../hydra/garaga/starknet/groth16_contract_generator/examples';

Expand All @@ -22,6 +22,7 @@ describe('Groth16 Parsing Tests', () => {
const proofPaths = [
`${PATH}/proof_bn254.json`,
`${PATH}/proof_bls.json`,
`${PATH}/proof_risc0.json`,
];

test.each(proofPaths)('should parse proof from %s', (proofPath) => {
Expand Down
Loading