Skip to content

Commit 6796e57

Browse files
author
corey
committed
fix
1 parent 3938164 commit 6796e57

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

token-price-oracle/client/sign.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (s *Signer) CreateAndSignTx(
104104
if maxTip := client.GetMaxGasTipCap(); maxTip != nil {
105105
if tip.Cmp(maxTip) > 0 {
106106
log.Debug("Applying gas tip cap limit", "dynamic", tip, "cap", maxTip)
107-
tip = maxTip
107+
tip = new(big.Int).Set(maxTip)
108108
}
109109
}
110110

@@ -129,10 +129,16 @@ func (s *Signer) CreateAndSignTx(
129129
if maxFeeCap := client.GetMaxGasFeeCap(); maxFeeCap != nil {
130130
if gasFeeCap.Cmp(maxFeeCap) > 0 {
131131
log.Debug("Applying gas fee cap limit", "dynamic", gasFeeCap, "cap", maxFeeCap)
132-
gasFeeCap = maxFeeCap
132+
gasFeeCap = new(big.Int).Set(maxFeeCap)
133133
}
134134
}
135135

136+
// Ensure gasTipCap <= gasFeeCap (EIP-1559 invariant)
137+
if tip.Cmp(gasFeeCap) > 0 {
138+
log.Debug("Clamping tip to gasFeeCap", "tip", tip, "gasFeeCap", gasFeeCap)
139+
tip = new(big.Int).Set(gasFeeCap)
140+
}
141+
136142
// Estimate gas
137143
gas, err := client.GetClient().EstimateGas(ctx, ethereum.CallMsg{
138144
From: from,

token-price-oracle/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ func LoadConfig(ctx *cli.Context) (*Config, error) {
126126
cfg.GasTipCap = &v
127127
}
128128

129+
// Validate GasFeeCap >= GasTipCap when both are set (EIP-1559 invariant)
130+
if cfg.GasFeeCap != nil && cfg.GasTipCap != nil && *cfg.GasFeeCap < *cfg.GasTipCap {
131+
return nil, fmt.Errorf("--gas-fee-cap (%d) must be >= --gas-tip-cap (%d)", *cfg.GasFeeCap, *cfg.GasTipCap)
132+
}
133+
129134
// Parse token registry address (optional)
130135
cfg.L2TokenRegistryAddr = predeploys.L2TokenRegistryAddr
131136

token-price-oracle/updater/tx_manager.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ func (m *TxManager) applyGasCaps(ctx context.Context, auth *bind.TransactOpts) e
247247
}
248248
auth.GasFeeCap = gasFeeCap
249249

250+
// Ensure gasTipCap <= gasFeeCap (EIP-1559 invariant)
251+
if auth.GasTipCap.Cmp(auth.GasFeeCap) > 0 {
252+
log.Debug("Clamping tip to gasFeeCap", "tip", auth.GasTipCap, "gasFeeCap", auth.GasFeeCap)
253+
auth.GasTipCap = new(big.Int).Set(auth.GasFeeCap)
254+
}
255+
250256
log.Debug("Gas caps applied", "tipCap", auth.GasTipCap, "feeCap", auth.GasFeeCap)
251257
return nil
252258
}

0 commit comments

Comments
 (0)