Skip to content

Commit

Permalink
removed validator balance proof logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidu28 committed Jan 13, 2024
1 parent 51b01da commit 743a827
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 97 deletions.
21 changes: 16 additions & 5 deletions data/goerli_block_header_6399998.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
{
"slot": "6399998",
"proposer_index": "470543",
"parent_root": "0x5e83fd9f12a10bd0aa14d9300f245cdc5ffaabec780453c1638eaf6177dd64f1",
"state_root": "0x9150ef194c1028ae7b938602b896a5c3649f8bb37943a0d742f0e675e1af71cf",
"body_root": "0x8b7e82d37076560671cbc868022756db12b668f0b16e18a4a56bfbdfd4392882"
"execution_optimistic": false,
"finalized": true,
"data": {
"root": "0xec53179027584f241d8a2ef782890a1a4f8ea48f57978f35b71440dec0b2ad5a",
"canonical": true,
"header": {
"message": {
"slot": "6399998",
"proposer_index": "470543",
"parent_root": "0x5e83fd9f12a10bd0aa14d9300f245cdc5ffaabec780453c1638eaf6177dd64f1",
"state_root": "0x9150ef194c1028ae7b938602b896a5c3649f8bb37943a0d742f0e675e1af71cf",
"body_root": "0x8b7e82d37076560671cbc868022756db12b668f0b16e18a4a56bfbdfd4392882"
},
"signature": "0xb2e8c2cff276abcb468a2ac2fd8f613eb2fd5a8f12c4f3e7c68300f94d5f616be52e196d2b38d1c804fbd20084c0ffb900754ceb2561ab383e37fbe6fba09463727efdcc453c23cc64ecf3b1f8624afa12fc6c4b1a740b7c663155809bc4e109"
}
}
}
14 changes: 1 addition & 13 deletions generate_balance_update_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,15 @@ func GenerateBalanceUpdateProof(oracleBlockHeaderFile string, stateFile string,
log.Debug().AnErr("Error creating EPP object", err)
}

balanceRootList, err := GetBalanceRoots(state.Balances)
if err != nil {
log.Debug().AnErr("Error with GetBalanceRoots", err)
}
balanceRoot := balanceRootList[validatorIndex/4]
balanceProof, err := epp.ProveValidatorBalance(&oracleBeaconBlockHeader, &state, uint64(validatorIndex))
if err != nil {
log.Debug().AnErr("Error with ProveValidatorBalance", err)
}

stateRootProof, validatorFieldsProof, err := epp.ProveValidatorFields(&oracleBeaconBlockHeader, &state, uint64(validatorIndex))
if err != nil {
log.Debug().AnErr("Error with ProveValidatorFields", err)
}
proofs := BalanceUpdateProofs{
ValidatorIndex: uint64(validatorIndex),
BeaconStateRoot: "0x" + hex.EncodeToString(beaconStateRoot[:]),
BalanceRoot: "0x" + hex.EncodeToString(balanceRoot[:]),
ValidatorBalanceProof: ConvertBytesToStrings(balanceProof.BalanceUpdateProof.ValidatorBalanceProof),
StateRootAgainstLatestBlockHeaderProof: ConvertBytesToStrings(stateRootProof.StateRootProof),
WithdrawalCredentialProof: ConvertBytesToStrings(validatorFieldsProof),
ValidatorFieldsProof: ConvertBytesToStrings(validatorFieldsProof),
ValidatorFields: GetValidatorFields(state.Validators[validatorIndex]),
}

