diff --git a/beacon/block.go b/beacon/block.go index 12b97ad7..dddb102a 100644 --- a/beacon/block.go +++ b/beacon/block.go @@ -13,7 +13,7 @@ func ProveBlockBodyAgainstBlockHeader(blockHeader *phase0.BeaconBlockHeader) (co return nil, err } - return common.GetProof(blockHeaderContainerRoots, beaconBlockBodyRootIndex, blockHeaderMerkleSubtreeNumLayers) + return common.GetProof(blockHeaderContainerRoots, BeaconBlockBodyRootIndex, blockHeaderMerkleSubtreeNumLayers) } // refer to this: https://github.com/attestantio/go-eth2-client/blob/654ac05b4c534d96562329f988655e49e5743ff5/spec/phase0/beaconblockheader_encoding.go @@ -33,7 +33,7 @@ func ProveSlotAgainstBlockHeader(blockHeader *phase0.BeaconBlockHeader) (common. return nil, err } - return common.GetProof(blockHeaderContainerRoots, slotIndex, blockHeaderMerkleSubtreeNumLayers) + return common.GetProof(blockHeaderContainerRoots, SlotIndex, blockHeaderMerkleSubtreeNumLayers) } func GetBlockHeaderFieldRoots(blockHeader *phase0.BeaconBlockHeader) ([]phase0.Root, error) { diff --git a/beacon/capella.go b/beacon/capella.go index 18a5cf77..7b5b4a19 100644 --- a/beacon/capella.go +++ b/beacon/capella.go @@ -181,9 +181,9 @@ func ProveExecutionPayloadAgainstBlockBodyCapella(beaconBlockBody *capella.Beaco hh.Reset() } - proof, err := common.GetProof(beaconBlockBodyContainerRoots, executionPayloadIndex, blockBodyMerkleSubtreeNumLayers) + proof, err := common.GetProof(beaconBlockBodyContainerRoots, ExecutionPayloadIndex, BlockBodyMerkleSubtreeNumLayers) - return proof, beaconBlockBodyContainerRoots[executionPayloadIndex], err + return proof, beaconBlockBodyContainerRoots[ExecutionPayloadIndex], err } func GetExecutionPayloadFieldRootsCapella(executionPayloadFields *capella.ExecutionPayload) ([]phase0.Root, error) { diff --git a/beacon/constants.go b/beacon/constants.go index e189c50e..9e923381 100644 --- a/beacon/constants.go +++ b/beacon/constants.go @@ -1,33 +1,33 @@ package beacon const ( - slotsPerHistoricalRoot = uint64(8192) + SlotsPerHistoricalRoot = uint64(8192) // Index of the historical summaries in the beacon state - historicalSummaryListIndex = uint64(27) + HistoricalSummaryListIndex = uint64(27) // Index of validator list in beacon state - validatorListIndex = uint64(11) + ValidatorListIndex = uint64(11) balanceListIndex = uint64(12) // Index of the beacon body root inside the beacon body header - beaconBlockBodyRootIndex = uint64(4) + BeaconBlockBodyRootIndex = uint64(4) // Index of the execution payload in the BeaconBlockBody container - executionPayloadIndex = uint64(9) + ExecutionPayloadIndex = uint64(9) // Index of the timestamp inside the execution payload - timestampIndex = uint64(9) + TimestampIndex = uint64(9) // Index of the withdrawals inside the execution payload - withdrawalsIndex = uint64(14) + WithdrawalsIndex = uint64(14) // Index of the slot in the beacon block header - slotIndex = uint64(0) + SlotIndex = uint64(0) stateRootIndex = uint64(3) // in the historical summary coontainer, the block root summary is at index 0 - blockSummaryRootIndex = uint64(0) + BlockSummaryRootIndex = uint64(0) ) // @@ -40,27 +40,28 @@ const ( // Number of layers for various merkle subtrees blockHeaderMerkleSubtreeNumLayers = uint64(3) - blockBodyMerkleSubtreeNumLayers = uint64(4) + BlockBodyMerkleSubtreeNumLayers = uint64(4) + // TODO unused; remove // Number of layers for the merkelization of the Execution Payload executionPayloadMerkleSubtreeNumLayersDeneb = uint64(5) executionPayloadMerkleSubtreeNumLayersCapella = uint64(4) // Number of layers for the merkleixation of the Validator List in the Beacon State - validatorListMerkleSubtreeNumLayers = uint64(40) + ValidatorListMerkleSubtreeNumLayers = uint64(40) // Number of layers for the merkleixation of the Historical Summary List in the Beacon State - historicalSummaryListMerkleSubtreeNumLayers = uint64(24) + HistoricalSummaryListMerkleSubtreeNumLayers = uint64(24) // Number of layers for the merkleization of the Withdrawal List in the Exection Payload - withdrawalListMerkleSubtreeNumLayers = uint64(4) + WithdrawalListMerkleSubtreeNumLayers = uint64(4) // Number of layers for the merkleization of the Beacon State beaconStateMerkleSubtreeNumLayers = uint64(5) // Number of layers for the merkleization of the Block Roots in the Beacon State - blockRootsMerkleSubtreeNumLayers = uint64(13) + BlockRootsMerkleSubtreeNumLayers = uint64(13) // **************Number of fields of various containers************** beaconBlockHeaderNumFields = uint64(5) diff --git a/beacon/deneb.go b/beacon/deneb.go index f2a0f913..56949576 100644 --- a/beacon/deneb.go +++ b/beacon/deneb.go @@ -5,6 +5,7 @@ import ( "github.com/Layr-Labs/eigenpod-proofs-generation/common" "github.com/attestantio/go-eth2-client/spec/altair" + "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" @@ -194,9 +195,9 @@ func ProveExecutionPayloadAgainstBlockBodyDeneb(beaconBlockBody *deneb.BeaconBlo hh.Reset() } - proof, err := common.GetProof(beaconBlockBodyContainerRoots, executionPayloadIndex, blockBodyMerkleSubtreeNumLayers) + proof, err := common.GetProof(beaconBlockBodyContainerRoots, ExecutionPayloadIndex, BlockBodyMerkleSubtreeNumLayers) - return proof, beaconBlockBodyContainerRoots[executionPayloadIndex], err + return proof, beaconBlockBodyContainerRoots[ExecutionPayloadIndex], err } // taken from https://github.com/attestantio/go-eth2-client/blob/21f7dd480fed933d8e0b1c88cee67da721c80eb2/spec/deneb/beaconstate_ssz.go#L640 @@ -743,3 +744,135 @@ func ComputeExecutionPayloadFieldRootsDeneb(executionPayloadFields *deneb.Execut return executionPayloadFieldRoots, nil } + +func ComputeExecutionPayloadFieldRootsCapella(executionPayloadFields *capella.ExecutionPayload) ([]phase0.Root, error) { + executionPayloadFieldRoots := make([]phase0.Root, 15) + var err error + + hh := ssz.NewHasher() + + //Field 0: ParentHash + hh.PutBytes(executionPayloadFields.ParentHash[:]) + copy(executionPayloadFieldRoots[0][:], hh.Hash()) + hh.Reset() + + //Field 1: FeeRecipient + hh.PutBytes(executionPayloadFields.FeeRecipient[:]) + copy(executionPayloadFieldRoots[1][:], hh.Hash()) + hh.Reset() + + //Field 2: StateRoot + hh.PutBytes(executionPayloadFields.StateRoot[:]) + copy(executionPayloadFieldRoots[2][:], hh.Hash()) + hh.Reset() + + //Field 3: ReceiptRoot + hh.PutBytes(executionPayloadFields.ReceiptsRoot[:]) + copy(executionPayloadFieldRoots[3][:], hh.Hash()) + hh.Reset() + + //Field 4: LogsBloom + hh.PutBytes(executionPayloadFields.LogsBloom[:]) + copy(executionPayloadFieldRoots[4][:], hh.Hash()) + hh.Reset() + + //Field 5: PrevRandao + hh.PutBytes(executionPayloadFields.PrevRandao[:]) + copy(executionPayloadFieldRoots[5][:], hh.Hash()) + hh.Reset() + + //Field 6: BlockNumber + hh.PutUint64(executionPayloadFields.BlockNumber) + copy(executionPayloadFieldRoots[6][:], hh.Hash()) + hh.Reset() + + //Field 7: GasLimit + hh.PutUint64(executionPayloadFields.GasLimit) + copy(executionPayloadFieldRoots[7][:], hh.Hash()) + hh.Reset() + + //Field 8: GasUsed + hh.PutUint64(executionPayloadFields.GasUsed) + copy(executionPayloadFieldRoots[8][:], hh.Hash()) + hh.Reset() + + //Field 9: Timestamp + hh.PutUint64(executionPayloadFields.Timestamp) + copy(executionPayloadFieldRoots[9][:], hh.Hash()) + hh.Reset() + + //Field 10: ExtraData + + // //If the field is empty, we set it to 0 + // if len(executionPayloadFields.ExtraData) == 0 { + // executionPayloadFields.ExtraData = []byte{0} + // } + + { + elemIndx := hh.Index() + byteLen := uint64(len(executionPayloadFields.ExtraData)) + if byteLen > 32 { + err = ssz.ErrIncorrectListSize + fmt.Println(err) + } + hh.PutBytes(executionPayloadFields.ExtraData) + hh.MerkleizeWithMixin(elemIndx, byteLen, (32+31)/32) + copy(executionPayloadFieldRoots[10][:], hh.Hash()) + hh.Reset() + } + + //Field 11: BaseFeePerGas + hh.PutBytes(executionPayloadFields.BaseFeePerGas[:]) + copy(executionPayloadFieldRoots[11][:], hh.Hash()) + hh.Reset() + + //Field 12: BlockHash + hh.PutBytes(executionPayloadFields.BlockHash[:]) + copy(executionPayloadFieldRoots[12][:], hh.Hash()) + hh.Reset() + + //Field 13: Transactions + { + subIndx := hh.Index() + num := uint64(len(executionPayloadFields.Transactions)) + if num > 1048576 { + err = ssz.ErrIncorrectListSize + fmt.Println(err) + } + for _, elem := range executionPayloadFields.Transactions { + { + elemIndx := hh.Index() + byteLen := uint64(len(elem)) + if byteLen > 1073741824 { + err = ssz.ErrIncorrectListSize + fmt.Println(err) + } + hh.AppendBytes32(elem) + hh.MerkleizeWithMixin(elemIndx, byteLen, (1073741824+31)/32) + } + } + hh.MerkleizeWithMixin(subIndx, num, 1048576) + copy(executionPayloadFieldRoots[13][:], hh.Hash()) + hh.Reset() + } + + //Field 14: Withdrawals + { + subIndx := hh.Index() + num := uint64(len(executionPayloadFields.Withdrawals)) + if num > 16 { + err := ssz.ErrIncorrectListSize + return nil, err + } + for _, elem := range executionPayloadFields.Withdrawals { + if err = elem.HashTreeRootWith(hh); err != nil { + return nil, err + } + } + hh.MerkleizeWithMixin(subIndx, num, 16) + copy(executionPayloadFieldRoots[14][:], hh.Hash()) + hh.Reset() + } + + return executionPayloadFieldRoots, nil +} diff --git a/beacon/shared.go b/beacon/shared.go index 256b6455..6fa231f8 100644 --- a/beacon/shared.go +++ b/beacon/shared.go @@ -79,7 +79,7 @@ func GetBalanceRoots(balances []phase0.Gwei) ([]phase0.Root, 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) + historicalSummariesListAgainstBeaconState, err := ProveBeaconTopLevelRootAgainstBeaconState(beaconStateTopLevelRoots, HistoricalSummaryListIndex) if err != nil { return nil, err } @@ -98,7 +98,7 @@ func ProveBlockRootAgainstBeaconStateViaHistoricalSummaries(beaconStateTopLevelR } // historical block roots are incklude the really old block root you wanna prove - beaconBlockHeaderRootsProof, err := common.GetProof(historicalBlockRoots, blockRootIndex, blockRootsMerkleSubtreeNumLayers) + beaconBlockHeaderRootsProof, err := common.GetProof(historicalBlockRoots, blockRootIndex, BlockRootsMerkleSubtreeNumLayers) if err != nil { return nil, err } @@ -120,7 +120,7 @@ func ProveHistoricalSummaryAgainstHistoricalSummariesList(historicalSummaries [] historicalSummaryNodeList[i] = phase0.Root(historicalSummaryRoot) } - proof, err := common.GetProof(historicalSummaryNodeList, historicalSummaryIndex, historicalSummaryListMerkleSubtreeNumLayers) + proof, err := common.GetProof(historicalSummaryNodeList, historicalSummaryIndex, HistoricalSummaryListMerkleSubtreeNumLayers) if err != nil { return nil, err @@ -143,7 +143,7 @@ func ProveBlockRootListAgainstHistoricalSummary(historicalSummary *capella.Histo } func ProveBlockRootAgainstBlockRootsList(blockRoots []phase0.Root, blockRootIndex uint64) (common.Proof, error) { - proof, err := common.GetProof(blockRoots, blockRootIndex, blockRootsMerkleSubtreeNumLayers) + proof, err := common.GetProof(blockRoots, blockRootIndex, BlockRootsMerkleSubtreeNumLayers) if err != nil { return nil, err } @@ -176,7 +176,7 @@ func ProveWithdrawalAgainstExecutionPayload( } func ProveWithdrawalListAgainstExecutionPayload(executionPayloadFieldRoots []phase0.Root) (common.Proof, error) { - return common.GetProof(executionPayloadFieldRoots, withdrawalsIndex, common.CeilLog2(len(executionPayloadFieldRoots))) + return common.GetProof(executionPayloadFieldRoots, WithdrawalsIndex, common.CeilLog2(len(executionPayloadFieldRoots))) } func ProveWithdrawalAgainstWithdrawalList(withdrawals []*capella.Withdrawal, withdrawalIndex uint8) (common.Proof, error) { @@ -189,7 +189,7 @@ func ProveWithdrawalAgainstWithdrawalList(withdrawals []*capella.Withdrawal, wit withdrawalNodeList[i] = phase0.Root(withdrawalRoot) } - proof, err := common.GetProof(withdrawalNodeList, uint64(withdrawalIndex), withdrawalListMerkleSubtreeNumLayers) + proof, err := common.GetProof(withdrawalNodeList, uint64(withdrawalIndex), WithdrawalListMerkleSubtreeNumLayers) if err != nil { return nil, err } @@ -202,5 +202,5 @@ func ProveWithdrawalAgainstWithdrawalList(withdrawals []*capella.Withdrawal, wit } func ProveTimestampAgainstExecutionPayload(executionPayloadFieldRoots []phase0.Root) (common.Proof, error) { - return common.GetProof(executionPayloadFieldRoots, timestampIndex, common.CeilLog2(len(executionPayloadFieldRoots))) + return common.GetProof(executionPayloadFieldRoots, TimestampIndex, common.CeilLog2(len(executionPayloadFieldRoots))) } diff --git a/eigen_pod_proofs.go b/eigen_pod_proofs.go index 2e1c8356..59b8975e 100644 --- a/eigen_pod_proofs.go +++ b/eigen_pod_proofs.go @@ -115,7 +115,7 @@ func (epp *EigenPodProofs) ComputeValidatorTree(slot phase0.Slot, validators []* } // compute the validator tree - validatorTree, err := common.ComputeMerkleTreeFromLeaves(validatorLeaves, validatorListMerkleSubtreeNumLayers) + validatorTree, err := common.ComputeMerkleTreeFromLeaves(validatorLeaves, beacon.ValidatorListMerkleSubtreeNumLayers) if err != nil { return nil, err } diff --git a/merkle_util_test.go b/merkle_util_test.go index 92421c05..1a72b072 100644 --- a/merkle_util_test.go +++ b/merkle_util_test.go @@ -85,7 +85,7 @@ func setupSuite() { executionPayload = *block.Body.ExecutionPayload - blockHeaderIndex = uint64(blockHeader.Slot) % slotsPerHistoricalRoot + blockHeaderIndex = uint64(blockHeader.Slot) % beacon.SlotsPerHistoricalRoot epp, err = NewEigenPodProofs(GOERLI_CHAIN_ID, 1000) if err != nil { @@ -124,7 +124,7 @@ func TestGenerateWithdrawalCredentialsProof(t *testing.T) { fmt.Println("error with hash tree root of beacon state") } - index := validatorListIndex<<(validatorListMerkleSubtreeNumLayers+1) | uint64(validatorIndex) + index := beacon.ValidatorListIndex<<(beacon.ValidatorListMerkleSubtreeNumLayers+1) | uint64(validatorIndex) flag := common.ValidateProof(root, proof, leaf, index) if flag != true { @@ -167,7 +167,7 @@ func TestProveBeaconTopLevelRootAgainstBeaconState(t *testing.T) { } // compute the Merkle proof for the inclusion of Validators Root as a leaf - validatorsRootProof, err := beacon.ProveBeaconTopLevelRootAgainstBeaconState(beaconStateTopLevelRoots, validatorListIndex) + validatorsRootProof, err := beacon.ProveBeaconTopLevelRootAgainstBeaconState(beaconStateTopLevelRoots, beacon.ValidatorListIndex) if err != nil { fmt.Println("error") } @@ -181,7 +181,7 @@ func TestProveBeaconTopLevelRootAgainstBeaconState(t *testing.T) { // validation of the proof // get the leaf denoting the validatorsRoot in the BeaconStateRoot Merkle tree leaf := beaconStateTopLevelRoots.ValidatorsRoot - flag := common.ValidateProof(beaconStateRoot, validatorsRootProof, *leaf, validatorListIndex) + flag := common.ValidateProof(beaconStateRoot, validatorsRootProof, *leaf, beacon.ValidatorListIndex) if flag != true { fmt.Println("error") } @@ -256,9 +256,9 @@ func TestGetHistoricalSummariesBlockRootsProofProof(t *testing.T) { currentBeaconStateRoot, _ := currentBeaconState.HashTreeRoot() - historicalBlockHeaderIndex := historicalSummaryListIndex<<((historicalSummaryListMerkleSubtreeNumLayers+1)+1+(blockRootsMerkleSubtreeNumLayers)) | - historicalSummaryIndex<<(1+blockRootsMerkleSubtreeNumLayers) | - blockSummaryRootIndex<<(blockRootsMerkleSubtreeNumLayers) | beaconBlockHeaderToVerifyIndex + historicalBlockHeaderIndex := beacon.HistoricalSummaryListIndex<<((beacon.HistoricalSummaryListMerkleSubtreeNumLayers+1)+1+(beacon.BlockRootsMerkleSubtreeNumLayers)) | + historicalSummaryIndex<<(1+beacon.BlockRootsMerkleSubtreeNumLayers) | + beacon.BlockSummaryRootIndex<<(beacon.BlockRootsMerkleSubtreeNumLayers) | beaconBlockHeaderToVerifyIndex flag := common.ValidateProof(currentBeaconStateRoot, historicalSummaryBlockHeaderProof, beaconBlockHeaderToVerify, historicalBlockHeaderIndex) if flag != true { @@ -334,9 +334,9 @@ func TestGetHistoricalSummariesBlockRootsProofProofCapellaAgainstDeneb(t *testin currentBeaconStateRoot, _ := currentBeaconState.HashTreeRoot() - historicalBlockHeaderIndex := historicalSummaryListIndex<<((historicalSummaryListMerkleSubtreeNumLayers+1)+1+(blockRootsMerkleSubtreeNumLayers)) | - historicalSummaryIndex<<(1+blockRootsMerkleSubtreeNumLayers) | - blockSummaryRootIndex<<(blockRootsMerkleSubtreeNumLayers) | beaconBlockHeaderToVerifyIndex + historicalBlockHeaderIndex := beacon.HistoricalSummaryListIndex<<((beacon.HistoricalSummaryListMerkleSubtreeNumLayers+1)+1+(beacon.BlockRootsMerkleSubtreeNumLayers)) | + historicalSummaryIndex<<(1+beacon.BlockRootsMerkleSubtreeNumLayers) | + beacon.BlockSummaryRootIndex<<(beacon.BlockRootsMerkleSubtreeNumLayers) | beaconBlockHeaderToVerifyIndex flag := common.ValidateProof(currentBeaconStateRoot, historicalSummaryBlockHeaderProof, beaconBlockHeaderToVerify, historicalBlockHeaderIndex) if flag != true { @@ -405,7 +405,7 @@ func TestComputeBlockSlotProof(t *testing.T) { } // calling the proof verification function - flag := common.ValidateProof(beaconBlockHeaderRoot, blockHeaderSlotProof, slotHashRoot, slotIndex) + flag := common.ValidateProof(beaconBlockHeaderRoot, blockHeaderSlotProof, slotHashRoot, beacon.SlotIndex) if flag != true { fmt.Println("error") } @@ -435,7 +435,7 @@ func TestProveBlockBodyAgainstBlockHeader(t *testing.T) { } // calling the proof verification function - flag := common.ValidateProof(beaconBlockHeaderRoot, blockHeaderBlockBodyProof, blockBodyHashRoot, beaconBlockBodyRootIndex) + flag := common.ValidateProof(beaconBlockHeaderRoot, blockHeaderBlockBodyProof, blockBodyHashRoot, beacon.BeaconBlockBodyRootIndex) if flag != true { fmt.Println("error") } @@ -465,7 +465,7 @@ func TestComputeExecutionPayloadHeader(t *testing.T) { blockHeaderBodyRoot := blockHeader.BodyRoot // calling the proof verification function - flag := common.ValidateProof(blockHeaderBodyRoot, beaconBlockBodyProof, executionPayloadHashRoot, executionPayloadIndex) + flag := common.ValidateProof(blockHeaderBodyRoot, beaconBlockBodyProof, executionPayloadHashRoot, beacon.ExecutionPayloadIndex) if flag != true { fmt.Println("error") } @@ -530,7 +530,7 @@ func TestGetExecutionPayloadProof(t *testing.T) { // get the body root in the beacon block header - will be used as the Merkle root root, _ := blockHeader.HashTreeRoot() - index := beaconBlockBodyRootIndex<<(blockBodyMerkleSubtreeNumLayers) | executionPayloadIndex + index := beacon.BeaconBlockBodyRootIndex<<(beacon.BlockBodyMerkleSubtreeNumLayers) | beacon.ExecutionPayloadIndex // calling the proof verification function flag := common.ValidateProof(root, exectionPayloadProof, executionPayloadHashRoot, index) @@ -575,7 +575,7 @@ func TestComputeWithdrawalsListProof(t *testing.T) { } copy(executionPayloadHashRoot[:], hh.Hash()) } - flag := common.ValidateProof(executionPayloadHashRoot, withdrawalsListProof, withdrawalsHashRoot, withdrawalsIndex) + flag := common.ValidateProof(executionPayloadHashRoot, withdrawalsListProof, withdrawalsHashRoot, beacon.WithdrawalsIndex) if flag != true { fmt.Println("Proof Failed") } @@ -646,9 +646,9 @@ func TestGetWithdrawalProof(t *testing.T) { if err != nil { fmt.Println("error") } - // withdrawalIndex = beaconBlockBodyRootIndex<<( blockBodyMerkleSubtreeNumLayers+ executionPayloadMerkleSubtreeNumLayers+( withdrawalListMerkleSubtreeNumLayers+1)) | executionPayloadIndex<<( executionPayloadMerkleSubtreeNumLayers+( withdrawalListMerkleSubtreeNumLayers+1)) | withdrawalsIndex<<( withdrawalListMerkleSubtreeNumLayers+1) | withdrawalIndex + // withdrawalIndex = beacon.BeaconBlockBodyRootIndex<<( beacon.BlockBodyMerkleSubtreeNumLayers+ executionPayloadMerkleSubtreeNumLayers+( beacon.WithdrawalListMerkleSubtreeNumLayers+1)) | beacon.ExecutionPayloadIndex<<( executionPayloadMerkleSubtreeNumLayers+( beacon.WithdrawalListMerkleSubtreeNumLayers+1)) | beacon.WithdrawalsIndex<<( beacon.WithdrawalListMerkleSubtreeNumLayers+1) | withdrawalIndex - withdrawalRelativeToELPayloadIndex := withdrawalsIndex<<(withdrawalListMerkleSubtreeNumLayers+1) | uint64(withdrawalIndex) + withdrawalRelativeToELPayloadIndex := beacon.WithdrawalsIndex<<(beacon.WithdrawalListMerkleSubtreeNumLayers+1) | uint64(withdrawalIndex) // calling the proof verification func flag := common.ValidateProof(executionPayloadRoot, withdrawalProof, leaf, withdrawalRelativeToELPayloadIndex) @@ -678,7 +678,7 @@ func TestGetTimestampProof(t *testing.T) { } // calling the proof verification func - flag := common.ValidateProof(root, timestampProof, leaf, timestampIndex) + flag := common.ValidateProof(root, timestampProof, leaf, beacon.TimestampIndex) if flag != true { fmt.Println("proof failed") } @@ -707,7 +707,7 @@ func TestGetValidatorProof(t *testing.T) { // calling the proof verification func beaconRoot, _ := b.HashTreeRoot() - validatorIndex = validatorListIndex<<(validatorListMerkleSubtreeNumLayers+1) | uint64(validatorIndex) + validatorIndex = beacon.ValidatorListIndex<<(beacon.ValidatorListMerkleSubtreeNumLayers+1) | uint64(validatorIndex) flag := common.ValidateProof(beaconRoot, validatorProof, leaf, validatorIndex) if flag != true { diff --git a/prove_validator.go b/prove_validator.go index 0e8c3bc5..8a18faac 100644 --- a/prove_validator.go +++ b/prove_validator.go @@ -87,7 +87,7 @@ func (epp *EigenPodProofs) ProveValidatorFields(oracleBlockHeader *phase0.Beacon func (epp *EigenPodProofs) ProveValidatorAgainstBeaconState(oracleBeaconState *deneb.BeaconState, beaconStateTopLevelRoots *beacon.BeaconStateTopLevelRoots, validatorIndex uint64) (common.Proof, error) { // prove the validator list against the beacon state - validatorListProof, err := beacon.ProveBeaconTopLevelRootAgainstBeaconState(beaconStateTopLevelRoots, validatorListIndex) + validatorListProof, err := beacon.ProveBeaconTopLevelRootAgainstBeaconState(beaconStateTopLevelRoots, beacon.ValidatorListIndex) if err != nil { return nil, err } @@ -109,7 +109,7 @@ func (epp *EigenPodProofs) ProveValidatorAgainstValidatorList(slot phase0.Slot, return nil, err } - proof, err := common.ComputeMerkleProofFromTree(validatorTree, validatorIndex, validatorListMerkleSubtreeNumLayers) + proof, err := common.ComputeMerkleProofFromTree(validatorTree, validatorIndex, beacon.ValidatorListMerkleSubtreeNumLayers) if err != nil { return nil, err } diff --git a/prove_withdrawal.go b/prove_withdrawal.go index f1a3e140..4ca19232 100644 --- a/prove_withdrawal.go +++ b/prove_withdrawal.go @@ -55,13 +55,13 @@ const FIRST_CAPELLA_SLOT_GOERLI = uint64(5193728) const FIRST_CAPELLA_SLOT_MAINNET = uint64(6209536) func IsProvableWithdrawal(latestOracleBeaconSlot, withdrawalSlot uint64) bool { - return latestOracleBeaconSlot > slotsPerHistoricalRoot+withdrawalSlot + return latestOracleBeaconSlot > beacon.SlotsPerHistoricalRoot+withdrawalSlot } func (epp *EigenPodProofs) GetWithdrawalProofParams(latestOracleBeaconSlot, withdrawalSlot uint64) (uint64, error) { if withdrawalSlot > latestOracleBeaconSlot { return 0, errors.New("withdrawal slot is after than the latest oracle beacon slot") - } else if latestOracleBeaconSlot-withdrawalSlot < slotsPerHistoricalRoot { + } else if latestOracleBeaconSlot-withdrawalSlot < beacon.SlotsPerHistoricalRoot { return 0, errors.New("oracle beacon slot does not have enough historical summaries to prove withdrawal") } @@ -72,10 +72,10 @@ func (epp *EigenPodProofs) GetWithdrawalProofParams(latestOracleBeaconSlot, with FIRST_CAPELLA_SLOT = FIRST_CAPELLA_SLOT_MAINNET } // index of the historical summary in the array of historical_summaries - historicalSummaryIndex := (withdrawalSlot - FIRST_CAPELLA_SLOT) / slotsPerHistoricalRoot + historicalSummaryIndex := (withdrawalSlot - FIRST_CAPELLA_SLOT) / beacon.SlotsPerHistoricalRoot // slot of which the beacon state is retrieved for getting the block roots array containing the old block with the old withdrawal - historicalSummarySlot := FIRST_CAPELLA_SLOT + (historicalSummaryIndex+1)*slotsPerHistoricalRoot + historicalSummarySlot := FIRST_CAPELLA_SLOT + (historicalSummaryIndex+1)*beacon.SlotsPerHistoricalRoot return historicalSummarySlot, nil } @@ -323,10 +323,10 @@ func (epp *EigenPodProofs) proveWithdrawal( withdrawalSlotUint64 := uint64(withdrawalBlockHeader.Slot) // index of the historical summary in the array of historical_summaries - withdrawalProof.HistoricalSummaryIndex = (withdrawalSlotUint64 - FIRST_CAPELLA_SLOT) / slotsPerHistoricalRoot + withdrawalProof.HistoricalSummaryIndex = (withdrawalSlotUint64 - FIRST_CAPELLA_SLOT) / beacon.SlotsPerHistoricalRoot // index of the block containing the target withdrawal in the block roots array - withdrawalProof.BlockRootIndex = withdrawalSlotUint64 % slotsPerHistoricalRoot + withdrawalProof.BlockRootIndex = withdrawalSlotUint64 % beacon.SlotsPerHistoricalRoot withdrawalProof.BlockRoot = historicalSummaryStateBlockRoots[withdrawalProof.BlockRootIndex] // make sure the withdrawal index is in range