Skip to content

Commit

Permalink
updated to deneb, code building
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidu28 committed Jan 19, 2024
1 parent ab932f5 commit 606a3f3
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 37 deletions.
6 changes: 3 additions & 3 deletions generate_balance_update_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import (
"encoding/json"
"os"

"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/rs/zerolog/log"
)

func GenerateBalanceUpdateProof(oracleBlockHeaderFile string, stateFile string, validatorIndex uint64, chainID uint64, output string) {

var state capella.BeaconState
var state deneb.BeaconState
var oracleBeaconBlockHeader phase0.BeaconBlockHeader
stateJSON, err := parseStateJSONFile(stateFile)
if err != nil {
log.Debug().AnErr("GenerateBalanceUpdateProof: error with JSON parsing", err)
}
ParseCapellaBeaconStateFromJSON(*stateJSON, &state)
ParseDenebBeaconStateFromJSON(*stateJSON, &state)

oracleBeaconBlockHeader, err = ExtractBlockHeader(oracleBlockHeaderFile)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion generate_validator_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func GenerateValidatorFieldsProof(oracleBlockHeaderFile string, stateFile string
if err != nil {
log.Debug().Msg("GenerateValidatorFieldsProof: error with JSON parsing")
}
ParseCapellaBeaconStateFromJSON(*stateJSON, &state)
ParseDenebBeaconStateFromJSON(*stateJSON, &state)

oracleBeaconBlockHeader, err = ExtractBlockHeader(oracleBlockHeaderFile)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions generate_withdrawal_fields_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"os"

"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
ssz "github.com/ferranbt/fastssz"
"github.com/rs/zerolog/log"
Expand All @@ -29,10 +29,10 @@ func GenerateWithdrawalFieldsProof(
//this is the oracle provided state
var oracleBeaconBlockHeader phase0.BeaconBlockHeader
//this is the state with the withdrawal in it
var state capella.BeaconState
var historicalSummaryState capella.BeaconState
var state deneb.BeaconState
var historicalSummaryState deneb.BeaconState
var withdrawalBlockHeader phase0.BeaconBlockHeader
var withdrawalBlock capella.BeaconBlock
var withdrawalBlock deneb.BeaconBlock

oracleBeaconBlockHeader, err := ExtractBlockHeader(oracleBlockHeaderFile)

Expand All @@ -47,13 +47,13 @@ func GenerateWithdrawalFieldsProof(
if err != nil {
log.Debug().AnErr("GenerateWithdrawalFieldsProof: error with JSON parsing state file", err)
}
ParseCapellaBeaconStateFromJSON(*stateJSON, &state)
ParseDenebBeaconStateFromJSON(*stateJSON, &state)

historicalSummaryJSON, err := parseStateJSONFile(historicalSummaryStateFile)
if err != nil {
log.Debug().AnErr("GenerateWithdrawalFieldsProof: error with JSON parsing historical summary state file", err)
}
ParseCapellaBeaconStateFromJSON(*historicalSummaryJSON, &historicalSummaryState)
ParseDenebBeaconStateFromJSON(*historicalSummaryJSON, &historicalSummaryState)

withdrawalBlockHeader, err = ExtractBlockHeader(blockHeaderFile)
if err != nil {
Expand Down
21 changes: 10 additions & 11 deletions merkle_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ import (
ssz "github.com/ferranbt/fastssz"
"github.com/stretchr/testify/assert"

"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
)

var (
b capella.BeaconState
b deneb.BeaconState
blockHeader phase0.BeaconBlockHeader
blockHeaderIndex uint64
block capella.BeaconBlock
block deneb.BeaconBlock
validatorIndex phase0.ValidatorIndex
beaconBlockHeaderToVerifyIndex uint64
executionPayload deneb.ExecutionPayload
Expand Down Expand Up @@ -67,7 +66,7 @@ func setupSuite() {
if err != nil {
fmt.Println("error with JSON parsing beacon state")
}
ParseCapellaBeaconStateFromJSON(*stateJSON, &b)
ParseDenebBeaconStateFromJSON(*stateJSON, &b)

blockHeader, err = ExtractBlockHeader(headerFile)
if err != nil {
Expand Down Expand Up @@ -206,11 +205,11 @@ func TestGetHistoricalSummariesBlockRootsProofProof(t *testing.T) {
fmt.Println("blockHeader.UnmarshalJSON error", err)
}

var currentBeaconState capella.BeaconState
var oldBeaconState capella.BeaconState
var currentBeaconState deneb.BeaconState
var oldBeaconState deneb.BeaconState

ParseCapellaBeaconStateFromJSON(*currentBeaconStateJSON, &currentBeaconState)
ParseCapellaBeaconStateFromJSON(*oldBeaconStateJSON, &oldBeaconState)
ParseDenebBeaconStateFromJSON(*currentBeaconStateJSON, &currentBeaconState)
ParseDenebBeaconStateFromJSON(*oldBeaconStateJSON, &oldBeaconState)

currentBeaconStateTopLevelRoots, _ := ComputeBeaconStateTopLevelRoots(&currentBeaconState)
//oldBeaconStateTopLevelRoots, _ := ComputeBeaconStateTopLevelRoots(&oldBeaconState)
Expand Down Expand Up @@ -391,7 +390,7 @@ func TestStateRootAgainstLatestBlockHeaderProof(t *testing.T) {
// this is the state where the latest block header from the oracle was taken. This is the next slot after
// the state we want to prove things about (remember latestBlockHeader.state_root = previous slot's state root)
// oracleStateJSON, err := parseJSONFile("data/historical_summary_proof/goerli_slot_6399999.json")
// var oracleState capella.BeaconState
// var oracleState deneb.BeaconState
// ParseCapellaBeaconStateFromJSON(*oracleStateJSON, &oracleState)

var blockHeader phase0.BeaconBlockHeader
Expand All @@ -406,8 +405,8 @@ func TestStateRootAgainstLatestBlockHeaderProof(t *testing.T) {

//the state from the prev slot which contains shit we wanna prove about
stateToProveJSON, err := parseJSONFile("data/goerli_slot_6399998.json")
var stateToProve capella.BeaconState
ParseCapellaBeaconStateFromJSON(*stateToProveJSON, &stateToProve)
var stateToProve deneb.BeaconState
ParseDenebBeaconStateFromJSON(*stateToProveJSON, &stateToProve)

proof, err := ProveStateRootAgainstBlockHeader(&blockHeader)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions proof_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ type InputDataBlockHeader struct {
type InputDataBlock struct {
Version string `json:"version"`
Data struct {
Message capella.BeaconBlock `json:"message"`
Signature string `json:"signature"`
Message deneb.BeaconBlock `json:"message"`
Signature string `json:"signature"`
} `json:"data"`
Execution_optimistic bool `json:"execution_optimistic"`
Finalized bool `json:"finalized"`
Expand Down Expand Up @@ -174,16 +174,16 @@ func ExtractBlockHeader(blockHeaderFile string) (phase0.BeaconBlockHeader, error
return inputData.Data.Header.Message, nil
}

func ExtractBlock(blockHeaderFile string) (capella.BeaconBlock, error) {
func ExtractBlock(blockHeaderFile string) (deneb.BeaconBlock, error) {
fileBytes, err := os.ReadFile(blockHeaderFile)
if err != nil {
return capella.BeaconBlock{}, err
return deneb.BeaconBlock{}, err
}

// Decode JSON
var data InputDataBlock
if err := json.Unmarshal(fileBytes, &data); err != nil {
return capella.BeaconBlock{}, err
return deneb.BeaconBlock{}, err
}

// Extract block body
Expand Down Expand Up @@ -233,7 +233,7 @@ func parseStateJSONFile(filePath string) (*beaconStateJSON, error) {
}

// nolint:gocyclo
func ParseCapellaBeaconStateFromJSON(data beaconStateJSON, s *deneb.BeaconState) error {
func ParseDenebBeaconStateFromJSON(data beaconStateJSON, s *deneb.BeaconState) error {
var err error

if data.GenesisTime == "" {
Expand Down
4 changes: 2 additions & 2 deletions proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type BeaconStateTopLevelRoots struct {
HistoricalSummariesRoot *phase0.Root
}

func ProveBlockRootAgainstBeaconStateViaHistoricalSummaries(beaconStateTopLevelRoots *BeaconStateTopLevelRoots, historicalSummaries []*deneb.HistoricalSummary, historicalBlockRoots []phase0.Root, historicalSummaryIndex uint64, blockRootIndex uint64) ([][32]byte, error) {
func ProveBlockRootAgainstBeaconStateViaHistoricalSummaries(beaconStateTopLevelRoots *BeaconStateTopLevelRoots, historicalSummaries []*capella.HistoricalSummary, historicalBlockRoots []phase0.Root, historicalSummaryIndex uint64, blockRootIndex uint64) ([][32]byte, error) {
// prove the historical summaries against the beacon state
historicalSummariesListAgainstBeaconState, err := ProveBeaconTopLevelRootAgainstBeaconState(beaconStateTopLevelRoots, historicalSummaryListIndex)

Expand Down Expand Up @@ -953,7 +953,7 @@ func GetExecutionPayloadFieldRoots(executionPayloadFields *deneb.ExecutionPayloa
}

//Field 11: BaseFeePerGas
hh.PutBytes(executionPayloadFields.BaseFeePerGas[:])
hh.PutBytes(executionPayloadFields.BaseFeePerGas.Bytes())
copy(executionPayloadFieldRoots[11][:], hh.Hash())
hh.Reset()

Expand Down
3 changes: 1 addition & 2 deletions prove_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package eigenpodproofs
import (
"math/big"

"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
)
Expand All @@ -16,7 +15,7 @@ type VerifyWithdrawalCredentialsCallParams struct {
ValidatorFields [][]Bytes32 `json:"validatorFields"`
}

func (epp *EigenPodProofs) ProveValidatorWithdrawalCredentials(oracleBlockHeader *phase0.BeaconBlockHeader, oracleBeaconState *capella.BeaconState, validatorIndices []uint64) (*VerifyWithdrawalCredentialsCallParams, error) {
func (epp *EigenPodProofs) ProveValidatorWithdrawalCredentials(oracleBlockHeader *phase0.BeaconBlockHeader, oracleBeaconState *deneb.BeaconState, validatorIndices []uint64) (*VerifyWithdrawalCredentialsCallParams, error) {
verifyWithdrawalCredentialsCallParams := &VerifyWithdrawalCredentialsCallParams{}
verifyWithdrawalCredentialsCallParams.StateRootProof = &StateRootProof{}
// Get beacon state top level roots
Expand Down
10 changes: 5 additions & 5 deletions prove_withdrawal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"math"
"time"

"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/rs/zerolog/log"
)
Expand Down Expand Up @@ -79,9 +79,9 @@ func (epp *EigenPodProofs) GetWithdrawalProofParams(latestOracleBeaconSlot, with

func (epp *EigenPodProofs) ProveWithdrawals(
oracleBlockHeader *phase0.BeaconBlockHeader,
oracleBeaconState *capella.BeaconState,
oracleBeaconState *deneb.BeaconState,
historicalSummaryStateBlockRoots [][]phase0.Root,
withdrawalBlocks []*capella.BeaconBlock,
withdrawalBlocks []*deneb.BeaconBlock,
validatorIndices []uint64,
) (*VerifyAndProcessWithdrawalCallParams, error) {
verifyAndProcessWithdrawalCallParams := &VerifyAndProcessWithdrawalCallParams{}
Expand Down Expand Up @@ -150,10 +150,10 @@ func (epp *EigenPodProofs) ProveWithdrawals(
// validatorIndex: the index of the validator that the withdrawal happened for
func (epp *EigenPodProofs) ProveWithdrawal(
oracleBlockHeader *phase0.BeaconBlockHeader,
oracleBeaconState *capella.BeaconState,
oracleBeaconState *deneb.BeaconState,
oracleBeaconStateTopLevelRoots *BeaconStateTopLevelRoots,
historicalSummaryStateBlockRoots []phase0.Root,
withdrawalBlock *capella.BeaconBlock,
withdrawalBlock *deneb.BeaconBlock,
validatorIndex uint64,
) (*WithdrawalProof, error) {
withdrawalProof := &WithdrawalProof{}
Expand Down
3 changes: 2 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/bits"

"github.com/attestantio/go-eth2-client/spec/capella"
"github.com/attestantio/go-eth2-client/spec/deneb"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethereum/go-ethereum/common/hexutil"
ssz "github.com/ferranbt/fastssz"
Expand Down Expand Up @@ -89,7 +90,7 @@ func NextPowerOfTwo(v uint64) uint {
return uint(v)
}

func GetSlotTimestamp(beaconState *capella.BeaconState, blockHeader *phase0.BeaconBlockHeader) uint64 {
func GetSlotTimestamp(beaconState *deneb.BeaconState, blockHeader *phase0.BeaconBlockHeader) uint64 {
return beaconState.GenesisTime + uint64(blockHeader.Slot)*12
}

Expand Down

0 comments on commit 606a3f3

Please sign in to comment.