Skip to content

Commit

Permalink
proofs work
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidu28 committed Jan 19, 2024
1 parent 606a3f3 commit 78815e8
Show file tree
Hide file tree
Showing 6 changed files with 2,396 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
data/goerli_slot_6397852.json
data/goerli_slot_6397952.json
data/goerli_slot_6399998.json
data/goerli_slot_6399998.json
data/deneb_slot_7426414.json
2,348 changes: 2,348 additions & 0 deletions data/deneb_goerli_block_7426113.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/deneb_goerli_block_header_7426113.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"execution_optimistic":false,"finalized":true,"data":{"root":"0xe64da3df320154a81437cd555928466d43d74dba7faa587a744a3904337213c9","canonical":true,"header":{"message":{"slot":"7426113","proposer_index":"406830","parent_root":"0x72271b271ac0349dce8ea5ccee3d1d17acfc44d6b3a0fb53889bede8ac161b8f","state_root":"0x704a2798ef24dab06a2ae80d301dd4b00e8e7a00445a8dab9a2e51a6cc9658e3","body_root":"0x2d68b4e5d26e837d1a5127d5844a5c7fa9759b53603f74215ca2dd0cf0079806"},"signature":"0x99a0fd3272bcec213e7e05c29c8d82d165e978c90077e4e8d3bffc08a809fd7cb8d42702ad2db6f72903595b87288cad06f8c40dee72c36952f0a28499bdc324e575faad56eea2e10b48b871336d0f8478ebf7c6d8fe8ed4f893ea8257d08846"}}}
8 changes: 8 additions & 0 deletions data/deneb_goerli_block_header_7426414.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slot": "7426414",
"proposer_index": "159320",
"parent_root": "0xfa586c486340d7f587d394e88e3bcf716ea4f114ade2c1fc4a34cee4639bac3c",
"state_root": "0x5e4b30444a386c0b96d0c06d02281c72294b98c1d5def533c325de54496cab4a",
"body_root": "0x9f29bd12c85f8936a56e5d3dc63d594ae935695ea7325d7434fa019189d7c65c"
}

19 changes: 12 additions & 7 deletions merkle_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ func TestMain(m *testing.M) {

func setupSuite() {
log.Println("Setting up suite")
stateFile := "data/goerli_slot_6399998.json"
headerFile := "data/goerli_block_header_6376200.json"
bodyFile := "data/goerli_block_6376200.json"
// stateFile := "data/goerli_slot_6399998.json"
// headerFile := "data/goerli_block_header_6376200.json"
// bodyFile := "data/goerli_block_6376200.json"
stateFile := "data/deneb_slot_7426414.json"
headerFile := "data/deneb_goerli_block_header_7426113.json"
bodyFile := "data/deneb_goerli_block_7426113.json"

//ParseCapellaBeaconState(stateFile)

Expand All @@ -70,12 +73,12 @@ func setupSuite() {

blockHeader, err = ExtractBlockHeader(headerFile)
if err != nil {
fmt.Println("error with block header")
fmt.Println("error with block header", err)
}

block, err = ExtractBlock(bodyFile)
if err != nil {
fmt.Println("error with block body")
fmt.Println("error with block body", err)
}

executionPayload = *block.Body.ExecutionPayload
Expand Down Expand Up @@ -394,7 +397,8 @@ func TestStateRootAgainstLatestBlockHeaderProof(t *testing.T) {
// ParseCapellaBeaconStateFromJSON(*oracleStateJSON, &oracleState)

var blockHeader phase0.BeaconBlockHeader
buf, err := os.ReadFile("data/goerli_block_header_6399998.json")
// buf, err := os.ReadFile("data/goerli_block_header_6399998.json")
buf, err := os.ReadFile("data/deneb_goerli_block_header_7426414.json")
if err != nil {
fmt.Println("read error with header file")
}
Expand All @@ -404,7 +408,8 @@ func TestStateRootAgainstLatestBlockHeaderProof(t *testing.T) {
}

//the state from the prev slot which contains shit we wanna prove about
stateToProveJSON, err := parseJSONFile("data/goerli_slot_6399998.json")
// stateToProveJSON, err := parseJSONFile("data/goerli_slot_6399998.json")
stateToProveJSON, err := parseJSONFile("data/deneb_slot_7426414.json")
var stateToProve deneb.BeaconState
ParseDenebBeaconStateFromJSON(*stateToProveJSON, &stateToProve)

Expand Down
27 changes: 25 additions & 2 deletions proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func ProveTimestampAgainstExecutionPayload(executionPayloadFields *deneb.Executi
// Refer to beaconblockbody.go in go-eth2-client
// https://github.com/attestantio/go-eth2-client/blob/654ac05b4c534d96562329f988655e49e5743ff5/spec/bellatrix/beaconblockbody_encoding.go
func ProveExecutionPayloadAgainstBlockBody(beaconBlockBody *deneb.BeaconBlockBody) (Proof, [32]byte, error) {
beaconBlockBodyContainerRoots := make([]phase0.Root, 11)
beaconBlockBodyContainerRoots := make([]phase0.Root, 12)
var err error

hh := ssz.NewHasher()
Expand Down Expand Up @@ -455,6 +455,21 @@ func ProveExecutionPayloadAgainstBlockBody(beaconBlockBody *deneb.BeaconBlockBod
hh.Reset()
}

{
if size := len(beaconBlockBody.BlobKZGCommitments); size > 4096 {
err = ssz.ErrListTooBigFn("BeaconBlockBody.BlobKZGCommitments", size, 4096)
return nil, [32]byte{}, err
}
subIndx := hh.Index()
for _, i := range beaconBlockBody.BlobKZGCommitments {
hh.PutBytes(i[:])
}
numItems := uint64(len(beaconBlockBody.BlobKZGCommitments))
hh.MerkleizeWithMixin(subIndx, numItems, 4096)
copy(beaconBlockBodyContainerRoots[11][:], hh.Hash())
hh.Reset()
}

proof, err := GetProof(beaconBlockBodyContainerRoots, executionPayloadIndex, blockBodyMerkleSubtreeNumLayers)

return proof, beaconBlockBodyContainerRoots[executionPayloadIndex], err
Expand Down Expand Up @@ -877,7 +892,7 @@ func ComputeBeaconStateTopLevelRoots(b *deneb.BeaconState) (*BeaconStateTopLevel
}

func GetExecutionPayloadFieldRoots(executionPayloadFields *deneb.ExecutionPayload) ([]phase0.Root, error) {
executionPayloadFieldRoots := make([]phase0.Root, 15)
executionPayloadFieldRoots := make([]phase0.Root, 17)
var err error

hh := ssz.NewHasher()
Expand Down Expand Up @@ -1005,6 +1020,14 @@ func GetExecutionPayloadFieldRoots(executionPayloadFields *deneb.ExecutionPayloa
hh.Reset()
}

hh.PutUint64(executionPayloadFields.BlobGasUsed)
copy(executionPayloadFieldRoots[15][:], hh.Hash())
hh.Reset()

hh.PutUint64(executionPayloadFields.ExcessBlobGas)
copy(executionPayloadFieldRoots[16][:], hh.Hash())
hh.Reset()

return executionPayloadFieldRoots, nil
}

Expand Down

0 comments on commit 78815e8

Please sign in to comment.