Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan committed Nov 1, 2023
1 parent 98437ce commit 9a3770f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
21 changes: 15 additions & 6 deletions arbos/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"math"
"math/big"
"strings"

"github.com/offchainlabs/nitro/arbos/arbosState"
"github.com/offchainlabs/nitro/arbos/arbostypes"
Expand Down Expand Up @@ -127,7 +126,8 @@ func NoopSequencingHooks() *SequencingHooks {
}

type ProduceConfig struct {
evil bool
evil bool
interceptDepositGweiAmount *big.Int
}
type ProduceOpt func(*ProduceConfig)

Expand All @@ -137,6 +137,15 @@ func WithEvilProduction() ProduceOpt {
}
}

func WithInterceptDepositSize(depositGwei *big.Int) ProduceOpt {
return func(pc *ProduceConfig) {
pc.interceptDepositGweiAmount = depositGwei
}
}

// By default, intercept and modify any Arbitrum deposits with a value of a 1M gwei.
var DefaultEvilInterceptDepositGweiAmount = big.NewInt(1_000_000 * params.GWei)

func ProduceBlock(
message *arbostypes.L1IncomingMessage,
delayedMessagesRead uint64,
Expand Down Expand Up @@ -169,7 +178,9 @@ func ProduceBlock(
txes = types.Transactions{}
}

produceCfg := &ProduceConfig{}
produceCfg := &ProduceConfig{
interceptDepositGweiAmount: DefaultEvilInterceptDepositGweiAmount,
}
for _, o := range opts {
o(produceCfg)
}
Expand All @@ -184,9 +195,7 @@ func ProduceBlock(
modifiedTxs = append(modifiedTxs, tx)
continue
}
currValue := fmt.Sprintf("%#x", txData.Value.Bytes())
wanted := "2386f26fc10000"
if !strings.Contains(currValue, wanted) {
if txData.Value.Cmp(produceCfg.interceptDepositGweiAmount) != 0 {
modifiedTxs = append(modifiedTxs, tx)
continue
}
Expand Down
1 change: 1 addition & 0 deletions execution/gethexec/block_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (r *BlockRecorder) RecordBlockCreation(
opts := make([]arbos.ProduceOpt, 0)
if r.execEngine.evil {
opts = append(opts, arbos.WithEvilProduction())
opts = append(opts, arbos.WithInterceptDepositSize(r.execEngine.interceptDepositGweiAmount))
}
block, _, err := arbos.ProduceBlock(
msg.Message,
Expand Down
20 changes: 15 additions & 5 deletions execution/gethexec/executionengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"math/big"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -40,8 +41,9 @@ type ExecutionEngine struct {

nextScheduledVersionCheck time.Time // protected by the createBlocksMutex

reorgSequencing bool
evil bool
reorgSequencing bool
evil bool
interceptDepositGweiAmount *big.Int
}

type Opt func(*ExecutionEngine)
Expand All @@ -52,11 +54,18 @@ func WithEvilExecution() Opt {
}
}

func WithInterceptDepositSize(depositGwei *big.Int) Opt {
return func(exec *ExecutionEngine) {
exec.interceptDepositGweiAmount = depositGwei
}
}

func NewExecutionEngine(bc *core.BlockChain, opts ...Opt) (*ExecutionEngine, error) {
exec := &ExecutionEngine{
bc: bc,
resequenceChan: make(chan []*arbostypes.MessageWithMetadata),
newBlockNotifier: make(chan struct{}, 1),
bc: bc,
resequenceChan: make(chan []*arbostypes.MessageWithMetadata),
newBlockNotifier: make(chan struct{}, 1),
interceptDepositGweiAmount: arbos.DefaultEvilInterceptDepositGweiAmount,
}
for _, o := range opts {
o(exec)
Expand Down Expand Up @@ -458,6 +467,7 @@ func (s *ExecutionEngine) createBlockFromNextMessage(msg *arbostypes.MessageWith
opts := make([]arbos.ProduceOpt, 0)
if s.evil {
opts = append(opts, arbos.WithEvilProduction())
opts = append(opts, arbos.WithInterceptDepositSize(s.interceptDepositGweiAmount))
}
block, receipts, err := arbos.ProduceBlock(
msg.Message,
Expand Down

0 comments on commit 9a3770f

Please sign in to comment.