Skip to content

Commit

Permalink
simulate calldata
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrower95 committed Aug 12, 2024
1 parent 6a48990 commit 77f0207
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 24 deletions.
8 changes: 4 additions & 4 deletions cli/core/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/fatih/color"
)

func SubmitCheckpointProof(ctx context.Context, owner, eigenpodAddress string, chainId *big.Int, proof *eigenpodproofs.VerifyCheckpointProofsCallParams, eth *ethclient.Client, batchSize uint64, noPrompt bool) ([]*types.Transaction, error) {
func SubmitCheckpointProof(ctx context.Context, owner, eigenpodAddress string, chainId *big.Int, proof *eigenpodproofs.VerifyCheckpointProofsCallParams, eth *ethclient.Client, batchSize uint64, noPrompt bool, noSend bool) ([]*types.Transaction, error) {
tracing := GetContextTracingCallbacks(ctx)

allProofChunks := chunk(proof.BalanceProofs, batchSize)
Expand All @@ -32,7 +32,7 @@ func SubmitCheckpointProof(ctx context.Context, owner, eigenpodAddress string, c
tracing.OnStartSection("pepe::proof::checkpoint::batch::submit", map[string]string{
"chunk": fmt.Sprintf("%d", i),
})
txn, err := SubmitCheckpointProofBatch(ctx, owner, eigenpodAddress, chainId, proof.ValidatorBalancesRootProof, balanceProofs, eth)
txn, err := SubmitCheckpointProofBatch(ctx, owner, eigenpodAddress, chainId, proof.ValidatorBalancesRootProof, balanceProofs, eth, noSend)
tracing.OnEndSection()
if err != nil {
// failed to submit batch.
Expand All @@ -52,10 +52,10 @@ func SubmitCheckpointProof(ctx context.Context, owner, eigenpodAddress string, c
return transactions, nil
}

func SubmitCheckpointProofBatch(ctx context.Context, owner, eigenpodAddress string, chainId *big.Int, proof *eigenpodproofs.ValidatorBalancesRootProof, balanceProofs []*eigenpodproofs.BalanceProof, eth *ethclient.Client) (*types.Transaction, error) {
func SubmitCheckpointProofBatch(ctx context.Context, owner, eigenpodAddress string, chainId *big.Int, proof *eigenpodproofs.ValidatorBalancesRootProof, balanceProofs []*eigenpodproofs.BalanceProof, eth *ethclient.Client, noSend bool) (*types.Transaction, error) {
tracing := GetContextTracingCallbacks(ctx)

ownerAccount, err := PrepareAccount(&owner, chainId)
ownerAccount, err := PrepareAccount(&owner, chainId, noSend)
if err != nil {
return nil, err
}
Expand Down
10 changes: 7 additions & 3 deletions cli/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ type Owner = struct {
FromAddress gethCommon.Address
PublicKey *ecdsa.PublicKey
TransactionOptions *bind.TransactOpts
IsDryRun bool
}

func StartCheckpoint(ctx context.Context, eigenpodAddress string, ownerPrivateKey string, chainId *big.Int, eth *ethclient.Client, forceCheckpoint bool) (uint64, error) {
ownerAccount, err := PrepareAccount(&ownerPrivateKey, chainId)
func StartCheckpoint(ctx context.Context, eigenpodAddress string, ownerPrivateKey string, chainId *big.Int, eth *ethclient.Client, forceCheckpoint bool, noSend bool) (uint64, error) {
ownerAccount, err := PrepareAccount(&ownerPrivateKey, chainId, noSend)
if err != nil {
return 0, fmt.Errorf("failed to parse private key: %w", err)
}
Expand Down Expand Up @@ -328,7 +329,7 @@ func PanicIfNoConsent(prompt string) {
}
}

func PrepareAccount(owner *string, chainID *big.Int) (*Owner, error) {
func PrepareAccount(owner *string, chainID *big.Int, noSend bool) (*Owner, error) {
if owner == nil {
return nil, errors.New("no owner")
}
Expand All @@ -349,10 +350,13 @@ func PrepareAccount(owner *string, chainID *big.Int) (*Owner, error) {
return nil, err
}

auth.NoSend = noSend

return &Owner{
FromAddress: fromAddress,
PublicKey: publicKeyECDSA,
TransactionOptions: auth,
IsDryRun: noSend,
}, nil
}

Expand Down
14 changes: 10 additions & 4 deletions cli/core/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func LoadValidatorProofFromFile(path string) (*SerializableCredentialProof, erro
return &res, nil
}

func SubmitValidatorProof(ctx context.Context, owner, eigenpodAddress string, chainId *big.Int, eth *ethclient.Client, batchSize uint64, proofs *eigenpodproofs.VerifyValidatorFieldsCallParams, oracleBeaconTimesetamp uint64, noPrompt bool) ([]*types.Transaction, error) {
ownerAccount, err := PrepareAccount(&owner, chainId)
func SubmitValidatorProof(ctx context.Context, owner, eigenpodAddress string, chainId *big.Int, eth *ethclient.Client, batchSize uint64, proofs *eigenpodproofs.VerifyValidatorFieldsCallParams, oracleBeaconTimesetamp uint64, noPrompt bool, noSend bool) ([]*types.Transaction, error) {
ownerAccount, err := PrepareAccount(&owner, chainId, noSend)
if err != nil {
return nil, err
}
Expand All @@ -54,14 +54,20 @@ func SubmitValidatorProof(ctx context.Context, owner, eigenpodAddress string, ch
validatorIndicesChunks := chunk(indices, batchSize)
validatorProofsChunks := chunk(proofs.ValidatorFieldsProofs, batchSize)
validatorFieldsChunks := chunk(proofs.ValidatorFields, batchSize)
if !noPrompt {
if !noPrompt && !noSend {
PanicIfNoConsent(SubmitCredentialsProofConsent(len(validatorFieldsChunks)))
}

transactions := []*types.Transaction{}
numChunks := len(validatorIndicesChunks)

color.Green("calling EigenPod.VerifyWithdrawalCredentials() (using %d txn(s), max(%d) proofs per txn)", numChunks, batchSize)
color.Green("calling EigenPod.VerifyWithdrawalCredentials() (using %d txn(s), max(%d) proofs per txn [%s])", numChunks, batchSize, func() string {
if ownerAccount.TransactionOptions.NoSend {
return "simulated"
} else {
return "live"
}
}())
color.Green("Submitting proofs with %d transactions", numChunks)

for i := 0; i < numChunks; i++ {
Expand Down
49 changes: 36 additions & 13 deletions cli/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/hex"
"encoding/json"
"fmt"
"math"
Expand Down Expand Up @@ -48,7 +49,7 @@ func Require(flag *cli.StringFlag) *cli.StringFlag {

// Destinations for values set by various flags
var eigenpodAddress, beacon, node, sender, output string
var useJson bool = false
var useJson, simulateTransaction bool = false, false
var specificValidator uint64 = math.MaxUint64
var proofPath string

Expand Down Expand Up @@ -83,6 +84,13 @@ var EXEC_NODE_FLAG = &cli.StringFlag{
Required: true,
Destination: &node,
}
var PRINT_CALLDATA_BUT_DO_NOT_EXECUTE_FLAG = &cli.BoolFlag{
Name: "print-calldata",
Value: false,
Usage: "Print the calldata for all associated transactions, but do not execute them. Note that some transactions have an order dependency (you cannot submit checkpoint proofs if you haven't started a checkpoint) so this may require you to get your pod into the correct state before usage.",
Required: false,
Destination: &simulateTransaction,
}

// Optional commands:

Expand Down Expand Up @@ -156,7 +164,7 @@ func main() {
return fmt.Errorf("failed to reach eth node for chain id: %w", err)
}

ownerAccount, err := core.PrepareAccount(&sender, chainId)
ownerAccount, err := core.PrepareAccount(&sender, chainId, false /* noSend */)
if err != nil {
return fmt.Errorf("failed to parse --sender: %w", err)
}
Expand All @@ -175,7 +183,7 @@ func main() {
return fmt.Errorf("error: new proof submitter is existing proof submitter (%s)", currentSubmitter)
}

if !noPrompt {
if !noPrompt && !simulateTransaction {
fmt.Printf("Your pod's current proof submitter is %s.\n", currentSubmitter)
core.PanicIfNoConsent(fmt.Sprintf("This will update your EigenPod to allow %s to submit proofs on its behalf. As the EigenPod's owner, you can always change this later.", newSubmitter))
}
Expand Down Expand Up @@ -373,6 +381,7 @@ func main() {
BEACON_NODE_FLAG,
EXEC_NODE_FLAG,
SENDER_PK_FLAG,
PRINT_CALLDATA_BUT_DO_NOT_EXECUTE_FLAG,
BatchBySize(&batchSize, DEFAULT_BATCH_CHECKPOINT),
PROOF_PATH_FLAG,
&cli.BoolFlag{
Expand Down Expand Up @@ -414,7 +423,7 @@ func main() {
proof, err := core.LoadCheckpointProofFromFile(proofPath)
core.PanicOnError("failed to parse checkpoint proof from file", err)

txns, err := core.SubmitCheckpointProof(ctx, sender, eigenpodAddress, chainId, proof, eth, batchSize, noPrompt)
txns, err := core.SubmitCheckpointProof(ctx, sender, eigenpodAddress, chainId, proof, eth, batchSize, noPrompt, simulateTransaction)
for _, txn := range txns {
color.Green("submitted txn: %s", txn.Hash())
}
Expand All @@ -427,11 +436,11 @@ func main() {

if currentCheckpoint == 0 {
if len(sender) != 0 {
if !noPrompt {
if !noPrompt && !simulateTransaction {
core.PanicIfNoConsent(core.StartCheckpointProofConsent())
}

newCheckpoint, err := core.StartCheckpoint(ctx, eigenpodAddress, sender, chainId, eth, forceCheckpoint)
newCheckpoint, err := core.StartCheckpoint(ctx, eigenpodAddress, sender, chainId, eth, forceCheckpoint, simulateTransaction)
core.PanicOnError("failed to start checkpoint", err)
currentCheckpoint = newCheckpoint
} else {
Expand All @@ -449,9 +458,15 @@ func main() {
if out != nil {
core.WriteOutputToFileOrStdout(jsonString, out)
} else if len(sender) != 0 {
txns, err := core.SubmitCheckpointProof(ctx, sender, eigenpodAddress, chainId, proof, eth, batchSize, noPrompt)
for _, txn := range txns {
color.Green("submitted txn: %s", txn.Hash())
txns, err := core.SubmitCheckpointProof(ctx, sender, eigenpodAddress, chainId, proof, eth, batchSize, noPrompt, simulateTransaction)
if simulateTransaction {
for i, txn := range txns {
color.Green("transaction(%d).calldata: %s", i, hex.EncodeToString(txn.Data()))
}
} else {
for i, txn := range txns {
color.Green("transaction(%d): %s", i, txn.Hash().Hex())
}
}
core.PanicOnError("an error occurred while submitting your checkpoint proofs", err)
}
Expand All @@ -468,6 +483,7 @@ func main() {
BEACON_NODE_FLAG,
EXEC_NODE_FLAG,
SENDER_PK_FLAG,
PRINT_CALLDATA_BUT_DO_NOT_EXECUTE_FLAG,
BatchBySize(&batchSize, DEFAULT_BATCH_CREDENTIALS),
&cli.Uint64Flag{
Name: "validatorIndex",
Expand Down Expand Up @@ -504,7 +520,7 @@ func main() {
proof, err := core.LoadValidatorProofFromFile(proofPath)
core.PanicOnError("failed to parse checkpoint proof from file", err)

txns, err := core.SubmitValidatorProof(ctx, sender, eigenpodAddress, chainId, eth, batchSize, proof.ValidatorProofs, proof.OracleBeaconTimestamp, noPrompt)
txns, err := core.SubmitValidatorProof(ctx, sender, eigenpodAddress, chainId, eth, batchSize, proof.ValidatorProofs, proof.OracleBeaconTimestamp, noPrompt, simulateTransaction)
for _, txn := range txns {
color.Green("submitted txn: %s", txn.Hash())
}
Expand All @@ -520,10 +536,17 @@ func main() {
}

if len(sender) != 0 {
txns, err := core.SubmitValidatorProof(ctx, sender, eigenpodAddress, chainId, eth, batchSize, validatorProofs, oracleBeaconTimestamp, noPrompt)
for i, txn := range txns {
color.Green("transaction(%d): %s", i, txn.Hash().Hex())
txns, err := core.SubmitValidatorProof(ctx, sender, eigenpodAddress, chainId, eth, batchSize, validatorProofs, oracleBeaconTimestamp, noPrompt, simulateTransaction)
if simulateTransaction {
for i, txn := range txns {
color.Green("transaction(%d).calldata: %s", i, hex.EncodeToString(txn.Data()))
}
} else {
for i, txn := range txns {
color.Green("transaction(%d): %s", i, txn.Hash().Hex())
}
}

core.PanicOnError("failed to invoke verifyWithdrawalCredentials", err)
} else {
proof := core.SerializableCredentialProof{
Expand Down

0 comments on commit 77f0207

Please sign in to comment.