Skip to content

Commit

Permalink
feat: add ORA_SINGLE mainnet verifier
Browse files Browse the repository at this point in the history
  • Loading branch information
nom4dv3 committed May 8, 2024
1 parent 8d03d1b commit 21800de
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 14 deletions.
13 changes: 9 additions & 4 deletions src/api/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AggregatorVerifierABI, AggregatorVerifierAddress, PROVER_RPC_CONSTANTS
import { ProveTaskNotReady } from '../common/error'
import type { BatchOption, ProofParams, ProofParams as VerifyProofParams } from '../types'
import { BatchStyle } from '../types'
import { getNetworkNameByChainID } from '../common/utils'
import { waitProve } from './prove'
// import { VerifyProofParams } from '@ora-io/zkwasm-service-helper'

Expand Down Expand Up @@ -37,11 +38,15 @@ export async function verifyOnchain(
if (isZKVerifier === false)
throw new Error('isZKVerifier==false is reserved, not supported yet')
const { provider } = options
const network = (await provider.getNetwork()).name

const chainId = (await provider.getNetwork()).chainId
const network = getNetworkNameByChainID(chainId).toLowerCase()
const defaultVerifierAddress
= batchStyle === BatchStyle.ORA
? AggregatorVerifierAddress.ORA[network]
: AggregatorVerifierAddress.ZKWASMHUB[network]
= batchStyle === BatchStyle.ZKWASMHUB
? AggregatorVerifierAddress.ZKWASMHUB[network]
: batchStyle === BatchStyle.ORA_SINGLE
? AggregatorVerifierAddress.ORA_SINGLE[network]
: AggregatorVerifierAddress.ORA[network]

const { verifierAddress = defaultVerifierAddress } = options

Expand Down
8 changes: 8 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ export const networks = [
name: 'Sepolia',
label: 'Sepolia',
value: 11155111,
chainId: 11155111,
expectedEth: 0.002,
hex: '0xaa36a7',
},
{
name: 'Goerli',
label: 'Goerli',
value: 5,
chainId: 5,
expectedEth: 0.5,
hex: '0x5',
},
{
name: 'Mainnet',
label: 'Mainnet',
value: 1,
chainId: 1,
},
]

Expand Down Expand Up @@ -88,6 +91,11 @@ export const AggregatorVerifierAddress: { [key: string]: { [key: string]: string
sepolia: '0xfD74dce645Eb5EB65D818aeC544C72Ba325D93B0',
goerli: '0xbEF9572648284CB63a0DA32a89D3b4F2BeD65a89',
},
ORA_SINGLE: {
mainnet: '0x9B13520f499e95f7e94E8346Ed8F52D2F830d955',
sepolia: 'not support yet',
goerli: 'not support yet',
},
ORA: {
mainnet: 'not support yet',
sepolia: '0xf48dC1e1AaA6bB8cA43b03Ca0695973a2F440090',
Expand Down
9 changes: 9 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ export function getTargetNetwork(inputtedNetworkName: string) {
return targetNetwork
}

export function getNetworkNameByChainID(chainId: number) {
const netname = networks.find(
net => net.chainId === chainId,
)?.name
if (netname === undefined)
throw new Error('Unsupported network id')
return netname
}

/**
* normalize DSP params
* @param paramNames
Expand Down
2 changes: 1 addition & 1 deletion src/requests/ora_prove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function ora_prove(

// zkwasmhub doesn't accept aux_params

if (batchStyle === BatchStyle.ORA) {
if (batchStyle === BatchStyle.ORA || batchStyle === BatchStyle.ORA_SINGLE) {
if (proverUrl.startsWith(DEFAULT_URL.ZKWASMHUB))
throw new BatchStyleUnsupport('zkwasmhub doesn\'t support ORA batch style, use ProverType.ZKWASMHUB instead.')

Expand Down
1 change: 1 addition & 0 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ProofParams {

export enum BatchStyle {
ORA,
ORA_SINGLE,
ZKWASMHUB,
}
export interface BatchOption {
Expand Down
26 changes: 17 additions & 9 deletions tests/verify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { config } from './config'
(global as any).__BROWSER__ = false

const yamlPath = fixtures['dsp/ethereum(event)'].yamlPath
// const proveTaskId = 'QS2lHw1j6ZyxE2NSkwjt58kX' // ora prover proof
// const proveTaskId = 'v4YpdX4UufG89z2CwA26m0OS' // ora prover proof
const proveTaskId = '65dd7dad235cd47b5193efce' // zkwasmhub proof

describe('test verify', () => {
Expand All @@ -35,20 +35,28 @@ describe('test verify', () => {
it.only('test verify proof params', async () => {
const proofParams = await cleapi.getVerifyProofParamsByTaskID(config.ZkwasmProviderUrl, proveTaskId)
const network = 'sepolia'
// const sepolia_verifier = '0xDf0946992839A1f2B5aD09D001adF6C0332B1263' // ora verifier
const sepolia_verifier = '0xfD74dce645Eb5EB65D818aeC544C72Ba325D93B0' // zkwasmhub verifier
// const verifierAddress = '0x9B13520f499e95f7e94E8346Ed8F52D2F830d955' // ora verifier
// const verifierAddress = '0xfD74dce645Eb5EB65D818aeC544C72Ba325D93B0' // zkwasmhub verifier

expect(await cleapi.verifyProof(
proofParams,
{ verifierAddress: sepolia_verifier, provider: new ethers.providers.JsonRpcProvider(config.JsonRpcProviderUrl[network]) },
{
// verifierAddress,
provider: new ethers.providers.JsonRpcProvider(config.JsonRpcProviderUrl[network]),
// batchStyle: cleapi.BatchStyle.ORA_SINGLE
},
)).toBeTruthy()

/// / make a wrong proof for test
// proofParams.aggregate_proof[0] = 0x12
// expect(await cleapi.verifyProof(
// proofParams,
// { verifierAddress: sepolia_verifier, provider: new ethers.providers.JsonRpcProvider(rpcUrl) },
// )).toBeFalsy()
proofParams.aggregate_proof[0] = 0x12
expect(await cleapi.verifyProof(
proofParams,
{
// verifierAddress,
provider: new ethers.providers.JsonRpcProvider(config.JsonRpcProviderUrl[network]),
// batchStyle: cleapi.BatchStyle.ORA_SINGLE
},
)).toBeFalsy()
}, {
timeout: 1000000,
})
Expand Down

0 comments on commit 21800de

Please sign in to comment.