|
1 | 1 | package beacon |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "errors" |
4 | 5 | "reflect" |
5 | 6 |
|
6 | 7 | "github.com/Layr-Labs/eigenpod-proofs-generation/common" |
| 8 | + "github.com/attestantio/go-eth2-client/spec" |
7 | 9 | "github.com/attestantio/go-eth2-client/spec/phase0" |
8 | 10 | ) |
9 | 11 |
|
10 | | -type BeaconStateTopLevelRoots struct { |
| 12 | +type VersionedBeaconStateTopLevelRoots struct { |
| 13 | + Version spec.DataVersion |
| 14 | + Deneb *BeaconStateTopLevelRootsDeneb |
| 15 | + Electra *BeaconStateTopLevelRootsElectra |
| 16 | +} |
| 17 | + |
| 18 | +func (v *VersionedBeaconStateTopLevelRoots) GetBalancesRoot() (*phase0.Root, error) { |
| 19 | + switch v.Version { |
| 20 | + case spec.DataVersionDeneb: |
| 21 | + return v.Deneb.BalancesRoot, nil |
| 22 | + case spec.DataVersionElectra: |
| 23 | + return v.Electra.BalancesRoot, nil |
| 24 | + default: |
| 25 | + return nil, errors.New("unsupported beacon state version") |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +type BeaconStateTopLevelRootsDeneb struct { |
11 | 30 | GenesisTimeRoot *phase0.Root |
12 | 31 | GenesisValidatorsRoot *phase0.Root |
13 | 32 | SlotRoot *phase0.Root |
@@ -38,18 +57,71 @@ type BeaconStateTopLevelRoots struct { |
38 | 57 | HistoricalSummariesRoot *phase0.Root |
39 | 58 | } |
40 | 59 |
|
41 | | -func ProveBeaconTopLevelRootAgainstBeaconState(beaconTopLevelRoots *BeaconStateTopLevelRoots, index uint64) (common.Proof, error) { |
42 | | - v := reflect.ValueOf(*beaconTopLevelRoots) |
| 60 | +type BeaconStateTopLevelRootsElectra struct { |
| 61 | + GenesisTimeRoot *phase0.Root |
| 62 | + GenesisValidatorsRoot *phase0.Root |
| 63 | + SlotRoot *phase0.Root |
| 64 | + ForkRoot *phase0.Root |
| 65 | + LatestBlockHeaderRoot *phase0.Root |
| 66 | + BlockRootsRoot *phase0.Root |
| 67 | + StateRootsRoot *phase0.Root |
| 68 | + HistoricalRootsRoot *phase0.Root |
| 69 | + ETH1DataRoot *phase0.Root |
| 70 | + ETH1DataVotesRoot *phase0.Root |
| 71 | + ETH1DepositIndexRoot *phase0.Root |
| 72 | + ValidatorsRoot *phase0.Root |
| 73 | + BalancesRoot *phase0.Root |
| 74 | + RANDAOMixesRoot *phase0.Root |
| 75 | + SlashingsRoot *phase0.Root |
| 76 | + PreviousEpochParticipationRoot *phase0.Root |
| 77 | + CurrentEpochParticipationRoot *phase0.Root |
| 78 | + JustificationBitsRoot *phase0.Root |
| 79 | + PreviousJustifiedCheckpointRoot *phase0.Root |
| 80 | + CurrentJustifiedCheckpointRoot *phase0.Root |
| 81 | + FinalizedCheckpointRoot *phase0.Root |
| 82 | + InactivityScoresRoot *phase0.Root |
| 83 | + CurrentSyncCommitteeRoot *phase0.Root |
| 84 | + NextSyncCommitteeRoot *phase0.Root |
| 85 | + LatestExecutionPayloadHeaderRoot *phase0.Root |
| 86 | + NextWithdrawalIndexRoot *phase0.Root |
| 87 | + NextWithdrawalValidatorIndexRoot *phase0.Root |
| 88 | + HistoricalSummariesRoot *phase0.Root |
| 89 | + DepositRequestsStartIndexRoot *phase0.Root |
| 90 | + DepositBalanceToConsumeRoot *phase0.Root |
| 91 | + ExitBalanceToConsumeRoot *phase0.Root |
| 92 | + EarliestExitEpochRoot *phase0.Root |
| 93 | + ConsolidationBalanceToConsumeRoot *phase0.Root |
| 94 | + EarliestConsolidationEpochRoot *phase0.Root |
| 95 | + PendingDepositsRoot *phase0.Root |
| 96 | + PendingPartialWithdrawalsRoot *phase0.Root |
| 97 | + PendingConsolidationsRoot *phase0.Root |
| 98 | +} |
| 99 | + |
| 100 | +func ProveBeaconTopLevelRootAgainstBeaconState(beaconTopLevelRoots *VersionedBeaconStateTopLevelRoots, index uint64) (common.Proof, error) { |
| 101 | + var v reflect.Value |
| 102 | + var treeHeight uint64 |
| 103 | + switch beaconTopLevelRoots.Version { |
| 104 | + case spec.DataVersionDeneb: |
| 105 | + v = reflect.ValueOf(*beaconTopLevelRoots.Deneb) |
| 106 | + treeHeight = BEACON_STATE_TREE_HEIGHT_DENEB |
| 107 | + case spec.DataVersionElectra: |
| 108 | + v = reflect.ValueOf(*beaconTopLevelRoots.Electra) |
| 109 | + treeHeight = BEACON_STATE_TREE_HEIGHT_ELECTRA |
| 110 | + default: |
| 111 | + return nil, errors.New("unsupported beacon state version") |
| 112 | + } |
| 113 | + |
43 | 114 | beaconTopLevelRootsList := make([]interface{}, v.NumField()) |
44 | 115 | for i := 0; i < v.NumField(); i++ { |
45 | 116 | r := v.Field(i).Interface() |
46 | 117 | typedR := r.(*phase0.Root) |
47 | 118 | beaconTopLevelRootsList[i] = *typedR |
48 | 119 | } |
| 120 | + |
49 | 121 | roots := make([]phase0.Root, len(beaconTopLevelRootsList)) |
50 | 122 | for i, v := range beaconTopLevelRootsList { |
51 | 123 | roots[i] = v.(phase0.Root) |
52 | 124 | } |
53 | 125 |
|
54 | | - return common.GetProof(roots, index, BEACON_STATE_TREE_HEIGHT) |
| 126 | + return common.GetProof(roots, index, treeHeight) |
55 | 127 | } |
0 commit comments