Skip to content

Commit

Permalink
Update comments. Add synCommittePoseidon logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ltyu committed Mar 11, 2024
1 parent e679be0 commit 9929125
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
2 changes: 2 additions & 0 deletions solidity/contracts/interfaces/ccip-gateways/ILightClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ interface ILightClient {
function GENESIS_TIME() external view returns (uint256);

function SECONDS_PER_SLOT() external view returns (uint256);

function SLOTS_PER_PERIOD() external view returns (uint256);
}
6 changes: 3 additions & 3 deletions typescript/ccip-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import { ProofsService } from './services/ProofsService';

// Initalize Services
const proofsService = new ProofsService(
// succinctConfig
// SuccinctConfig
{
stepFunctionId: config.STEP_FN_ID,
lightClientAddress: config.LIGHT_CLIENT_ADDR,
apiKey: config.SUCCINCT_API_KEY,
platformUrl: config.SUCCINCT_PLATFORM_URL,
chainId: config.CHAIN_ID,
},
// rpcConfig
// RpcConfig
{
url: config.RPC_ADDRESS,
chainId: config.CHAIN_ID,
},
// hyperlaneConfig
// HyperlaneConfig
{
url: config.HYPERLANE_API_URL,
},
Expand Down
30 changes: 19 additions & 11 deletions typescript/ccip-server/src/services/LightClientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ILightClient } from '../../../../solidity/types';
import { ILightClient__factory } from '../../../../solidity/types';
import { TelepathyCcipReadIsmAbi } from '../abis/TelepathyCcipReadIsmAbi';

import { ProofStatus } from './common/ProofStatusEnum';
import { ProofStatus } from './constants/ProofStatusEnum';

export type SuccinctConfig = {
readonly lightClientAddress: string;
Expand All @@ -28,23 +28,27 @@ class LightClientService {
);
}

private getSyncCommitteePeriod(slot: bigint): bigint {
return slot / 8192n; // Slots Per Period
/**
* Calculates period, given a slot
* @dev Src: https://github.com/succinctlabs/telepathyx/blob/main/src/operatorx/operator.ts#L20-L22
* @param slot
*/
async getSyncCommitteePeriod(slot: BigNumber): Promise<BigNumber> {
return slot.div(await this.lightClientContract.SLOTS_PER_PERIOD());
}

/**
* Gets syncCommitteePoseidons from ISM/LightClient
* Calculates the sync committee poseidon from the LightClient, given a slot
* @param slot
* @returns
*/
async getSyncCommitteePoseidons(slot: bigint): Promise<string> {
async getSyncCommitteePoseidons(slot: BigNumber): Promise<string> {
return await this.lightClientContract.syncCommitteePoseidons(
this.getSyncCommitteePeriod(slot),
await this.getSyncCommitteePeriod(slot),
);
}

/**
* Calculates the slot given a timestamp, and the LightClient's configured Genesis Time and Secods Per Slot
* Calculates the slot, given a timestamp, and the LightClient's configured Genesis Time and Secods Per Slot
* @param timestamp timestamp to calculate slot with
*/
async calculateSlot(timestamp: BigNumber): Promise<BigNumber> {
Expand All @@ -54,7 +58,7 @@ class LightClientService {
}

/**
* Request the proof from Succinct.
* Request the ZK proof from Succinct, given the sync committee poseidon, and a slot
* @param slot
* @param syncCommitteePoseidon
*/
Expand Down Expand Up @@ -91,13 +95,17 @@ class LightClientService {
return responseAsJson.proof_id;
}

// @dev in the case of when a proof doesn't exist, the request returns an object of { error: 'failed to get proof' }.
// Example: GET https://alpha.succinct.xyz/api/proof/4dfd2802-4edf-4c4f-91db-b2d05eb69791
/**
* Check on the status of the ZK proof from Succinct.
* @param proofId
*/
async getProofStatus(proofId: string): Promise<ProofStatus> {
const response = await fetch(
`${this.succinctConfig.platformUrl}/${proofId}`,
);
const responseAsJson = await response.json();
// @dev in the case of when a proof doesn't exist, the request returns an object of { error: 'failed to get proof' }.
// Example: GET https://alpha.succinct.xyz/api/proof/4dfd2802-4edf-4c4f-91db-b2d05eb69791
return responseAsJson.status ?? ProofStatus.error;
}
}
Expand Down
9 changes: 5 additions & 4 deletions typescript/ccip-server/src/services/ProofsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BigNumber, ethers } from 'ethers';
import { HyperlaneService } from './HyperlaneService';
import { LightClientService, SuccinctConfig } from './LightClientService';
import { ProofResult, RPCService } from './RPCService';
import { ProofStatus } from './common/ProofStatusEnum';
import { ProofStatus } from './constants/ProofStatusEnum';

type RPCConfig = {
readonly url: string;
Expand Down Expand Up @@ -70,7 +70,7 @@ class ProofsService {
);
if (proofStatus === ProofStatus.success) {
// Succinct Proof is ready.
// This means that the LightClient should have the latest state root. Fetch and return the storage proofs from eth_getProof
// This means that the LightClient should have the latest state root. Proceed to fetch and return the storage proofs from eth_getProof
proofs.push(await this.getStorageProofs(target, storageKey, messageId));
this.pendingProof.delete(pendingProofKey);
} else {
Expand All @@ -82,7 +82,7 @@ class ProofsService {
}

/**
* Requests the Succinct proof
* Requests the Succinct ZK proof
* @param messageId messageId that will be used to get the block info from hyperlane
* @returns the proofId
*/
Expand All @@ -93,7 +93,8 @@ class ProofsService {
const slot = await this.lightClientService.calculateSlot(
BigNumber.from(timestamp),
);
const syncCommitteePoseidon = ''; // TODO get from LC
const syncCommitteePoseidon =
await this.lightClientService.getSyncCommitteePoseidons(slot);
return await this.lightClientService.requestProof(
syncCommitteePoseidon,
slot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LightClientService {
async calculateSlot(timestamp: BigNumber): Promise<BigNumber> {
return timestamp
.sub(BigNumber.from(genesisTime))
.div(BigNumber.from(slotsPerSecond)); // (timestamp - GENESIS TIME) / SLOTS_PER_SECOND
.div(BigNumber.from(slotsPerSecond));
}

async requestProof(
Expand All @@ -24,6 +24,10 @@ class LightClientService {
return 'pendingProofId12';
}

async getSyncCommitteePoseidons(slot: BigNumber): Promise<string> {
return '0x00ccb5d015f534ff595c2a31c425afcccfff08107c7f7a581cc1d4f27c307aa2';
}

async getProofStatus(pendingProofId: string): Promise<ProofStatus> {
return ProofStatus.success;
}
Expand Down
1 change: 1 addition & 0 deletions typescript/ccip-server/tests/services/RPCService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('RPCService', () => {
'0x1221E88',
);

// This just returns the mocked data
expect(proofs).not.toBeNull();
});
});

0 comments on commit 9929125

Please sign in to comment.