Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build: build-abi build-bin build-abi-go

build-abi: src/**
mkdir -p abi
forge inspect src/Simulator.sol:Simulator abi --json > abi/Simulator.json
forge inspect contracts/src/Simulator.sol:Simulator abi --json > abi/Simulator.json

build-bin: src/**
forge build --extra-output-files bin --force
Expand Down
31 changes: 19 additions & 12 deletions contracts/src/Simulator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -319,26 +319,33 @@ contract Simulator {

function run_blake2f(uint256 num_iterations) private {
bytes32[2] memory h;
h[0] = 0x48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5;
h[1] = 0xd182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b;
h[0] = 0xa1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8;
h[1] = 0xa1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8a1b2c3d4e5f6a7b8;

bytes32[4] memory m;
m[0] = 0x6162630000000000000000000000000000000000000000000000000000000000;
m[1] = 0x0000000000000000000000000000000000000000000000000000000000000000;
m[2] = 0x0000000000000000000000000000000000000000000000000000000000000000;
m[3] = 0x0000000000000000000000000000000000000000000000000000000000000000;
m[0] = 0xc3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2;
m[1] = 0xc3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2;
m[2] = 0xc3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2;
m[3] = 0xc3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2c3d4e5f6a7b8c1d2;

bytes8[2] memory t;
t[0] = 0x0300000000000000;
t[1] = 0x0000000000000000;
t[0] = 0x0000000000000000;
t[1] = 0x0000000000ff00ff;

bool f = true;

for (uint256 i = 0; i < num_iterations; i++) {
uint32 rounds = uint32(i);
(bool ok,) =
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
require(ok, "Blake2f failed");
uint32 rounds = 0xc00;
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
address(9).staticcall(abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f));
}
}

Expand Down
9 changes: 8 additions & 1 deletion runner/network/consensus/sequencer_consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ func (f *SequencerConsensusClient) generatePayloadAttributes(sequencerTxs [][]by
var b8 eth.Bytes8
copy(b8[:], eip1559.EncodeHolocene1559Params(50, 1))

timestamp := f.lastTimestamp + 1
lastTimestamp := f.lastTimestamp

// if the last timestamp is more than 2 seconds in the past, set it to the current time
if int64(lastTimestamp)-time.Now().Unix() < -2 {
lastTimestamp = uint64(time.Now().Unix())
}

timestamp := lastTimestamp + 1

number := uint64(0)
time := uint64(0)
Expand Down
2 changes: 1 addition & 1 deletion runner/payload/simulator/abi/Simulator.go

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions runner/payload/simulator/simulatorstats/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package simulatorstats

import (
"crypto/sha256"
"encoding/json"
"fmt"
"maps"
"math"
Expand Down Expand Up @@ -222,6 +224,16 @@ type Stats struct {
Precompiles OpcodeStats
}

func (s *Stats) Hash() common.Hash {

data, err := json.Marshal(s)
if err != nil {
panic(err)
}
hash := sha256.Sum256(data)
return common.Hash(hash[:])
}

func (s *Stats) ToConfig() (*abi.SimulatorConfig, error) {
rounded := s.Copy().Round()
precompiles := make([]abi.PrecompileConfig, 0, len(rounded.Precompiles))
Expand Down
38 changes: 35 additions & 3 deletions runner/payload/simulator/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ type Contract struct {
type SimulatorPayloadDefinition = simulatorstats.StatsConfig

type simulatorPayloadWorker struct {
log log.Logger
log log.Logger
gasUsedCache map[common.Hash]uint64

params benchtypes.RunParams
chainID *big.Int
Expand Down Expand Up @@ -139,12 +140,22 @@ func NewSimulatorPayloadWorker(ctx context.Context, log log.Logger, elRPCURL str

// Create transactors for each caller
transactors := make([]*bind.TransactOpts, numCallers)

for i, key := range callerKeys {
transactor, err := bind.NewKeyedTransactorWithChainID(key, chainID)
if err != nil {
return nil, errors.Wrapf(err, "failed to create transactor for caller %d", i)
}
transactor.NoSend = true
nonce, err := client.PendingNonceAt(context.Background(), crypto.PubkeyToAddress(key.PublicKey))
if err != nil {
return nil, errors.Wrapf(err, "failed to get nonce for caller %d", i)
}
transactor.Nonce = big.NewInt(int64(nonce))

transactor.GasFeeCap = new(big.Int).Mul(big.NewInt(1e9), big.NewInt(1))
transactor.GasTipCap = big.NewInt(1)

transactors[i] = transactor
}

Expand Down Expand Up @@ -192,6 +203,7 @@ func NewSimulatorPayloadWorker(ctx context.Context, log log.Logger, elRPCURL str
scaleFactor: scaleFactor,
actualNumConfig: simulatorstats.NewStats(),
numCallers: numCallers,
gasUsedCache: make(map[common.Hash]uint64),
}

return t, nil
Expand Down Expand Up @@ -469,6 +481,11 @@ func (t *simulatorPayloadWorker) fundCallerAccounts(ctx context.Context) error {
// If using just the prefunded account, no funding transfer needed
if t.numCallers == 1 && t.callerAddrs[0] == prefundAddr {
t.log.Info("Using single caller (prefunded account)", "address", prefundAddr.Hex())
pendingNonce, err := t.client.PendingNonceAt(ctx, prefundAddr)
if err != nil {
return errors.Wrap(err, "failed to get pending nonce for prefunded account")
}
t.transactors[0].Nonce = big.NewInt(int64(pendingNonce))
return nil
}

Expand Down Expand Up @@ -562,21 +579,34 @@ func (t *simulatorPayloadWorker) sendTxs(ctx context.Context) error {

gas := t.params.GasLimit - 100_000

sendTxsStartTime := time.Now()

for i := uint64(0); i < uint64(math.Ceil(float64(t.numCallsPerBlock)*t.scaleFactor)); i++ {
actual := t.actualNumConfig
expected := t.payloadParams.Mul(float64(t.numCalls+1) * t.scaleFactor)

// Round-robin across callers
callerIdx := t.currCallerIdx
t.currCallerIdx = (t.currCallerIdx + 1) % t.numCallers

blockCounts := expected.Sub(actual).Round()

expectedGas, ok := t.gasUsedCache[blockCounts.Hash()]
if ok {
t.transactors[callerIdx].GasLimit = expectedGas
} else {
t.transactors[callerIdx].GasLimit = 0
}

transferTx, err := t.createCallTx(t.transactors[callerIdx], t.callerKeys[callerIdx], blockCounts)
if err != nil {
t.log.Error("Failed to create transfer transaction", "err", err)
return err
}

t.gasUsedCache[blockCounts.Hash()] = transferTx.Gas()

t.transactors[callerIdx].Nonce = t.transactors[callerIdx].Nonce.Add(t.transactors[callerIdx].Nonce, big.NewInt(1))

gasUsed := transferTx.Gas()
if gasUsed > gas {
t.log.Warn("Gas used is greater than gas limit, stopping tx sending", "gasUsed", gasUsed, "gasLimit", t.params.GasLimit)
Expand All @@ -594,11 +624,13 @@ func (t *simulatorPayloadWorker) sendTxs(ctx context.Context) error {
}

t.mempool.AddTransactions(txs)
sendTxsDuration := time.Since(sendTxsStartTime)
log.Info("Send transactions duration", "duration", sendTxsDuration, "numCalls", uint64(math.Ceil(float64(t.numCallsPerBlock)*t.scaleFactor)))
return nil
}

func (t *simulatorPayloadWorker) createCallTx(transactor *bind.TransactOpts, fromPriv *ecdsa.PrivateKey, config *simulatorstats.Stats) (*types.Transaction, error) {
simulator, err := abi.NewSimulator(t.contractAddr, t.contractBackend)
simulator, err := abi.NewSimulatorTransactor(t.contractAddr, t.contractBackend)
if err != nil {
return nil, errors.Wrap(err, "failed to create simulator transactor")
}
Expand Down