Expand Down
6 changes: 5 additions & 1 deletion generate_withdrawal_fields_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eigenpodproofs
import (
"encoding/hex"
"encoding/json"
"fmt"
"os"

"github.com/attestantio/go-eth2-client/spec/capella"
Expand Down Expand Up @@ -34,6 +35,10 @@ func GenerateWithdrawalFieldsProof(
var withdrawalBlock capella.BeaconBlock

oracleBeaconBlockHeader, err := ExtractBlockHeader(oracleBlockHeaderFile)

root, _ := oracleBeaconBlockHeader.HashTreeRoot()
fmt.Println("oracleBeaconBlockHeader: ", root)

if err != nil {
log.Debug().AnErr("Error with parsing header file", err)
}
Expand Down Expand Up @@ -107,7 +112,6 @@ func GenerateWithdrawalFieldsProof(
if err != nil {
log.Debug().AnErr("GenerateWithdrawalFieldsProof: error with ProveSlotAgainstBlockHeader", err)
}

validatorProof, err := epp.ProveValidatorAgainstBeaconState(&state, oracleBeaconStateTopLevelRoots, uint64(validatorIndex))
if err != nil {
log.Debug().AnErr("GenerateWithdrawalFieldsProof: error with ProveValidatorAgainstBeaconState", err)
Expand Down
6 changes: 3 additions & 3 deletions proof_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ type WithdrawalCredentialProofs struct {
type BalanceUpdateProofs struct {
ValidatorIndex uint64 `json:"validatorIndex"`
BeaconStateRoot string `json:"beaconStateRoot"`
BalanceRoot string `json:"balanceRoot"`
LatestBlockHeaderRoot string `json:"latestBlockHeaderRoot"`
ValidatorBalanceProof []string `json:"ValidatorBalanceProof"`
StateRootAgainstLatestBlockHeaderProof []string `json:"StateRootAgainstLatestBlockHeaderProof"`
WithdrawalCredentialProof []string `json:"WithdrawalCredentialProof"`
ValidatorFieldsProof []string `json:"WithdrawalCredentialProof"`
ValidatorFields []string `json:"ValidatorFields"`
}

Expand Down Expand Up @@ -170,6 +168,8 @@ func ExtractBlockHeader(blockHeaderFile string) (phase0.BeaconBlockHeader, error
return phase0.BeaconBlockHeader{}, err
}

fmt.Println(inputData.Data.Header.Message)

return inputData.Data.Header.Message, nil
}

Expand Down
75 changes: 0 additions & 75 deletions prove_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,58 +53,6 @@ func (epp *EigenPodProofs) ProveValidatorWithdrawalCredentials(oracleBlockHeader
return verifyWithdrawalCredentialsCallParams, nil
}

type VerifyBalanceUpdateCallParams struct {
OracleTimestamp uint64 `json:"oracleTimestamp"`
ValidatorIndex uint64 `json:"validatorIndex"`
StateRootProof *StateRootProof `json:"stateRootProof"`
BalanceUpdateProof *BalanceUpdateProof `json:"validatorFieldsProofs"`
ValidatorFields []Bytes32 `json:"validatorFields"`
}

type BalanceUpdateProof struct {
ValidatorBalanceProof Proof `json:"validatorBalanceProof"`
ValidatorFieldsProof Proof `json:"validatorFieldsProof"`
BalanceRoot Bytes32 `json:"balanceRoot"`
}

func (epp *EigenPodProofs) ProveValidatorBalance(oracleBlockHeader *phase0.BeaconBlockHeader, oracleBeaconState *capella.BeaconState, validatorIndex uint64) (*VerifyBalanceUpdateCallParams, error) {
verifyBalanceUpdateCallParams := &VerifyBalanceUpdateCallParams{}
verifyBalanceUpdateCallParams.StateRootProof = &StateRootProof{}
// Get beacon state top level roots
beaconStateTopLevelRoots, err := epp.ComputeBeaconStateTopLevelRoots(oracleBeaconState)
if err != nil {
return nil, err
}

verifyBalanceUpdateCallParams.StateRootProof.BeaconStateRoot, err = epp.ComputeBeaconStateRoot(oracleBeaconState)
if err != nil {
return nil, err
}

verifyBalanceUpdateCallParams.StateRootProof.StateRootProof, err = ProveStateRootAgainstBlockHeader(oracleBlockHeader)
if err != nil {
return nil, err
}

verifyBalanceUpdateCallParams.OracleTimestamp = GetSlotTimestamp(oracleBeaconState, oracleBlockHeader)
verifyBalanceUpdateCallParams.ValidatorIndex = validatorIndex
verifyBalanceUpdateCallParams.BalanceUpdateProof = &BalanceUpdateProof{}
verifyBalanceUpdateCallParams.BalanceUpdateProof.ValidatorBalanceProof, err = epp.ProveValidatorBalanceAgainstBalanceRoot(oracleBeaconState, validatorIndex)
if err != nil {
return nil, err
}

verifyBalanceUpdateCallParams.BalanceUpdateProof.ValidatorFieldsProof, err = epp.ProveValidatorAgainstBeaconState(oracleBeaconState, beaconStateTopLevelRoots, validatorIndex)
if err != nil {
return nil, err
}

verifyBalanceUpdateCallParams.BalanceUpdateProof.BalanceRoot = ConvertUint64ToBytes32(uint64(oracleBeaconState.Balances[validatorIndex]))
verifyBalanceUpdateCallParams.ValidatorFields = ConvertValidatorToValidatorFields(oracleBeaconState.Validators[validatorIndex])

return verifyBalanceUpdateCallParams, err
}

func (epp *EigenPodProofs) ProveValidatorFields(oracleBlockHeader *phase0.BeaconBlockHeader, oracleBeaconState *capella.BeaconState, validatorIndex uint64) (*StateRootProof, Proof, error) {
stateRootProof := &StateRootProof{}
// Get beacon state top level roots
Expand Down Expand Up @@ -134,29 +82,6 @@ func (epp *EigenPodProofs) ProveValidatorFields(oracleBlockHeader *phase0.Beacon
return stateRootProof, validatorFieldsProof, nil
}

func (epp *EigenPodProofs) ProveValidatorBalanceAgainstBalanceRoot(oracleBeaconState *capella.BeaconState, validatorIndex uint64) ([][32]byte, error) {
// Get beacon state top level roots
beaconStateTopLevelRoots, err := epp.ComputeBeaconStateTopLevelRoots(oracleBeaconState)
if err != nil {
return nil, err
}

// prove the validator balance list root against the beacon state
beaconStateProof, err := ProveBeaconTopLevelRootAgainstBeaconState(beaconStateTopLevelRoots, balanceListIndex)
if err != nil {
return nil, err
}

// prove the validator balance root against the validator balance list root
balancesProof, err := ProveValidatorBalanceAgainstValidatorBalanceList(oracleBeaconState.Balances, validatorIndex)
if err != nil {
return nil, err
}

fullBalanceProof := append(balancesProof, beaconStateProof...)
return fullBalanceProof, nil
}

func (epp *EigenPodProofs) ProveValidatorAgainstBeaconState(oracleBeaconState *capella.BeaconState, beaconStateTopLevelRoots *BeaconStateTopLevelRoots, validatorIndex uint64) (Proof, error) {
// prove the validator list against the beacon state
validatorListProof, err := ProveBeaconTopLevelRootAgainstBeaconState(beaconStateTopLevelRoots, validatorListIndex)
Expand Down

0 comments on commit 743a827

Please sign in to comment.