Skip to content

Commit

Permalink
cmd/livefuzzer: add pectra spam
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Sep 18, 2024
1 parent e7dd267 commit 27b84ff
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/livefuzzer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ var blobSpamCommand = &cli.Command{
Flags: flags.SpamFlags,
}

var pectraSpamCommand = &cli.Command{
Name: "pectra",
Usage: "Send 7702 spam transactions",
Action: run7702Spam,
Flags: flags.SpamFlags,
}

var createCommand = &cli.Command{
Name: "create",
Usage: "Create ephemeral accounts",
Expand All @@ -61,6 +68,7 @@ func initApp() *cli.App {
airdropCommand,
spamCommand,
blobSpamCommand,
pectraSpamCommand,
createCommand,
unstuckCommand,
}
Expand Down Expand Up @@ -119,6 +127,16 @@ func runBlobSpam(c *cli.Context) error {
return spam(config, spammer.SendBlobTransactions, airdropValue)
}

func run7702Spam(c *cli.Context) error {
config, err := spammer.NewConfigFromContext(c)
if err != nil {
return err
}
airdropValue := new(big.Int).Mul(big.NewInt(int64((1+config.N)*1000000)), big.NewInt(params.GWei))
airdropValue = airdropValue.Mul(airdropValue, big.NewInt(100))
return spam(config, spammer.Send7702Transactions, airdropValue)
}

func runCreate(c *cli.Context) error {
spammer.CreateAddresses(100)
return nil
Expand Down
77 changes: 77 additions & 0 deletions spammer/eip7702.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package spammer

import (
"context"
"crypto/ecdsa"
"fmt"
"math/big"
"math/rand"
"time"

"github.com/MariusVanDerWijden/FuzzyVM/filler"
txfuzz "github.com/MariusVanDerWijden/tx-fuzz"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
)

func Send7702Transactions(config *Config, key *ecdsa.PrivateKey, f *filler.Filler) error {
backend := ethclient.NewClient(config.backend)
sender := crypto.PubkeyToAddress(key.PublicKey)
chainID, err := backend.ChainID(context.Background())
if err != nil {
log.Warn("Could not get chainID, using default")
chainID = big.NewInt(0x01000666)
}

var lastTx *types.Transaction
for i := uint64(0); i < config.N; i++ {
nonce, err := backend.NonceAt(context.Background(), sender, big.NewInt(-1))
if err != nil {
return err
}

authorizer := config.keys[rand.Intn(len(config.keys))]
nonceAuth, err := backend.NonceAt(context.Background(), crypto.PubkeyToAddress(authorizer.PublicKey), big.NewInt(-1))
if err != nil {
return err
}

auth := &types.Authorization{
ChainID: chainID,
Address: sender,
Nonce: []uint64{nonceAuth},
}

auth, err = types.SignAuth(auth, authorizer)
if err != nil {
return err
}

tx, err := txfuzz.RandomAuthTx(config.backend, f, sender, nonce, nil, nil, config.accessList, types.AuthorizationList{auth})
if err != nil {
log.Warn("Could not create valid tx: %v", nonce)
return err
}
signedTx, err := types.SignTx(tx, types.NewCancunSigner(chainID), key)
if err != nil {
return err
}
if err := backend.SendTransaction(context.Background(), signedTx); err != nil {
log.Warn("Could not submit transaction: %v", err)
return err
}
lastTx = signedTx
time.Sleep(10 * time.Millisecond)
}
if lastTx != nil {
ctx, cancel := context.WithTimeout(context.Background(), TX_TIMEOUT)
defer cancel()
if _, err := bind.WaitMined(ctx, backend, lastTx); err != nil {
fmt.Printf("Waiting for transactions to be mined failed: %v\n", err.Error())
}
}
return nil
}

0 comments on commit 27b84ff

Please sign in to comment.