Skip to content

Commit

Permalink
added new test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidu28 committed Jan 23, 2024
1 parent f574e63 commit 23230bd
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion merkle_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &currentBeaconState)
ParseDenebBeaconStateFromJSON(*oldBeaconStateJSON, &oldBeaconState)
fmt.Println("currentBeacon state historical summary lentgh is", len(currentBeaconState.HistoricalSummaries))

currentBeaconStateTopLevelRoots, _ := ComputeBeaconStateTopLevelRoots(&currentBeaconState)
//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)
Expand Down

0 comments on commit 23230bd

Please sign in to comment.