-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7dd267
commit 27b84ff
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |