diff --git a/merkle_util_test.go b/merkle_util_test.go index d9f1435e..faa2a605 100644 --- a/merkle_util_test.go +++ b/merkle_util_test.go @@ -223,7 +223,85 @@ func TestGetHistoricalSummariesBlockRootsProofProof(t *testing.T) { } historicalSummaryIndex := uint64(271) - beaconBlockHeaderToVerifyIndex = 8191 //(6397852 mod 8192) + beaconBlockHeaderToVerifyIndex = 8191 //(7421951 mod 8192) + beaconBlockHeaderToVerify, err := blockHeader.HashTreeRoot() + if err != nil { + fmt.Println("error", err) + } + + // fmt.Println("THESE SHOULD BE", hex.EncodeToString(beaconBlockHeaderToVerify[:])) + // fmt.Println("THE SAME", hex.EncodeToString(beaconBlockHeaderToVerify[:])) + // fmt.Println("THESE SHOULD BE", hex.EncodeToString(oldBeaconStateTopLevelRoots.BlockRootsRoot[:])) + // fmt.Println("THE SAME", hex.EncodeToString(currentBeaconState.HistoricalSummaries[146].BlockSummaryRoot[:])) + + oldBlockRoots := oldBeaconState.BlockRoots + + historicalSummaryBlockHeaderProof, err := ProveBlockRootAgainstBeaconStateViaHistoricalSummaries( + currentBeaconStateTopLevelRoots, + currentBeaconState.HistoricalSummaries, + oldBlockRoots, + historicalSummaryIndex, + beaconBlockHeaderToVerifyIndex, + ) + + if err != nil { + fmt.Println("error") + } + + currentBeaconStateRoot, _ := currentBeaconState.HashTreeRoot() + + historicalBlockHeaderIndex := historicalSummaryListIndex<<((historicalSummaryListMerkleSubtreeNumLayers+1)+1+(blockRootsMerkleSubtreeNumLayers)) | + historicalSummaryIndex<<(1+blockRootsMerkleSubtreeNumLayers) | + blockSummaryRootIndex<<(blockRootsMerkleSubtreeNumLayers) | beaconBlockHeaderToVerifyIndex + + flag := ValidateProof(currentBeaconStateRoot, historicalSummaryBlockHeaderProof, beaconBlockHeaderToVerify, historicalBlockHeaderIndex) + if flag != true { + fmt.Println("error 2") + } + + assert.True(t, flag, "Proof %v failed\n") +} + +func TestGetHistoricalSummariesBlockRootsProofProofCapellaAgainstDeneb(t *testing.T) { + + //curl -H "Accept: application/json" https://data.spiceai.io/goerli/beacon/eth/v2/debug/beacon/states/7431952 -o deneb_goerli_slot_7431952.json --header 'X-API-Key: 343035|8b6ddd9b31f54c07b3fc18282b30f61c' + currentBeaconStateJSON, err := parseJSONFile("data/deneb_goerli_slot_7431952.json") + + if err != nil { + fmt.Println("error parsing currentBeaconStateJSON") + } + + //this is not the beacon state of the slot containing the old withdrawal we want to proof but rather + // its the state that was merklized to create a historical summary containing the slot that has that withdrawal, ie, 7421952 mod 8192 = 0 + oldBeaconStateJSON, err := parseJSONFile("data/goerli_slot_6397952.json.json") + if err != nil { + fmt.Println("error parsing oldBeaconStateJSON") + } + + var blockHeader phase0.BeaconBlockHeader + //blockHeader, err = ExtractBlockHeader("data/goerli_block_header_6397852.json") + blockHeader, err = ExtractBlockHeader("data/deneb_goerli_block_header_7421951.json") + + if err != nil { + fmt.Println("blockHeader.UnmarshalJSON error", err) + } + + var currentBeaconState deneb.BeaconState + var oldBeaconState deneb.BeaconState + + ParseDenebBeaconStateFromJSON(*currentBeaconStateJSON, ¤tBeaconState) + ParseDenebBeaconStateFromJSON(*oldBeaconStateJSON, &oldBeaconState) + fmt.Println("currentBeacon state historical summary lentgh is", len(currentBeaconState.HistoricalSummaries)) + + currentBeaconStateTopLevelRoots, _ := ComputeBeaconStateTopLevelRoots(¤tBeaconState) + //oldBeaconStateTopLevelRoots, _ := ComputeBeaconStateTopLevelRoots(&oldBeaconState) + + if err != nil { + fmt.Println("error") + } + + historicalSummaryIndex := uint64(271) + beaconBlockHeaderToVerifyIndex = 8191 //(7421951 mod 8192) beaconBlockHeaderToVerify, err := blockHeader.HashTreeRoot() if err != nil { fmt.Println("error", err)