Skip to content
Merged
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
9 changes: 9 additions & 0 deletions oracle/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ var (
"https://bloxroute.regulated.blxrbdn.com",
),
})

optionBidOptionsSlashEnabled = altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "bid-options-slash-enabled",
Usage: "Enable slashing based on bid options (position constraints, shutterised bids)",
EnvVars: []string{"MEV_ORACLE_BID_OPTIONS_SLASH_ENABLED"},
Value: false,
})
)

func main() {
Expand Down Expand Up @@ -288,6 +295,7 @@ func main() {
optionGasTipCap,
optionGasFeeCap,
optionRelayUrls,
optionBidOptionsSlashEnabled,
}
app := &cli.App{
Name: "mev-oracle",
Expand Down Expand Up @@ -408,6 +416,7 @@ func launchOracleWithConfig(c *cli.Context) error {
DefaultGasTipCap: gasTipCap,
DefaultGasFeeCap: gasFeeCap,
RelayUrls: c.StringSlice(optionRelayUrls.Name),
BidOptionsSlashEnabled: c.Bool(optionBidOptionsSlashEnabled.Name),
})
if err != nil {
return fmt.Errorf("failed starting node: %w", err)
Expand Down
2 changes: 2 additions & 0 deletions oracle/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Options struct {
DefaultGasLimit uint64
DefaultGasTipCap *big.Int
DefaultGasFeeCap *big.Int
BidOptionsSlashEnabled bool
}

type Node struct {
Expand Down Expand Up @@ -269,6 +270,7 @@ func NewNode(opts *Options) (*Node, error) {
evtMgr,
oracleTransactorSession,
txmonitor.NewEVMHelperWithLogger(rawClient, nd.logger, contracts),
opts.BidOptionsSlashEnabled,
)
if err != nil {
nd.logger.Error("failed to instantiate updater", "error", err)
Expand Down
112 changes: 61 additions & 51 deletions oracle/pkg/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ type EVMClient interface {
}

type Updater struct {
logger *slog.Logger
l1Client EVMClient
winnerRegister WinnerRegister
oracle Oracle
evtMgr events.EventManager
l1BlockCache *lru.Cache[uint64, map[string]TxMetadata]
openedCmts chan *preconf.PreconfmanagerOpenedCommitmentStored
metrics *metrics
receiptBatcher txmonitor.BatchReceiptGetter
logger *slog.Logger
l1Client EVMClient
winnerRegister WinnerRegister
oracle Oracle
evtMgr events.EventManager
l1BlockCache *lru.Cache[uint64, map[string]TxMetadata]
openedCmts chan *preconf.PreconfmanagerOpenedCommitmentStored
metrics *metrics
receiptBatcher txmonitor.BatchReceiptGetter
bidOptionsSlashEnabled bool
}

func NewUpdater(
Expand All @@ -102,21 +103,23 @@ func NewUpdater(
evtMgr events.EventManager,
oracle Oracle,
receiptBatcher txmonitor.BatchReceiptGetter,
bidOptionsSlashEnabled bool,
) (*Updater, error) {
l1BlockCache, err := lru.New[uint64, map[string]TxMetadata](1024)
if err != nil {
return nil, fmt.Errorf("failed to create L1 block cache: %w", err)
}
return &Updater{
logger: logger,
l1Client: l1Client,
l1BlockCache: l1BlockCache,
winnerRegister: winnerRegister,
evtMgr: evtMgr,
oracle: oracle,
receiptBatcher: receiptBatcher,
metrics: newMetrics(),
openedCmts: make(chan *preconf.PreconfmanagerOpenedCommitmentStored),
logger: logger,
l1Client: l1Client,
l1BlockCache: l1BlockCache,
winnerRegister: winnerRegister,
evtMgr: evtMgr,
oracle: oracle,
receiptBatcher: receiptBatcher,
metrics: newMetrics(),
openedCmts: make(chan *preconf.PreconfmanagerOpenedCommitmentStored),
bidOptionsSlashEnabled: bidOptionsSlashEnabled,
}, nil
}

Expand Down Expand Up @@ -309,15 +312,18 @@ func (u *Updater) handleOpenedCommitment(
revertableTxnsMap[txn] = true
}

opts := new(bidderapiv1.BidOptions)
if update.BidOptions != nil {
if err := proto.Unmarshal(update.BidOptions, opts); err != nil {
u.logger.Error(
"failed to unmarshal bid options",
"commitmentIdx", common.Bytes2Hex(update.CommitmentIndex[:]),
"error", err,
)
return err
var opts *bidderapiv1.BidOptions
if u.bidOptionsSlashEnabled {
opts = new(bidderapiv1.BidOptions)
if update.BidOptions != nil {
if err := proto.Unmarshal(update.BidOptions, opts); err != nil {
u.logger.Error(
"failed to unmarshal bid options",
"commitmentIdx", common.Bytes2Hex(update.CommitmentIndex[:]),
"error", err,
)
return err
}
}
}

Expand All @@ -339,16 +345,18 @@ func (u *Updater) handleOpenedCommitment(
"revertible", revertableTxnsMap[commitmentTxnHashes[i]],
)

for _, opt := range opts.Options {
if sOpt := opt.GetShutterisedBidOption(); sOpt != nil {
u.logger.Info(
"shutterised bid option present, skipping slash",
"commitmentIdx", common.Bytes2Hex(update.CommitmentIndex[:]),
"txnHash", update.TxnHash,
"blockNumber", update.BlockNumber,
"shutter option", sOpt,
)
return nil
if u.bidOptionsSlashEnabled {
for _, opt := range opts.Options {
if sOpt := opt.GetShutterisedBidOption(); sOpt != nil {
u.logger.Info(
"shutterised bid option present, skipping slash",
"commitmentIdx", common.Bytes2Hex(update.CommitmentIndex[:]),
"txnHash", update.TxnHash,
"blockNumber", update.BlockNumber,
"shutter option", sOpt,
)
return nil
}
}
}

Expand All @@ -362,25 +370,27 @@ func (u *Updater) handleOpenedCommitment(
)
}

for idx, opt := range opts.Options {
if opt.GetPositionConstraint() != nil {
if checkPositionConstraintSatisfied(opt.GetPositionConstraint(), txnDetails, txns) {
u.logger.Debug(
"positional constraint satisfied",
"commitmentIdx", common.Bytes2Hex(update.CommitmentIndex[:]),
"txnHash", update.TxnHash,
"blockNumber", update.BlockNumber,
"constraint", opt.GetPositionConstraint(),
)
// Remove the satisfied constraint
opts.Options = append(opts.Options[:idx], opts.Options[idx+1:]...)
break
if u.bidOptionsSlashEnabled {
for idx, opt := range opts.Options {
if opt.GetPositionConstraint() != nil {
if checkPositionConstraintSatisfied(opt.GetPositionConstraint(), txnDetails, txns) {
u.logger.Debug(
"positional constraint satisfied",
"commitmentIdx", common.Bytes2Hex(update.CommitmentIndex[:]),
"txnHash", update.TxnHash,
"blockNumber", update.BlockNumber,
"constraint", opt.GetPositionConstraint(),
)
// Remove the satisfied constraint
opts.Options = append(opts.Options[:idx], opts.Options[idx+1:]...)
break
}
}
}
}
}

if len(opts.Options) > 0 {
if u.bidOptionsSlashEnabled && len(opts.Options) > 0 {
u.logger.Info(
"not all positional constraints satisfied",
"commitmentIdx", common.Bytes2Hex(update.CommitmentIndex[:]),
Expand Down
Loading
Loading