Skip to content

Commit 265fa75

Browse files
authored
Merge pull request #18 from lidofinance/feat/gi-first-validator
Feat/gi first validator
2 parents b22972e + 3de34a0 commit 265fa75

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

programs/predeposit-guarantee.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { program } from 'command';
22
import { getCLProofVerifierContract } from 'contracts';
33

4-
import { createPDGProof } from 'utils/index.js';
4+
import { createPDGProof, getFirstValidatorGIndex } from 'utils/index.js';
55

66
const predepositGuarantee = program
77
.command('pdg')
88
.description('predeposit guarantee contract');
99

1010
predepositGuarantee
11-
.command('create-proof')
12-
.description('create predeposit proof')
11+
.command('create-proof-and-check')
12+
.description(
13+
'create predeposit proof by validator index and check by test contract',
14+
)
1315
.argument('<validator-index>', 'validator index')
1416
.action(async (validatorIndex: bigint) => {
1517
const clProofVerifierContract = getCLProofVerifierContract();
@@ -18,7 +20,6 @@ predepositGuarantee
1820
const { proof, pubkey, childBlockTimestamp, withdrawalCredentials } =
1921
packageProof;
2022

21-
// verification by test contract
2223
await clProofVerifierContract.read.TEST_validatePubKeyWCProof([
2324
{ proof, pubkey, validatorIndex, childBlockTimestamp },
2425
withdrawalCredentials,
@@ -37,3 +38,34 @@ predepositGuarantee
3738
console.info('------------------------------------------------');
3839
console.info('-----------------------end-----------------------');
3940
});
41+
42+
predepositGuarantee
43+
.command('create-proof')
44+
.description('create predeposit proof by validator index')
45+
.argument('<validator-index>', 'validator index')
46+
.action(async (validatorIndex: bigint) => {
47+
const packageProof = await createPDGProof(Number(validatorIndex));
48+
const { proof, pubkey, childBlockTimestamp, withdrawalCredentials } =
49+
packageProof;
50+
51+
console.info('-----------------proof verified-----------------');
52+
console.info('------------------------------------------------');
53+
console.info('----------------------proof----------------------');
54+
console.info(proof);
55+
console.info('---------------------pubkey---------------------');
56+
console.table(pubkey);
57+
console.info('---------------childBlockTimestamp---------------');
58+
console.table(childBlockTimestamp);
59+
console.info('--------------withdrawalCredentials--------------');
60+
console.table(withdrawalCredentials);
61+
console.info('------------------------------------------------');
62+
console.info('-----------------------end-----------------------');
63+
});
64+
65+
predepositGuarantee
66+
.command('fv-gindex')
67+
.argument('<forks...>', 'fork name')
68+
.description('get first validator gindex')
69+
.action(async (forks: string[]) => {
70+
getFirstValidatorGIndex(forks);
71+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { ssz } from '@lodestar/types';
2+
3+
const SupportedFork = {
4+
deneb: 'deneb',
5+
electra: 'electra',
6+
};
7+
8+
export const getFirstValidatorGIndex = (forks: string[]) => {
9+
const gIndexes: Record<string, string> = {};
10+
for (const fork of forks) {
11+
const Fork = ssz[fork as keyof typeof SupportedFork];
12+
const Validators = Fork.BeaconState.getPathInfo(['validators']).type;
13+
14+
const gI = pack(
15+
Fork.BeaconState.getPathInfo(['validators', 0]).gindex,
16+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
17+
// @ts-ignore
18+
Validators.limit,
19+
);
20+
gIndexes[fork] = toBytes32String(gI);
21+
}
22+
console.table(gIndexes);
23+
};
24+
25+
const pack = (gI: bigint, limit: number) => {
26+
const width = limit ? BigInt(Math.log2(limit)) : 0n;
27+
return (gI << 8n) | width;
28+
};
29+
30+
const toBytes32String = (gI: bigint) => {
31+
return `0x${gI.toString(16).padStart(64, '0')}`;
32+
};

utils/proof/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './merkle-utils.js';
22
export * from './create-proof.js';
3+
export * from './first-validator-gindex.js';

0 commit comments

Comments
 (0)