|
1 | 1 | package eigenpodproofs_test |
2 | 2 |
|
3 | | -// func TestValidatorContainersProofOnChain(t *testing.T) { |
4 | | -// validators, err := beaconState.Validators() |
5 | | -// if err != nil { |
6 | | -// t.Fatal(err) |
7 | | -// } |
8 | | - |
9 | | -// validatorIndices := []uint64{} |
10 | | -// for i := int(0); i < len(validators); i += 100000000 { |
11 | | -// validatorIndices = append(validatorIndices, uint64(i)) |
12 | | -// } |
13 | | - |
14 | | -// verifyValidatorFieldsCallParams, err := epp.ProveValidatorContainers(beaconHeader, beaconState, validatorIndices) |
15 | | -// if err != nil { |
16 | | -// t.Fatal(err) |
17 | | -// } |
18 | | - |
19 | | -// blockRoot, err := beaconHeader.HashTreeRoot() |
20 | | -// if err != nil { |
21 | | -// t.Fatal(err) |
22 | | -// } |
23 | | - |
24 | | -// err = beaconChainProofsWrapper.VerifyStateRoot( |
25 | | -// &bind.CallOpts{}, |
26 | | -// blockRoot, |
27 | | -// BeaconChainProofsWrapper.BeaconChainProofsStateRootProof{ |
28 | | -// BeaconStateRoot: verifyValidatorFieldsCallParams.StateRootProof.BeaconStateRoot, |
29 | | -// Proof: verifyValidatorFieldsCallParams.StateRootProof.Proof.ToByteSlice(), |
30 | | -// }, |
31 | | -// ) |
32 | | -// assert.Nil(t, err) |
33 | | - |
34 | | -// for i := 0; i < len(verifyValidatorFieldsCallParams.ValidatorFields); i++ { |
35 | | -// validatorFields := [][32]byte{} |
36 | | -// for _, field := range verifyValidatorFieldsCallParams.ValidatorFields[i] { |
37 | | -// validatorFields = append(validatorFields, field) |
38 | | -// } |
39 | | - |
40 | | -// err = beaconChainProofsWrapper.VerifyValidatorFields( |
41 | | -// &bind.CallOpts{}, |
42 | | -// uint64(0), |
43 | | -// verifyValidatorFieldsCallParams.StateRootProof.BeaconStateRoot, |
44 | | -// validatorFields, |
45 | | -// verifyValidatorFieldsCallParams.ValidatorFieldsProofs[i].ToByteSlice(), |
46 | | -// new(big.Int).SetUint64(verifyValidatorFieldsCallParams.ValidatorIndices[i]), |
47 | | -// ) |
48 | | -// assert.Nil(t, err) |
49 | | -// } |
50 | | -// } |
51 | | - |
52 | | -// func TestValidatorBalancesProofOnChain(t *testing.T) { |
53 | | -// validators, err := beaconState.Validators() |
54 | | -// if err != nil { |
55 | | -// t.Fatal(err) |
56 | | -// } |
57 | | - |
58 | | -// validatorIndices := []uint64{} |
59 | | -// for i := int(0); i < len(validators); i += 100000000 { |
60 | | -// validatorIndices = append(validatorIndices, uint64(i)) |
61 | | -// } |
62 | | - |
63 | | -// verifyCheckpointProofsCallParams, err := epp.ProveCheckpointProofs(beaconHeader, beaconState, validatorIndices) |
64 | | -// if err != nil { |
65 | | -// t.Fatal(err) |
66 | | -// } |
67 | | - |
68 | | -// blockRoot, err := beaconHeader.HashTreeRoot() |
69 | | -// if err != nil { |
70 | | -// t.Fatal(err) |
71 | | -// } |
72 | | - |
73 | | -// err = beaconChainProofsWrapper.VerifyBalanceContainer( |
74 | | -// &bind.CallOpts{}, |
75 | | -// uint64(0), |
76 | | -// blockRoot, |
77 | | -// BeaconChainProofsWrapper.BeaconChainProofsBalanceContainerProof{ |
78 | | -// BalanceContainerRoot: verifyCheckpointProofsCallParams.ValidatorBalancesRootProof.ValidatorBalancesRoot, |
79 | | -// Proof: verifyCheckpointProofsCallParams.ValidatorBalancesRootProof.Proof.ToByteSlice(), |
80 | | -// }, |
81 | | -// ) |
82 | | -// assert.Nil(t, err) |
83 | | - |
84 | | -// for i := 0; i < len(verifyCheckpointProofsCallParams.BalanceProofs); i++ { |
85 | | -// _, err = beaconChainProofsWrapper.VerifyValidatorBalance( |
86 | | -// &bind.CallOpts{}, |
87 | | -// verifyCheckpointProofsCallParams.ValidatorBalancesRootProof.ValidatorBalancesRoot, |
88 | | -// new(big.Int).SetUint64(validatorIndices[i]), |
89 | | -// BeaconChainProofsWrapper.BeaconChainProofsBalanceProof{ |
90 | | -// PubkeyHash: verifyCheckpointProofsCallParams.BalanceProofs[i].PubkeyHash, |
91 | | -// BalanceRoot: verifyCheckpointProofsCallParams.BalanceProofs[i].BalanceRoot, |
92 | | -// Proof: verifyCheckpointProofsCallParams.BalanceProofs[i].Proof.ToByteSlice(), |
93 | | -// }, |
94 | | -// ) |
95 | | -// assert.Nil(t, err) |
96 | | -// } |
97 | | -// } |
| 3 | +import ( |
| 4 | + "math/big" |
| 5 | + "testing" |
| 6 | + |
| 7 | + BeaconChainProofsWrapper "github.com/Layr-Labs/eigenpod-proofs-generation/bindings/BeaconChainProofsWrapper" |
| 8 | + "github.com/attestantio/go-eth2-client/spec" |
| 9 | + "github.com/ethereum/go-ethereum/accounts/abi/bind" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | +) |
| 12 | + |
| 13 | +func TestValidatorContainersProofOnChain(t *testing.T) { |
| 14 | + validators, err := beaconState.Validators() |
| 15 | + if err != nil { |
| 16 | + t.Fatal(err) |
| 17 | + } |
| 18 | + |
| 19 | + validatorIndices := []uint64{} |
| 20 | + for i := int(0); i < len(validators); i += 100000 { |
| 21 | + validatorIndices = append(validatorIndices, uint64(i)) |
| 22 | + } |
| 23 | + |
| 24 | + verifyValidatorFieldsCallParams, err := epp.ProveValidatorContainers(beaconHeader, beaconState, validatorIndices) |
| 25 | + if err != nil { |
| 26 | + t.Fatal(err) |
| 27 | + } |
| 28 | + |
| 29 | + blockRoot, err := beaconHeader.HashTreeRoot() |
| 30 | + if err != nil { |
| 31 | + t.Fatal(err) |
| 32 | + } |
| 33 | + |
| 34 | + err = beaconChainProofsWrapper.VerifyStateRoot( |
| 35 | + &bind.CallOpts{}, |
| 36 | + blockRoot, |
| 37 | + BeaconChainProofsWrapper.BeaconChainProofsStateRootProof{ |
| 38 | + BeaconStateRoot: verifyValidatorFieldsCallParams.StateRootProof.BeaconStateRoot, |
| 39 | + Proof: verifyValidatorFieldsCallParams.StateRootProof.Proof.ToByteSlice(), |
| 40 | + }, |
| 41 | + ) |
| 42 | + assert.Nil(t, err) |
| 43 | + |
| 44 | + // Update the proof timestamp depending on the beacon state version |
| 45 | + var proofTimestamp uint64 |
| 46 | + if beaconState.Version == spec.DataVersionElectra { |
| 47 | + proofTimestamp = uint64(1730822401) // 1 second after mekong genesis |
| 48 | + } else { |
| 49 | + proofTimestamp = uint64(0) |
| 50 | + } |
| 51 | + |
| 52 | + for i := 0; i < len(verifyValidatorFieldsCallParams.ValidatorFields); i++ { |
| 53 | + validatorFields := [][32]byte{} |
| 54 | + for _, field := range verifyValidatorFieldsCallParams.ValidatorFields[i] { |
| 55 | + validatorFields = append(validatorFields, field) |
| 56 | + } |
| 57 | + |
| 58 | + err = beaconChainProofsWrapper.VerifyValidatorFields( |
| 59 | + &bind.CallOpts{}, |
| 60 | + proofTimestamp, |
| 61 | + verifyValidatorFieldsCallParams.StateRootProof.BeaconStateRoot, |
| 62 | + validatorFields, |
| 63 | + verifyValidatorFieldsCallParams.ValidatorFieldsProofs[i].ToByteSlice(), |
| 64 | + new(big.Int).SetUint64(verifyValidatorFieldsCallParams.ValidatorIndices[i]), |
| 65 | + ) |
| 66 | + assert.Nil(t, err) |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +func TestValidatorBalancesProofOnChain(t *testing.T) { |
| 71 | + validators, err := beaconState.Validators() |
| 72 | + if err != nil { |
| 73 | + t.Fatal(err) |
| 74 | + } |
| 75 | + |
| 76 | + validatorIndices := []uint64{} |
| 77 | + for i := int(0); i < len(validators); i += 100000 { |
| 78 | + validatorIndices = append(validatorIndices, uint64(i)) |
| 79 | + } |
| 80 | + |
| 81 | + verifyCheckpointProofsCallParams, err := epp.ProveCheckpointProofs(beaconHeader, beaconState, validatorIndices) |
| 82 | + if err != nil { |
| 83 | + t.Fatal(err) |
| 84 | + } |
| 85 | + |
| 86 | + blockRoot, err := beaconHeader.HashTreeRoot() |
| 87 | + if err != nil { |
| 88 | + t.Fatal(err) |
| 89 | + } |
| 90 | + |
| 91 | + // Update the proof timestamp depending on the beacon state version |
| 92 | + var proofTimestamp uint64 |
| 93 | + if beaconState.Version == spec.DataVersionElectra { |
| 94 | + proofTimestamp = uint64(1730822401) // 1 second after mekong genesis |
| 95 | + } else { |
| 96 | + proofTimestamp = uint64(0) |
| 97 | + } |
| 98 | + |
| 99 | + err = beaconChainProofsWrapper.VerifyBalanceContainer( |
| 100 | + &bind.CallOpts{}, |
| 101 | + proofTimestamp, |
| 102 | + blockRoot, |
| 103 | + BeaconChainProofsWrapper.BeaconChainProofsBalanceContainerProof{ |
| 104 | + BalanceContainerRoot: verifyCheckpointProofsCallParams.ValidatorBalancesRootProof.ValidatorBalancesRoot, |
| 105 | + Proof: verifyCheckpointProofsCallParams.ValidatorBalancesRootProof.Proof.ToByteSlice(), |
| 106 | + }, |
| 107 | + ) |
| 108 | + assert.Nil(t, err) |
| 109 | + |
| 110 | + for i := 0; i < len(verifyCheckpointProofsCallParams.BalanceProofs); i++ { |
| 111 | + _, err = beaconChainProofsWrapper.VerifyValidatorBalance( |
| 112 | + &bind.CallOpts{}, |
| 113 | + verifyCheckpointProofsCallParams.ValidatorBalancesRootProof.ValidatorBalancesRoot, |
| 114 | + new(big.Int).SetUint64(validatorIndices[i]), |
| 115 | + BeaconChainProofsWrapper.BeaconChainProofsBalanceProof{ |
| 116 | + PubkeyHash: verifyCheckpointProofsCallParams.BalanceProofs[i].PubkeyHash, |
| 117 | + BalanceRoot: verifyCheckpointProofsCallParams.BalanceProofs[i].BalanceRoot, |
| 118 | + Proof: verifyCheckpointProofsCallParams.BalanceProofs[i].Proof.ToByteSlice(), |
| 119 | + }, |
| 120 | + ) |
| 121 | + assert.Nil(t, err) |
| 122 | + } |
| 123 | +} |
0 commit comments