Skip to content

Commit

Permalink
update to newest spec version
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Sep 18, 2024
1 parent 0be8359 commit 940d729
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 35 deletions.
98 changes: 89 additions & 9 deletions cmd/prague/main.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
package main

import (
"context"
"crypto/rand"
"encoding/binary"
"fmt"
"time"

txfuzz "github.com/MariusVanDerWijden/tx-fuzz"
"github.com/MariusVanDerWijden/tx-fuzz/helper"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/params"
)

func main() {
testTouchContracts()
test2537()
test2537Long()
test3074()
test7702()
fmt.Println("Touching contracts")
//testTouchContracts()
fmt.Println("2537")
//test2537()
fmt.Println("2537")
//test2537Long()
fmt.Println("3074")
//test3074()
fmt.Println("7702")
//test7702()
fmt.Println("2935")
test2935()
}

func testTouchContracts() {
Expand Down Expand Up @@ -48,7 +59,6 @@ func test3074() {
helper.Execute([]byte{0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0xf7, 0x80, 0x55}, 200000)
helper.Execute([]byte{0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5a, 0xf7, 0x80, 0x55}, 200000)
helper.Execute([]byte{0x64, 0xff, 0xff, 0xff, 0xff, 0x5f, 0x64, 0xff, 0xff, 0xff, 0xff, 0x5f, 0x5f, 0x5f, 0x5a, 0xf7, 0x80, 0x55}, 200000)
time.Sleep(time.Minute)
fmt.Println("Execution tests")
vectors := [][]byte{
common.FromHex("000f6617e03f2800b69a0b018d3062535ec761c6648a4c73be71f97885e28505f67f0d4ee582093960a99757587fe74e6ec173477c4ca05310e25158152ff99d4f0000000000000000000000000000000000000000000000000000000000000001"),
Expand Down Expand Up @@ -152,7 +162,7 @@ func test7702() {
unsigned := &types.Authorization{
ChainID: helper.ChainID(),
Address: selfAddr,
Nonce: []uint64{helper.Nonce(selfAddr)},
Nonce: helper.Nonce(selfAddr),
}
sk := crypto.ToECDSAUnsafe(common.FromHex(txfuzz.SK))
self, _ := types.SignAuth(unsigned, sk)
Expand All @@ -161,7 +171,7 @@ func test7702() {
helper.ExecAuth(selfAddr, []byte{}, &types.AuthorizationList{self, self})
// authenticate self twice with different nonces
self2 := *self
self2.Nonce = []uint64{helper.Nonce(selfAddr) + 1}
self2.Nonce = helper.Nonce(selfAddr) + 1
self2P, _ := types.SignAuth(&self2, sk)
helper.ExecAuth(selfAddr, []byte{}, &types.AuthorizationList{self, self2P})
// unsigned authorization
Expand All @@ -178,3 +188,73 @@ func test7702() {
}
helper.ExecAuth(selfAddr, []byte{}, &list)
}

func test2935() {
contr, err := deploy2935Caller()
if err != nil {
panic(err)
}
addresses := []common.Address{
contr,
params.HistoryStorageAddress,
}

cl, _ := helper.GetRealBackend()

for _, addr := range addresses {
// empty bytes
helper.Exec(addr, []byte{}, false)
// 32 bytes random
var randomBytes [32]byte
rand.Read(randomBytes[:])
helper.Exec(addr, randomBytes[:], false)
// 33 bytes
var bigBytes [33]byte
rand.Read(bigBytes[:])
helper.Exec(addr, bigBytes[:], false)
// 32 bytes 0
var zeroBytes [32]byte
helper.Exec(addr, zeroBytes[:], false)
// 1
helper.Exec(addr, []byte{1}, false)
// block number specifics
client := ethclient.NewClient(cl)
currentBlock, err := client.BlockNumber(context.Background())
if err != nil {
panic(err)
}
// current block number
blocknumbers := []uint64{
currentBlock,
currentBlock + 1,
currentBlock - 1,
currentBlock - 8192,
currentBlock - 256,
currentBlock - 255,
}
for _, number := range blocknumbers {
helper.Exec(addr, binary.BigEndian.AppendUint64([]byte{}, number), false)
}
}
}

/*
pragma solidity >=0.7.0 <0.9.0;
contract EIP2935Caller {
bool _ok;
bytes out;
fallback (bytes calldata _input) external returns (bytes memory _output) {
address contrAddr = address(0x0AAE40965E6800cD9b1f4b05ff21581047E3F91e);
(bool ok, bytes memory output) = contrAddr.call{gas: 500000}(_input);
_output = output;
// Store return values to trigger sstore
_ok = ok;
out = output;
}
}
*/
func deploy2935Caller() (common.Address, error) {
bytecode1 := "6080604052348015600e575f80fd5b506104698061001c5f395ff3fe608060405234801561000f575f80fd5b505f3660605f730aae40965e6800cd9b1f4b05ff21581047e3f91e90505f808273ffffffffffffffffffffffffffffffffffffffff166207a1208787604051610059929190610112565b5f604051808303815f8787f1925050503d805f8114610093576040519150601f19603f3d011682016040523d82523d5f602084013e610098565b606091505b5091509150809350815f806101000a81548160ff02191690831515021790555080600190816100c79190610364565b50505050915050805190602001f35b5f81905092915050565b828183375f83830152505050565b5f6100f983856100d6565b93506101068385846100e0565b82840190509392505050565b5f61011e8284866100ee565b91508190509392505050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806101a557607f821691505b6020821081036101b8576101b7610161565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f6008830261021a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826101df565b61022486836101df565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f61026861026361025e8461023c565b610245565b61023c565b9050919050565b5f819050919050565b6102818361024e565b61029561028d8261026f565b8484546101eb565b825550505050565b5f90565b6102a961029d565b6102b4818484610278565b505050565b5b818110156102d7576102cc5f826102a1565b6001810190506102ba565b5050565b601f82111561031c576102ed816101be565b6102f6846101d0565b81016020851015610305578190505b610319610311856101d0565b8301826102b9565b50505b505050565b5f82821c905092915050565b5f61033c5f1984600802610321565b1980831691505092915050565b5f610354838361032d565b9150826002028217905092915050565b61036d8261012a565b67ffffffffffffffff81111561038657610385610134565b5b610390825461018e565b61039b8282856102db565b5f60209050601f8311600181146103cc575f84156103ba578287015190505b6103c48582610349565b86555061042b565b601f1984166103da866101be565b5f5b82811015610401578489015182556001820191506020850194506020810190506103dc565b8683101561041e578489015161041a601f89168261032d565b8355505b6001600288020188555050505b50505050505056fea264697066735822122033feaed59f5038b726e0ad09706fc2b959f0781cd00f5b4961c7ce6a676215f764736f6c634300081a0033"
return helper.Deploy(bytecode1)
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/MariusVanDerWijden/tx-fuzz

go 1.21
go 1.22

toolchain go1.21.5
toolchain go1.23.1

require (
github.com/MariusVanDerWijden/FuzzyVM v0.0.0-20240516070431-7828990cad7d
Expand All @@ -16,7 +16,7 @@ require (
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
golang.org/x/net v0.24.0 // indirect
)
Expand All @@ -25,7 +25,7 @@ require (
github.com/DataDog/zstd v1.5.5 // indirect
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.11.0 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
Expand Down Expand Up @@ -75,10 +75,10 @@ require (
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ethereum/go-ethereum => github.com/lightclient/go-ethereum v0.0.0-20240816152733-057e5d733218
replace github.com/ethereum/go-ethereum => github.com/lightclient/go-ethereum v0.0.0-20240909135523-effcd38a6e90
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKS
github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bits-and-blooms/bitset v1.11.0 h1:RMyy2mBBShArUAhfVRZJ2xyBO58KCBCtZFShw3umo6k=
github.com/bits-and-blooms/bitset v1.11.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/bits-and-blooms/bitset v1.13.0 h1:bAQ9OPNFYbGHV6Nez0tmNI0RiEu7/hxlYJRUA0wFAVE=
github.com/bits-and-blooms/bitset v1.13.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
Expand Down Expand Up @@ -58,8 +58,8 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etly
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/ethereum/c-kzg-4844 v1.0.0 h1:0X1LBXxaEtYD9xsyj9B9ctQEZIpnvVDeoBx8aHEwTNA=
github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 h1:KrE8I4reeVvf7C1tm8elRjj4BdscTYzz/WAbYyf/JI4=
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0/go.mod h1:D9AJLVXSyZQXJQVk8oh1EwjISE+sJTn2duYIZC0dy3w=
github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 h1:8NfxH2iXvJ60YRB8ChToFTUzl8awsc3cJ8CbLjGIl/A=
github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
Expand Down Expand Up @@ -128,8 +128,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/lightclient/go-ethereum v0.0.0-20240816152733-057e5d733218 h1:LtyNZ/Wul54gt29a0PlVXsCAPcrelDHe6u8927V2Lj4=
github.com/lightclient/go-ethereum v0.0.0-20240816152733-057e5d733218/go.mod h1:iBTR7NOAmQgPqbLFW8nSYcxe6gzgCm6lC6orEH7dz3U=
github.com/lightclient/go-ethereum v0.0.0-20240909135523-effcd38a6e90 h1:VKPUGkCnV33R6YwSBN7IZNrNNvvKtZP0pK4fW6OkNCk=
github.com/lightclient/go-ethereum v0.0.0-20240909135523-effcd38a6e90/go.mod h1:QeW+MtTpRdBEm2pUFoonByee8zfHv7kGp0wK0odvU1I=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
Expand Down Expand Up @@ -248,8 +248,8 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
6 changes: 3 additions & 3 deletions helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func ExecAuth(addr common.Address, data []byte, authList *types.AuthorizationLis
}
authList = &aList
}
tx := txfuzz.New7702Tx(nonce, &addr, gasLimit, chainid, tip.Mul(tip, common.Big1), gp.Mul(gp, common.Big1), common.Big0, data, big.NewInt(1_000_000), make(types.AccessList, 0), *authList)
signedTx, _ := types.SignTx(tx, types.NewCancunSigner(chainid), sk)
tx := txfuzz.New7702Tx(nonce, addr, gasLimit, chainid, tip.Mul(tip, common.Big1), gp.Mul(gp, common.Big1), common.Big0, data, big.NewInt(1_000_000), make(types.AccessList, 0), *authList)
signedTx, _ := types.SignTx(tx, types.NewPragueSigner(chainid), sk)
rlpData, err = signedTx.MarshalBinary()
if err != nil {
panic(err)
Expand Down Expand Up @@ -178,7 +178,7 @@ func Deploy(bytecode string) (common.Address, error) {
fmt.Printf("Nonce: %v\n", nonce)
gp, _ := backend.SuggestGasPrice(context.Background())
tx := types.NewContractCreation(nonce, common.Big0, 500000, gp.Mul(gp, common.Big2), common.Hex2Bytes(bytecode))
signedTx, _ := types.SignTx(tx, types.NewLondonSigner(chainid), sk)
signedTx, _ := types.SignTx(tx, types.NewCancunSigner(chainid), sk)
if err := backend.SendTransaction(context.Background(), signedTx); err != nil {
return common.Address{}, err
}
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package txfuzz

var (
RPC = "http://127.0.0.1:8545"
SK = "0xcdfbe6f7602f67a97602e3e9fc24cde1cdffa88acd47745c0b84c5ff55891e1b"
ADDR = "0xb02A2EdA1b317FBd16760128836B0Ac59B560e9D"
RPC = "https://rpc.pectra-devnet-3.ethpandaops.io"
SK = "0x9c07c2221efd8cef3e81511f463eebe803a6feda7a27ef2dc0e25001f09248aa"
ADDR = "0x7a40026A3b9A41754a95EeC8c92C6B99886f440C"
SK2 = "0x8c04e41e317a7cf0cf4c2f7431d0a890a950f352df41ff6d053698df61a73bba"
)
2 changes: 1 addition & 1 deletion random.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func randomAuthEntry(f *filler.Filler) *types.Authorization {
return &types.Authorization{
ChainID: f.MemInt(),
Address: randomAddress(),
Nonce: []uint64{f.Uint64()},
Nonce: f.Uint64(),
}
}

Expand Down
7 changes: 2 additions & 5 deletions transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ func RandomAuthTx(rpc *rpc.Client, f *filler.Filler, sender common.Address, nonc
if err != nil {
return nil, err
}
if rand.Int()%2 == 0 {
conf.to = nil // create a contract half of the time
}
return New7702Tx(conf.nonce, conf.to, conf.gasLimit, conf.chainID, tip, feecap, conf.value, conf.code, big.NewInt(1000000), list, aList), nil
return New7702Tx(conf.nonce, *conf.to, conf.gasLimit, conf.chainID, tip, feecap, conf.value, conf.code, big.NewInt(1000000), list, aList), nil
}

type txCreationStrategy func(conf *txConf) (*types.Transaction, error)
Expand Down Expand Up @@ -405,7 +402,7 @@ func kZGToVersionedHash(kzg kzg4844.Commitment) common.Hash {
return h
}

func New7702Tx(nonce uint64, to *common.Address, gasLimit uint64, chainID, tip, feeCap, value *big.Int, code []byte, blobFeeCap *big.Int, al types.AccessList, auth types.AuthorizationList) *types.Transaction {
func New7702Tx(nonce uint64, to common.Address, gasLimit uint64, chainID, tip, feeCap, value *big.Int, code []byte, blobFeeCap *big.Int, al types.AccessList, auth types.AuthorizationList) *types.Transaction {
return types.NewTx(
&types.SetCodeTx{
ChainID: uint256.MustFromBig(chainID),
Expand Down

0 comments on commit 940d729

Please sign in to comment.