Skip to content

Commit

Permalink
cmd/prague: add tests with valid EIP-7002 and EIP-7251 requests (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl authored Oct 25, 2024
1 parent 695060b commit 6e0def6
Showing 1 changed file with 87 additions and 2 deletions.
89 changes: 87 additions & 2 deletions cmd/prague/main.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
package main

import (
"context"
"fmt"
"math/big"
"time"

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

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"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"
)

func main() {
testTouchContracts()
test2537()
test2537Long()
test3074()
test7002()
test7251()
}

func testTouchContracts() {
// touch beacon root addr
addresses := []common.Address{
common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02"), // beacon roots
common.HexToAddress("0x00A3ca265EBcb825B45F985A16CEFB49958cE017"), // withdrawal requests
common.HexToAddress("0x09Fc772D0857550724b07B850a4323f39112aAaA"), // withdrawal requests
common.HexToAddress("0x01aBEa29659e5e97C95107F20bb753cD3e09bBBb"), // consolidation requests
common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe"), // system address
common.HexToAddress("0x25a219378dad9b3503c8268c9ca836a52427a4fb"), // history storage address
common.HexToAddress("0x00000000219ab540356cbb839cbe05303d7705fa"), // mainnet deposit contract
Expand Down Expand Up @@ -89,6 +97,48 @@ func test2537() {
}
}

// test7002 creates withdrawal requests in the EIP-7002 queue.
func test7002() {
fmt.Println("test7002")

cl, _ := helper.GetRealBackend()
backend := ethclient.NewClient(cl)

contract := common.HexToAddress("0x09Fc772D0857550724b07B850a4323f39112aAaA")
value := big.NewInt(1000000000)
inputs := [][]byte{
// input data is pubkey(48) || amount(8)
common.FromHex("b917cfdc0d25b72d55cf94db328e1629b7f4fde2c30cdacf873b664416f76a0c7f7cc50c9f72a3cb84be88144cde91250000000000000d80"),
common.FromHex("b9812f7d0b1f2f969b52bbb2d316b0c2fa7c9dba85c428c5e6c27766bcc4b0c6e874702ff1eb1c7024b08524a977160100000000000f423f"),
}
for i, data := range inputs {
tx := makeTxWithValue(contract, value, data)
if err := backend.SendTransaction(context.Background(), tx); err != nil {
panic("SendTransaction: " + err.Error())
}
receipt, err := bind.WaitMined(context.Background(), backend, tx)
if err != nil {
panic("WaitMined: " + err.Error())
}
if receipt.Status != types.ReceiptStatusSuccessful {
panic(fmt.Sprintf("test7002 tx %d reverted", i))
}
}
}

// test7251 creates consolidation requests in the EIP-7251 queue.
func test7251() {
fmt.Println("test7251")
contract := common.HexToAddress("0x01aBEa29659e5e97C95107F20bb753cD3e09bBBb")
inputs := [][]byte{
// input data is source_blskey(48) || target_blskey(48)
common.FromHex("b917cfdc0d25b72d55cf94db328e1629b7f4fde2c30cdacf873b664416f76a0c7f7cc50c9f72a3cb84be88144cde9125b9812f7d0b1f2f969b52bbb2d316b0c2fa7c9dba85c428c5e6c27766bcc4b0c6e874702ff1eb1c7024b08524a9771601"),
}
for _, data := range inputs {
helper.Exec(contract, data, false)
}
}

func test2537Long() {
multiexpG1 := common.FromHex("00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")
testLongBLS(0x0d, multiexpG1)
Expand Down Expand Up @@ -142,3 +192,38 @@ func deployPrecompileCaller(precompile string) (common.Address, error) {
// The byte in between bytecode1 and bytecode2 denotes the precompile which we want to call
return helper.Deploy(fmt.Sprintf("%v%v%v", bytecode1, precompile, bytecode2))
}

// makeTxWithValue creates a transaction invoking addr, sending eth along with calldata.
func makeTxWithValue(addr common.Address, value *big.Int, data []byte) *types.Transaction {
ctx := context.Background()
cl, sk := helper.GetRealBackend()
backend := ethclient.NewClient(cl)
sender := common.HexToAddress(txfuzz.ADDR)
nonce, err := backend.PendingNonceAt(ctx, sender)
if err != nil {
panic(err)
}
chainid, err := backend.ChainID(ctx)
if err != nil {
panic(err)
}
fmt.Printf("Nonce: %v\n", nonce)
gp, err := backend.SuggestGasPrice(ctx)
if err != nil {
panic(err)
}
tip, err := backend.SuggestGasTipCap(ctx)
if err != nil {
panic(err)
}
return types.MustSignNewTx(sk, types.NewCancunSigner(chainid), &types.DynamicFeeTx{
ChainID: chainid,
Nonce: nonce,
GasTipCap: tip,
GasFeeCap: gp,
Gas: 200_000,
Value: value,
To: &addr,
Data: data,
})
}

0 comments on commit 6e0def6

Please sign in to comment.