Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Withdrawal Oracle Slot Proof #16

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
data/goerli_slot_6397852.json
data/goerli_slot_6397952.json
data/goerli_slot_6399998.json
data/goerli_slot_6399998.json
data/deneb_goerli_slot_7413760.json
data/deneb_goerli_slot_7421952.json
data/deneb_goerli_slot_7431952.json
Binary file removed ProofGeneration
Binary file not shown.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This package allows you to generate withdrawal credential proofs, withdrawal pro
## Build the Executable

```
$cd proofGenCli
$go build
```

Expand All @@ -21,7 +22,7 @@ $ ./proof-gen -command ValidatorFieldsProof -oracleBlockHeaderFile [ORACLE_BLOCK
```
Here is an example of running this command with the sample state/block files in the `/data` folder
```
./proof-gen -command ValidatorFieldsProof -oracleBlockHeaderFile "data/goerli_block_header_6399998.json" -stateFile "data/goerli_slot_6399998.json" -validatorIndex 302913 -outputFile "withdrawal_credential_proof_302913.json" -chainID 5
./proof-gen -command ValidatorFieldsProof -oracleBlockHeaderFile "../data/goerli_block_header_6399998.json" -stateFile "../data/goerli_slot_6399998.json" -validatorIndex 302913 -outputFile "withdrawal_credential_proof_302913.json" -chainID 5
```
### Generate Withdrawal Proof
Here is the command:
Expand All @@ -31,7 +32,7 @@ $ ./proofGeneration -command WithdrawalFieldsProof -oracleBlockHeaderFile [ORACL
Here is an example of running this command with the sample state/block files in the `/data` folder

```
./proofGeneration -command WithdrawalFieldsProof -oracleBlockHeaderFile "data/goerli_block_header_6399998.json" -stateFile "data/goerli_slot_6399998.json" -validatorIndex 200240 -outputFile "withdrawal_proof_302913.json" -chainID 5 -historicalSummariesIndex 146 -blockHeaderIndex 8092 -historicalSummaryStateFile "data/goerli_slot_6397852.json" -blockHeaderFile "data/goerli_block_header_6397852.json" -blockBodyFile "data/goerli_block_6397852.json" -withdrawalIndex 0
./proofGenCli/proofGenCLI -command WithdrawalFieldsProof -oracleBlockHeaderFile "data/goerli_block_header_6399998.json" -stateFile "data/goerli_slot_6399998.json" -validatorIndex 200240 -outputFile "withdrawal_proof_302913.json" -chainID 5 -historicalSummariesIndex 146 -blockHeaderIndex 8092 -historicalSummaryStateFile "data/goerli_slot_6397952.json" -blockHeaderFile "data/goerli_block_header_6397852.json" -blockBodyFile "data/goerli_block_6397852.json" -withdrawalIndex 0
```

### Generate a Balance Update Proof.
Expand All @@ -40,7 +41,7 @@ $ ./proofGeneration "BalanceUpdateProof" -oracleBlockHeaderFile [ORACLE_BLOCK_H
```
Here is an example of running this command with the sample state/block files in the `/data` folder:
```
./proof-gen -command BalanceUpdateProof -oracleBlockHeaderFile "data/goerli_block_header_6399998.json" -stateFile "data/goerli_slot_6399998.json" -validatorIndex 302913 -outputFile "withdrawal_credential_proof_302913.json" -chainID 5
./proof-gen -command BalanceUpdateProof -oracleBlockHeaderFile "../data/goerli_block_header_6399998.json" -stateFile "../data/goerli_slot_6399998.json" -validatorIndex 302913 -outputFile "withdrawal_credential_proof_302913.json" -chainID 5
```

# Proof Generation Input Glossary
Expand Down
Binary file modified data/.DS_Store
Binary file not shown.
21 changes: 16 additions & 5 deletions data/goerli_block_header_6399998.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
14 changes: 1 addition & 13 deletions generate_balance_update_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,15 @@ 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)
}
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]),
}

