Skip to content

Commit

Permalink
Add Feature extra data
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay111meher committed Dec 27, 2024
1 parent af8fa19 commit c761246
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
14 changes: 8 additions & 6 deletions contracts/ProofMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -357,17 +357,19 @@ 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(
Ask calldata ask,
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();
Expand Down Expand Up @@ -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);
}
}

Expand Down
5 changes: 3 additions & 2 deletions contracts/verifierWrappers/plonk_vk_wrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions contracts/verifierWrappers/transfer_verifier_wrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions contracts/verifierWrappers/xor2_verifier_wrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions helpers/setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers, upgrades } from "hardhat";
import { Provider, Signer } from "ethers";
import { BytesLike, Provider, Signer } from "ethers";

import {
MockToken,
Expand Down Expand Up @@ -46,13 +46,14 @@ export const createAsk = async (
ask: ProofMarketplace.AskStruct,
setupTemplate: SetupTemplate,
secretType: number,
extraData: BytesLike = "0x",
): Promise<string> => {
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();
};
Expand Down
6 changes: 3 additions & 3 deletions test/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
11 changes: 7 additions & 4 deletions test/ProofMarketPlaceBasic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -751,6 +752,7 @@ describe("Proof market place", () => {
0,
"0x",
"0x",
"0x",
);

await generatorRegistry
Expand Down Expand Up @@ -842,6 +844,7 @@ describe("Proof market place", () => {
0,
"0x",
"0x",
"0x",
);

await expect(
Expand Down
8 changes: 8 additions & 0 deletions test/ProofMarketPlaceForAttestationZkVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -192,6 +199,7 @@ describe("Proof Market Place for Attestation Verifier", () => {
entityKeyRegistry,
},
1,
extraData,
);

await setup.createTask(
Expand Down

0 comments on commit c761246

Please sign in to comment.