@@ -2,6 +2,8 @@ package fees
2
2
3
3
import (
4
4
"bytes"
5
+ "github.com/scroll-tech/da-codec/encoding/zstd"
6
+ "github.com/scroll-tech/go-ethereum/log"
5
7
"math"
6
8
"math/big"
7
9
@@ -203,11 +205,22 @@ func calculateEncodedRollupFeeFeeFeynman(
203
205
execScalar * big.Int ,
204
206
blobScalar * big.Int ,
205
207
) * big.Int {
206
- // tx size (RLP-encoded)
207
208
txSize := big .NewInt (int64 (len (data )))
208
209
209
- // compression_ratio(tx) = 1 (placeholder, scaled to match scalars precision)
210
- compressionRatio := big .NewInt (rcfg .Precision .Int64 ())
210
+ // Default compression ratio is 1.0 (no compression)
211
+ compressionRatioInt := big .NewInt (rcfg .Precision .Int64 ())
212
+
213
+ if len (data ) != 0 {
214
+ compressedBytes , err := zstd .CompressScrollBatchBytes (data )
215
+ if err != nil {
216
+ log .Error ("Compress batch compress failed, using 1.0" , "err" , err )
217
+ } else {
218
+ compressedSize := big .NewInt (int64 (len (compressedBytes )))
219
+ // compressionRatioInt = (compressedSize * precision) / txSize
220
+ compressionRatioInt .Mul (compressedSize , rcfg .Precision )
221
+ compressionRatioInt .Div (compressionRatioInt , txSize )
222
+ }
223
+ }
211
224
212
225
// compute gas components
213
226
execGas := new (big.Int ).Mul (execScalar , l1BaseFee )
@@ -217,7 +230,7 @@ func calculateEncodedRollupFeeFeeFeynman(
217
230
feePerByte := new (big.Int ).Add (execGas , blobGas )
218
231
219
232
// rollupFee = compression_ratio * tx_size * feePerByte
220
- rollupFee := new (big.Int ).Mul (compressionRatio , txSize )
233
+ rollupFee := new (big.Int ).Mul (compressionRatioInt , txSize )
221
234
rollupFee .Mul (rollupFee , feePerByte )
222
235
223
236
// Divide by rcfg.Precision (once for ratio, once for scalar)
0 commit comments