@@ -280,12 +280,15 @@ func (st *StateTransition) buyGas() error {
280280 mgval .Add (mgval , blobFee )
281281 }
282282 }
283- balanceCheckU256 , overflow := uint256 .FromBig (balanceCheck )
284- if overflow {
285- return fmt .Errorf ("%w: address %v required balance exceeds 256 bits" , ErrInsufficientFunds , st .msg .From .Hex ())
286- }
287- if have , want := st .state .GetBalance (st .msg .From ), balanceCheckU256 ; have .Cmp (want ) < 0 {
288- return fmt .Errorf ("%w: address %v have %v want %v" , ErrInsufficientFunds , st .msg .From .Hex (), have , want )
283+ // Skip balance check for deposit transactions (free gas)
284+ if ! st .msg .IsDepositTx {
285+ balanceCheckU256 , overflow := uint256 .FromBig (balanceCheck )
286+ if overflow {
287+ return fmt .Errorf ("%w: address %v required balance exceeds 256 bits" , ErrInsufficientFunds , st .msg .From .Hex ())
288+ }
289+ if have , want := st .state .GetBalance (st .msg .From ), balanceCheckU256 ; have .Cmp (want ) < 0 {
290+ return fmt .Errorf ("%w: address %v have %v want %v" , ErrInsufficientFunds , st .msg .From .Hex (), have , want )
291+ }
289292 }
290293 if err := st .gp .SubGas (st .msg .GasLimit ); err != nil {
291294 return err
@@ -297,8 +300,11 @@ func (st *StateTransition) buyGas() error {
297300 st .gasRemaining = st .msg .GasLimit
298301
299302 st .initialGas = st .msg .GasLimit
300- mgvalU256 , _ := uint256 .FromBig (mgval )
301- st .state .SubBalance (st .msg .From , mgvalU256 , tracing .BalanceDecreaseGasBuy )
303+ // Skip balance subtraction for deposit transactions (free gas)
304+ if ! st .msg .IsDepositTx {
305+ mgvalU256 , _ := uint256 .FromBig (mgval )
306+ st .state .SubBalance (st .msg .From , mgvalU256 , tracing .BalanceDecreaseGasBuy )
307+ }
302308 return nil
303309}
304310
@@ -664,7 +670,8 @@ func (st *StateTransition) refundGas(refundQuotient uint64) uint64 {
664670 remaining := uint256 .NewInt (st .gasRemaining )
665671 remaining .Mul (remaining , uint256 .MustFromBig (st .msg .GasPrice ))
666672
667- if st .msg .From != params .OptimismSystemAddress {
673+ // Skip gas refund for deposit transactions (keep balance at zero)
674+ if ! st .msg .IsDepositTx && st .msg .From != params .OptimismSystemAddress {
668675 st .state .AddBalance (st .msg .From , remaining , tracing .BalanceIncreaseGasReturn )
669676 }
670677
0 commit comments