diff --git a/contracts/ProofMarketplace.sol b/contracts/ProofMarketplace.sol index 99ad8cd..eb4eff1 100644 --- a/contracts/ProofMarketplace.sol +++ b/contracts/ProofMarketplace.sol @@ -166,7 +166,7 @@ contract ProofMarketplace is //-------------------------------- Events start --------------------------------// - event AskCreated(uint256 indexed askId, bool indexed hasPrivateInputs, bytes secret_data, bytes acl); + event AskCreated(uint256 indexed askId, bool indexed hasPrivateInputs, bytes secret_data, bytes acl, bytes extraData); event TaskCreated(uint256 indexed askId, address indexed generator, bytes new_acl); // TODO: add ask ID also event ProofCreated(uint256 indexed askId, bytes proof); @@ -357,9 +357,10 @@ contract ProofMarketplace is // TODO: Check if this needs to be removed during review SecretType secretType, bytes calldata privateInputs, - bytes calldata acl + bytes calldata acl, + bytes calldata extraData ) external whenNotPaused nonReentrant { - _createAsk(ask, msg.sender, secretType, privateInputs, acl); + _createAsk(ask, msg.sender, secretType, privateInputs, acl, extraData); } function _createAsk( @@ -367,7 +368,8 @@ contract ProofMarketplace is address payFrom, SecretType secretType, bytes calldata privateInputs, - bytes calldata acl + bytes calldata acl, + bytes calldata extraData ) internal { if (ask.reward == 0 || ask.proverData.length == 0) { revert Error.CannotBeZero(); @@ -407,10 +409,10 @@ contract ProofMarketplace is if (market.proverImageId.IS_ENCLAVE()) { // ACL is emitted if private - emit AskCreated(askId, true, privateInputs, acl); + emit AskCreated(askId, true, privateInputs, acl, extraData); } else { // ACL is not emitted if not private - emit AskCreated(askId, false, "", ""); + emit AskCreated(askId, false, "", "", extraData); } } diff --git a/contracts/verifierWrappers/plonk_vk_wrapper.sol b/contracts/verifierWrappers/plonk_vk_wrapper.sol index 2c270c5..68b6b70 100644 --- a/contracts/verifierWrappers/plonk_vk_wrapper.sol +++ b/contracts/verifierWrappers/plonk_vk_wrapper.sol @@ -28,7 +28,8 @@ contract plonk_verifier_wrapper is SetPmp, IVerifier { ProofMarketplace.Ask calldata ask, ProofMarketplace.SecretType secretType, bytes calldata secret_inputs, - bytes calldata acl + bytes calldata acl, + bytes calldata extraData ) public { ProofMarketplace.Ask memory newAsk = ProofMarketplace.Ask( ask.marketId, @@ -40,7 +41,7 @@ contract plonk_verifier_wrapper is SetPmp, IVerifier { encodeInputs(verifyAndDecodeInputs(ask.proverData)) ); - proofMarketplace.createAsk(newAsk, secretType, secret_inputs, acl); + proofMarketplace.createAsk(newAsk, secretType, secret_inputs, acl, extraData); } function verifyAndDecodeInputs(bytes calldata inputs) internal pure returns (bytes32[] memory) { diff --git a/contracts/verifierWrappers/transfer_verifier_wrapper.sol b/contracts/verifierWrappers/transfer_verifier_wrapper.sol index 18c4b00..dc2dbcc 100644 --- a/contracts/verifierWrappers/transfer_verifier_wrapper.sol +++ b/contracts/verifierWrappers/transfer_verifier_wrapper.sol @@ -31,7 +31,8 @@ contract transfer_verifier_wrapper is SetPmp, IVerifier { ProofMarketplace.Ask calldata ask, ProofMarketplace.SecretType secretType, bytes calldata secret_inputs, - bytes calldata acl + bytes calldata acl, + bytes calldata extraData ) public { ProofMarketplace.Ask memory newAsk = ProofMarketplace.Ask( ask.marketId, @@ -43,7 +44,7 @@ contract transfer_verifier_wrapper is SetPmp, IVerifier { encodeInputs(verifyAndDecodeInputs(ask.proverData)) ); - proofMarketplace.createAsk(newAsk, secretType, abi.encode(secret_inputs), abi.encode(acl)); + proofMarketplace.createAsk(newAsk, secretType, abi.encode(secret_inputs), abi.encode(acl), extraData); } function verifyAndDecodeInputs(bytes calldata inputs) internal pure returns (uint256[5] memory) { diff --git a/contracts/verifierWrappers/xor2_verifier_wrapper.sol b/contracts/verifierWrappers/xor2_verifier_wrapper.sol index 2b0c714..c22402b 100644 --- a/contracts/verifierWrappers/xor2_verifier_wrapper.sol +++ b/contracts/verifierWrappers/xor2_verifier_wrapper.sol @@ -25,7 +25,8 @@ contract xor2_verifier_wrapper is SetPmp, IVerifier { ProofMarketplace.Ask calldata ask, ProofMarketplace.SecretType secretType, bytes calldata secret_inputs, - bytes calldata acl + bytes calldata acl, + bytes calldata extraData ) public { ProofMarketplace.Ask memory newAsk = ProofMarketplace.Ask( ask.marketId, @@ -37,7 +38,7 @@ contract xor2_verifier_wrapper is SetPmp, IVerifier { encodeInputs(verifyAndDecodeInputs(ask.proverData)) ); - proofMarketplace.createAsk(newAsk, secretType, abi.encode(secret_inputs), abi.encode(acl)); + proofMarketplace.createAsk(newAsk, secretType, abi.encode(secret_inputs), abi.encode(acl), extraData); } function verifyAndDecodeInputs(bytes calldata inputs) internal pure returns (uint[1] memory) { diff --git a/helpers/setup.ts b/helpers/setup.ts index f772b32..bf89288 100644 --- a/helpers/setup.ts +++ b/helpers/setup.ts @@ -1,5 +1,5 @@ import { ethers, upgrades } from "hardhat"; -import { Provider, Signer } from "ethers"; +import { BytesLike, Provider, Signer } from "ethers"; import { MockToken, @@ -46,13 +46,14 @@ export const createAsk = async ( ask: ProofMarketplace.AskStruct, setupTemplate: SetupTemplate, secretType: number, + extraData: BytesLike = "0x", ): Promise => { await setupTemplate.mockToken.connect(tokenHolder).transfer(await prover.getAddress(), ask.reward.toString()); await setupTemplate.mockToken.connect(prover).approve(await setupTemplate.proofMarketplace.getAddress(), ask.reward.toString()); const askId = await setupTemplate.proofMarketplace.askCounter(); - await setupTemplate.proofMarketplace.connect(prover).createAsk(ask, secretType, "0x", "0x"); + await setupTemplate.proofMarketplace.connect(prover).createAsk(ask, secretType, "0x", "0x", extraData); return askId.toString(); }; diff --git a/test/Generator.ts b/test/Generator.ts index 69438ed..eb130f5 100644 --- a/test/Generator.ts +++ b/test/Generator.ts @@ -381,7 +381,7 @@ describe("Checking Generator's multiple compute", () => { const askId = await proofMarketplace.askCounter(); - await proofMarketplace.connect(prover).createAsk(ask, marketId, "0x", "0x"); + await proofMarketplace.connect(prover).createAsk(ask, marketId, "0x", "0x", "0x"); const matchingEngine: Signer = new ethers.Wallet(matchingEngineEnclave.getPrivateKey(true), admin.provider); @@ -554,7 +554,7 @@ describe("Checking Generator's multiple compute", () => { const askId = await proofMarketplace.askCounter(); - await proofMarketplace.connect(prover).createAsk(ask, marketId, "0x", "0x"); + await proofMarketplace.connect(prover).createAsk(ask, marketId, "0x", "0x", "0x"); const matchingEngine: Signer = new ethers.Wallet(matchingEngineEnclave.getPrivateKey(true), admin.provider); @@ -646,7 +646,7 @@ describe("Checking Generator's multiple compute", () => { const askId = await proofMarketplace.askCounter(); - await proofMarketplace.connect(prover).createAsk(ask, marketId, "0x", "0x"); + await proofMarketplace.connect(prover).createAsk(ask, marketId, "0x", "0x", "0x"); const matchingEngine: Signer = new ethers.Wallet(matchingEngineEnclave.getPrivateKey(true), admin.provider); diff --git a/test/ProofMarketPlaceBasic.ts b/test/ProofMarketPlaceBasic.ts index 1e9e306..6e995b6 100644 --- a/test/ProofMarketPlaceBasic.ts +++ b/test/ProofMarketPlaceBasic.ts @@ -364,9 +364,9 @@ describe("Proof market place", () => { .connect(prover) .approve(await proofMarketplace.getAddress(), new BigNumber(platformFee.toString()).plus(reward).toFixed()); - await expect(proofMarketplace.connect(prover).createAsk(askRequest, 1, secretInfo, aclInfo)) + await expect(proofMarketplace.connect(prover).createAsk(askRequest, 1, secretInfo, aclInfo, "0x")) .to.emit(proofMarketplace, "AskCreated") - .withArgs(askIdToBeGenerated, true, "0x2345", "0x21") + .withArgs(askIdToBeGenerated, true, "0x2345", "0x21", "0x") .to.emit(mockToken, "Transfer") .withArgs(await prover.getAddress(), await proofMarketplace.getAddress(), new BigNumber(platformFee.toString()).plus(reward)); @@ -435,9 +435,9 @@ describe("Proof market place", () => { .connect(prover) .approve(await proofMarketplace.getAddress(), new BigNumber(platformFee.toString()).plus(reward).toFixed()); - await expect(proofMarketplace.connect(prover).createAsk(askRequest, 1, secretInfo, aclInfo)) + await expect(proofMarketplace.connect(prover).createAsk(askRequest, 1, secretInfo, aclInfo, "0x")) .to.emit(proofMarketplace, "AskCreated") - .withArgs(askIdToBeGenerated, false, "0x", "0x") + .withArgs(askIdToBeGenerated, false, "0x", "0x", "0x") .to.emit(mockToken, "Transfer") .withArgs(await prover.getAddress(), await proofMarketplace.getAddress(), new BigNumber(platformFee.toString()).plus(reward)); @@ -467,6 +467,7 @@ describe("Proof market place", () => { 0, "0x", "0x", + "0x", ), ).to.be.revertedWithPanic(0x32); // 0x32 mean array out of bounds // market is not created }); @@ -751,6 +752,7 @@ describe("Proof market place", () => { 0, "0x", "0x", + "0x", ); await generatorRegistry @@ -842,6 +844,7 @@ describe("Proof market place", () => { 0, "0x", "0x", + "0x", ); await expect( diff --git a/test/ProofMarketPlaceForAttestationZkVerifier.ts b/test/ProofMarketPlaceForAttestationZkVerifier.ts index f895c25..ca5ee38 100644 --- a/test/ProofMarketPlaceForAttestationZkVerifier.ts +++ b/test/ProofMarketPlaceForAttestationZkVerifier.ts @@ -85,6 +85,13 @@ describe("Proof Market Place for Attestation Verifier", () => { let inputBytes = attestation.attestation; + let extraData = Buffer.from(`Figure out some way to pass attestation in extra data, and only journal_bytes in public inputs. + Prover will then, fetch the attestation from the extra data, generate proof. + When submitProof() is called, prover_bytes, attestation_from_extra_data, and proof will be sent by user only. + Verification Contract needs to check the consistency here. + start looking from risc0_attestation_verifier_wrapper.sol#verify(bytes memory encodedData) + `); + beforeEach(async () => { signers = await ethers.getSigners(); admin = signers[0]; @@ -192,6 +199,7 @@ describe("Proof Market Place for Attestation Verifier", () => { entityKeyRegistry, }, 1, + extraData, ); await setup.createTask(