Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deneb cleanup #22

Merged
merged 15 commits into from
Jan 25, 2024
Binary file modified .DS_Store
Binary file not shown.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ data/deneb_slot_7426414.json
data/deneb_goerli_slot_7416760.json
data/deneb_goerli_slot_7413760.json
data/deneb_goerli_slot_7421952.json
data/deneb_goerli_slot_7431952.json
data/deneb_goerli_slot_7431952.json

generation/proofGenCLI

solidityProofGen/solidityProofGen
56 changes: 56 additions & 0 deletions beacon/beacon_state_top_level_roots.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package beacon

import (
"reflect"

"github.com/Layr-Labs/eigenpod-proofs-generation/common"
"github.com/attestantio/go-eth2-client/spec/phase0"
)

type BeaconStateTopLevelRoots struct {
GenesisTimeRoot *phase0.Root
GenesisValidatorsRoot *phase0.Root
SlotRoot *phase0.Root
ForkRoot *phase0.Root
LatestBlockHeaderRoot *phase0.Root
BlockRootsRoot *phase0.Root
StateRootsRoot *phase0.Root
HistoricalRootsRoot *phase0.Root
ETH1DataRoot *phase0.Root
ETH1DataVotesRoot *phase0.Root
ETH1DepositIndexRoot *phase0.Root
ValidatorsRoot *phase0.Root
BalancesRoot *phase0.Root
RANDAOMixesRoot *phase0.Root
SlashingsRoot *phase0.Root
PreviousEpochParticipationRoot *phase0.Root
CurrentEpochParticipationRoot *phase0.Root
JustificationBitsRoot *phase0.Root
PreviousJustifiedCheckpointRoot *phase0.Root
CurrentJustifiedCheckpointRoot *phase0.Root
FinalizedCheckpointRoot *phase0.Root
InactivityScoresRoot *phase0.Root
CurrentSyncCommitteeRoot *phase0.Root
NextSyncCommitteeRoot *phase0.Root
LatestExecutionPayloadHeaderRoot *phase0.Root
NextWithdrawalIndexRoot *phase0.Root
NextWithdrawalValidatorIndexRoot *phase0.Root
HistoricalSummariesRoot *phase0.Root
}

func ProveBeaconTopLevelRootAgainstBeaconState(beaconTopLevelRoots *BeaconStateTopLevelRoots, index uint64) (common.Proof, error) {
v := reflect.ValueOf(*beaconTopLevelRoots)
beaconTopLevelRootsList := make([]interface{}, v.NumField())
for i := 0; i < v.NumField(); i++ {
r := v.Field(i).Interface()
typedR := r.(*phase0.Root)
beaconTopLevelRootsList[i] = *typedR

}
roots := make([]phase0.Root, len(beaconTopLevelRootsList))
for i, v := range beaconTopLevelRootsList {
roots[i] = v.(phase0.Root)
}

return common.GetProof(roots, index, beaconStateMerkleSubtreeNumLayers)
}
65 changes: 65 additions & 0 deletions beacon/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package beacon

import (
"github.com/Layr-Labs/eigenpod-proofs-generation/common"
"github.com/attestantio/go-eth2-client/spec/phase0"
ssz "github.com/ferranbt/fastssz"
)

func ProveBlockBodyAgainstBlockHeader(blockHeader *phase0.BeaconBlockHeader) (common.Proof, error) {
blockHeaderContainerRoots, err := GetBlockHeaderFieldRoots(blockHeader)

if err != nil {
return nil, err
}

return common.GetProof(blockHeaderContainerRoots, BeaconBlockBodyRootIndex, blockHeaderMerkleSubtreeNumLayers)
}

// refer to this: https://github.com/attestantio/go-eth2-client/blob/654ac05b4c534d96562329f988655e49e5743ff5/spec/phase0/beaconblockheader_encoding.go
func ProveStateRootAgainstBlockHeader(b *phase0.BeaconBlockHeader) (common.Proof, error) {

beaconBlockHeaderContainerRoots, err := GetBlockHeaderFieldRoots(b)
if err != nil {
return nil, err
}

return common.GetProof(beaconBlockHeaderContainerRoots, stateRootIndex, blockHeaderMerkleSubtreeNumLayers)
}

func ProveSlotAgainstBlockHeader(blockHeader *phase0.BeaconBlockHeader) (common.Proof, error) {
blockHeaderContainerRoots, err := GetBlockHeaderFieldRoots(blockHeader)
if err != nil {
return nil, err
}

return common.GetProof(blockHeaderContainerRoots, SlotIndex, blockHeaderMerkleSubtreeNumLayers)
}

func GetBlockHeaderFieldRoots(blockHeader *phase0.BeaconBlockHeader) ([]phase0.Root, error) {
blockHeaderContainerRoots := make([]phase0.Root, beaconBlockHeaderNumFields)

hh := ssz.NewHasher()

hh.PutUint64(uint64(blockHeader.Slot))
copy(blockHeaderContainerRoots[0][:], hh.Hash())
hh.Reset()

hh.PutUint64(uint64(blockHeader.ProposerIndex))
copy(blockHeaderContainerRoots[1][:], hh.Hash())
hh.Reset()

hh.PutBytes(blockHeader.ParentRoot[:])
copy(blockHeaderContainerRoots[2][:], hh.Hash())
hh.Reset()

hh.PutBytes(blockHeader.StateRoot[:])
copy(blockHeaderContainerRoots[3][:], hh.Hash())
hh.Reset()

hh.PutBytes(blockHeader.BodyRoot[:])
copy(blockHeaderContainerRoots[4][:], hh.Hash())
hh.Reset()

return blockHeaderContainerRoots, nil
}
Loading
Loading