diff --git a/data/goerli_block_header_6399998.json b/data/goerli_block_header_6399998.json index fb75e146..e9734aae 100644 --- a/data/goerli_block_header_6399998.json +++ b/data/goerli_block_header_6399998.json @@ -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" + } + } } \ No newline at end of file diff --git a/generate_balance_update_proof.go b/generate_balance_update_proof.go index 0995eb94..30345631 100644 --- a/generate_balance_update_proof.go +++ b/generate_balance_update_proof.go @@ -36,16 +36,6 @@ 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) @@ -53,10 +43,8 @@ func GenerateBalanceUpdateProof(oracleBlockHeaderFile string, stateFile string, 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]), } diff --git a/generate_withdrawal_fields_proof.go b/generate_withdrawal_fields_proof.go index 6a4b33cc..cf7117c8 100644 --- a/generate_withdrawal_fields_proof.go +++ b/generate_withdrawal_fields_proof.go @@ -3,6 +3,7 @@ package eigenpodproofs import ( "encoding/hex" "encoding/json" + "fmt" "os" "github.com/attestantio/go-eth2-client/spec/capella" @@ -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) } @@ -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) diff --git a/proof_utils.go b/proof_utils.go index 9189d8e0..2d3b363c 100644 --- a/proof_utils.go +++ b/proof_utils.go @@ -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"` } @@ -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 } diff --git a/prove_validator.go b/prove_validator.go index 0f750d58..9905a733 100644 --- a/prove_validator.go +++ b/prove_validator.go @@ -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 @@ -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)