Expand Down
15 changes: 13 additions & 2 deletions generate_withdrawal_fields_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eigenpodproofs
import (
"encoding/hex"
"encoding/json"
"fmt"
"os"

"github.com/attestantio/go-eth2-client/spec/capella"
Expand Down Expand Up @@ -34,6 +35,11 @@ func GenerateWithdrawalFieldsProof(
var withdrawalBlock capella.BeaconBlock

oracleBeaconBlockHeader, err := ExtractBlockHeader(oracleBlockHeaderFile)

root, _ := oracleBeaconBlockHeader.HashTreeRoot()
fmt.Println("oracleBeaconBlockHeader: ", hex.EncodeToString(root[:]))
fmt.Println("validatorIndex: ", validatorIndex)

if err != nil {
log.Debug().AnErr("Error with parsing header file", err)
}
Expand Down Expand Up @@ -99,16 +105,21 @@ func GenerateWithdrawalFieldsProof(
if err != nil {
log.Debug().AnErr("GenerateWithdrawalFieldsProof: error with ProveWithdrawal", err)
}
stateRootProof, err := ProveStateRootAgainstBlockHeader(&oracleBeaconBlockHeader)
stateRootProofAgainstBlockHeader, err := ProveStateRootAgainstBlockHeader(&oracleBeaconBlockHeader)
if err != nil {
log.Debug().AnErr("GenerateWithdrawalFieldsProof: error with ProveStateRootAgainstBlockHeader", err)
}
slotProofAgainstBlockHeader, err := ProveSlotAgainstBlockHeader(&oracleBeaconBlockHeader)
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)
}
proofs := WithdrawalProofs{
StateRootAgainstLatestBlockHeaderProof: ConvertBytesToStrings(stateRootProof),
StateRootAgainstLatestBlockHeaderProof: ConvertBytesToStrings(stateRootProofAgainstBlockHeader),
SlotAgainstLatestBlockHeaderProof: ConvertBytesToStrings(slotProofAgainstBlockHeader),
BeaconStateRoot: "0x" + hex.EncodeToString(beaconStateRoot[:]),
WithdrawalProof: ConvertBytesToStrings(withdrawalProof.WithdrawalProof),
SlotProof: ConvertBytesToStrings(withdrawalProof.SlotProof),
Expand Down
10 changes: 4 additions & 6 deletions merkle_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ func TestGetHistoricalSummariesBlockRootsProofProof(t *testing.T) {

oldBlockRoots := oldBeaconState.BlockRoots

fmt.Println("historicalSummaryIndex", historicalSummaryIndex)
fmt.Println("beaconBlockHeaderToVerifyIndex", beaconBlockHeaderToVerifyIndex)
historicalSummaryBlockHeaderProof, err := ProveBlockRootAgainstBeaconStateViaHistoricalSummaries(
currentBeaconStateTopLevelRoots,
currentBeaconState.HistoricalSummaries,
Expand All @@ -255,7 +257,7 @@ func TestGetHistoricalSummariesBlockRootsProofProof(t *testing.T) {
fmt.Println("error 2")
}

assert.True(t, flag, "Proof %v failed\n")
assert.True(t, false, "Proof %v failed\n")

}

Expand Down Expand Up @@ -394,11 +396,7 @@ func TestStateRootAgainstLatestBlockHeaderProof(t *testing.T) {
// ParseCapellaBeaconStateFromJSON(*oracleStateJSON, &oracleState)

var blockHeader phase0.BeaconBlockHeader
buf, err := os.ReadFile("data/goerli_block_header_6399998.json")
if err != nil {
fmt.Println("read error with header file")
}
err = blockHeader.UnmarshalJSON(buf)
blockHeader, err := ExtractBlockHeader("data/goerli_block_header_6399998.json")
if err != nil {
fmt.Println("blockHeader.UnmarshalJSON error", err)
}
Expand Down
File renamed without changes.
Binary file added proofGenCli/proofGenCLI
Binary file not shown.
Loading
Loading