1818 ErrNilPackedPrice = errors .New ("packed price cannot be nil" )
1919 // ErrNegativePackedPrice is returned when a negative packed price is passed to UnpackGasPrice.
2020 ErrNegativePackedPrice = errors .New ("packed price cannot be negative" )
21+
22+ // Pre-computed bit masks for gas price packing/unpacking
23+ mask112 = maxUint (112 ) // 2^112 - 1, used for 112-bit values
24+ mask224 = maxUint (224 ) // 2^224 - 1, used for 224-bit packed values
2125)
2226
2327// maxUint returns 2^bits - 1, which is the maximum value for an unsigned integer of the given bit length.
@@ -43,10 +47,10 @@ func PackGasPrice(executionGasPrice, dataAvailabilityGasPrice *big.Int) (*big.In
4347 if executionGasPrice .Sign () < 0 || dataAvailabilityGasPrice .Sign () < 0 {
4448 return nil , ErrNegativeGasPrice
4549 }
46- if executionGasPrice .Cmp (maxUint ( 112 ) ) > 0 {
50+ if executionGasPrice .Cmp (mask112 ) > 0 {
4751 return nil , ErrGasPriceExceeds112Bits
4852 }
49- if dataAvailabilityGasPrice .Cmp (maxUint ( 112 ) ) > 0 {
53+ if dataAvailabilityGasPrice .Cmp (mask112 ) > 0 {
5054 return nil , ErrGasPriceExceeds112Bits
5155 }
5256
@@ -74,11 +78,11 @@ func UnpackGasPrice(packedPrice *big.Int) (executionGasPrice, dataAvailabilityGa
7478 if packedPrice .Sign () < 0 {
7579 return nil , nil , ErrNegativePackedPrice
7680 }
77- if packedPrice .Cmp (maxUint ( 224 ) ) > 0 {
81+ if packedPrice .Cmp (mask224 ) > 0 {
7882 return nil , nil , ErrPackedPriceExceeds224Bits
7983 }
8084
81- executionGasPrice = new (big.Int ).And (packedPrice , maxUint ( 112 ) )
85+ executionGasPrice = new (big.Int ).And (packedPrice , mask112 )
8286 dataAvailabilityGasPrice = new (big.Int ).Rsh (packedPrice , 112 )
8387
8488 return executionGasPrice , dataAvailabilityGasPrice , nil
0 commit comments