diff --git a/params/version.go b/params/version.go index 6922f55f136..09b939c2b2c 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 9 // Minor version component of the current release - VersionPatch = 7 // Patch version component of the current release + VersionPatch = 8 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string ) diff --git a/rollup/fees/rollup_fee.go b/rollup/fees/rollup_fee.go index 73127ded40c..f239be4b402 100644 --- a/rollup/fees/rollup_fee.go +++ b/rollup/fees/rollup_fee.go @@ -210,6 +210,33 @@ func estimateTxCompressionRatio(data []byte, blockNumber uint64, blockTime uint6 return ratio, nil } +// calculateTxCompressedSize calculates the size of `data` after compression using da-codec. +// We constrain compressed_size so that it cannot exceed the original size: +// +// compressed_size(tx) = min(size(zstd(rlp(tx))), size(rlp(tx))) +// +// This provides an upper bound on the rollup fee for a given transaction, regardless +// what compression algorithm the sequencer/prover uses. +func calculateTxCompressedSize(data []byte, blockNumber uint64, blockTime uint64, config *params.ChainConfig) (*big.Int, error) { + // Compressed size of empty data is 0. + // In practice, the rlp-encoded transaction is always non-empty. + if len(data) == 0 { + return common.Big0, nil + } + + // Compress data using da-codec + compressed, err := encoding.CompressScrollBatchBytes(data, blockNumber, blockTime, config) + if err != nil { + log.Error("Transaction compression failed", "error", err, "data size", len(data), "data", common.Bytes2Hex(data), "blockNumber", blockNumber, "blockTime", blockTime, "galileoTime", config.GalileoTime) + return nil, fmt.Errorf("transaction compression failed: %w", err) + } + + if len(compressed) < len(data) { + return new(big.Int).SetUint64(uint64(len(compressed))), nil + } + return new(big.Int).SetUint64(uint64(len(data))), nil +} + // calculatePenalty computes the penalty multiplier based on compression ratio // penalty(tx) = compression_ratio(tx) >= penalty_threshold ? 1 * PRECISION : penalty_factor func calculatePenalty(compressionRatio, penaltyThreshold, penaltyFactor *big.Int) *big.Int { @@ -290,6 +317,48 @@ func calculateEncodedL1DataFeeFeynman( return l1DataFee } +// calculateEncodedL1DataFeeGalileo computes the rollup fee for an RLP-encoded tx, post Galileo +// +// Post Galileo rollup fee formula: +// rollupFee(tx) = feePerByte * compressedSize(tx) * (1 + penalty(tx)) / PRECISION +// +// Where: +// feePerByte = (execScalar * l1BaseFee + blobScalar * l1BlobBaseFee) +// compressedSize(tx) = min(len(zstd(rlp(tx))), len(rlp(tx))) +// penalty(tx) = compressedSize(tx) / penaltyFactor +func calculateEncodedL1DataFeeGalileo( + l1BaseFee *big.Int, + l1BlobBaseFee *big.Int, + execScalar *big.Int, + blobScalar *big.Int, + penaltyFactor *big.Int, + compressedSize *big.Int, +) *big.Int { + // Sanitize penalty factor. + if penaltyFactor.Cmp(common.Big0) == 0 { + penaltyFactor = common.Big1 + } + + // feePerByte = (execScalar * l1BaseFee) + (blobScalar * l1BlobBaseFee) + execGas := new(big.Int).Mul(execScalar, l1BaseFee) + blobGas := new(big.Int).Mul(blobScalar, l1BlobBaseFee) + feePerByte := new(big.Int).Add(execGas, blobGas) + + // baseTerm = feePerByte * compressedSize + baseTerm := new(big.Int).Mul(feePerByte, compressedSize) + + // penaltyTerm = (baseTerm * compressedSize) / penaltyFactor + // Note: We divide by penaltyFactor after multiplication to preserve precision. + penaltyTerm := new(big.Int).Mul(baseTerm, compressedSize) + penaltyTerm.Div(penaltyTerm, penaltyFactor) + + // rollupFee = (baseTerm + penaltyTerm) / PRECISION + rollupFee := new(big.Int).Add(baseTerm, penaltyTerm) + rollupFee.Div(rollupFee, rcfg.Precision) // execScalar and blobScalar are scaled by PRECISION + + return rollupFee +} + // calculateL1GasUsed computes the L1 gas used based on the calldata and // constant sized overhead. The overhead can be decreased as the cost of the // batch submission goes down via contract optimizations. This will not overflow @@ -341,7 +410,7 @@ func CalculateL1DataFee(tx *types.Transaction, state StateDB, config *params.Cha l1DataFee = calculateEncodedL1DataFee(raw, gpoState.overhead, gpoState.l1BaseFee, gpoState.scalar) } else if !config.IsFeynman(blockTime) { l1DataFee = calculateEncodedL1DataFeeCurie(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.commitScalar, gpoState.blobScalar) - } else { + } else if !config.IsGalileo(blockTime) { // Calculate compression ratio for Feynman // Note: We compute the transaction ratio on tx.data, not on the full encoded transaction. compressionRatio, err := estimateTxCompressionRatio(tx.Data(), blockNumber.Uint64(), blockTime, config) @@ -360,6 +429,21 @@ func CalculateL1DataFee(tx *types.Transaction, state StateDB, config *params.Cha gpoState.penaltyFactor, compressionRatio, ) + } else { + // Note: In Galileo, we take the compressed size of the full RLP-encoded transaction. + compressedSize, err := calculateTxCompressedSize(raw, blockNumber.Uint64(), blockTime, config) + if err != nil { + return nil, fmt.Errorf("failed to calculate compressed size: tx hash=%s: %w", tx.Hash().Hex(), err) + } + + l1DataFee = calculateEncodedL1DataFeeGalileo( + gpoState.l1BaseFee, + gpoState.l1BlobBaseFee, + gpoState.commitScalar, // now represents execScalar + gpoState.blobScalar, + gpoState.penaltyFactor, // in Galileo, penaltyFactor is repurposed as a coefficient of the blob utilization penalty + compressedSize, + ) } // ensure l1DataFee fits into uint64 for circuit compatibility diff --git a/rollup/fees/rollup_fee_test.go b/rollup/fees/rollup_fee_test.go index 9dc9fad47f2..2296120ac71 100644 --- a/rollup/fees/rollup_fee_test.go +++ b/rollup/fees/rollup_fee_test.go @@ -96,20 +96,70 @@ func TestL1DataFeeFeynman(t *testing.T) { }) } -func TestEstimateTxCompressionRatio(t *testing.T) { +func TestL1DataFeeGalileo(t *testing.T) { + l1BaseFee := new(big.Int).SetInt64(1_000_000_000) // 1 gwei + l1BlobBaseFee := new(big.Int).SetInt64(1_000_000_000) // 1 gwei + execScalar := new(big.Int).SetInt64(2394981796) // 2.39 + blobScalar := new(big.Int).SetInt64(1019097245) // 1.02 + penaltyFactor := new(big.Int).SetInt64(10000) + + testcases := []struct { + name string + compressedSize int64 + expected int64 + }{ + {"50-byte tx", 50, 171557471810}, // ~0.06 cents + {"100-byte tx", 100, 344821983141}, // ~0.12 cents + {"1-KiB tx", 1024, 3854009072433}, // ~1.35 cents + {"10-KiB tx", 10 * 1024, 70759382824796}, // ~24.77 cents + {"1-MiB tx", 1024 * 1024, 378961881717079120}, // ~1325 USD + } + + for _, tt := range testcases { + t.Run(tt.name, func(t *testing.T) { + actual := calculateEncodedL1DataFeeGalileo( + l1BaseFee, + l1BlobBaseFee, + execScalar, + blobScalar, + penaltyFactor, + new(big.Int).SetInt64(tt.compressedSize), + ) + assert.Equal(t, + new(big.Int).SetInt64(tt.expected), + actual, + ) + }) + } +} + +func TestCompression(t *testing.T) { // Mock config that would select a specific codec version // Note: You'll need to adjust this based on your actual params.ChainConfig structure - calcCompressionRatio := func(data []byte) (*big.Int, error) { - return estimateTxCompressionRatio(data, 1000000, 1700000000, params.TestChainConfig) + compress := func(data []byte) (*big.Int, *big.Int) { + // Compute compression ratio and compressed size for each test case. + // These test cases are meant to be shared between the Go and Rust implementations. + // Note: Feynman's compression ratio is computed on the transaction payload, + // while Galileo's compressed size is computed on the full RLP-encoded transaction. + // In these compression tests we ignore this distinction. + + ratio, err := estimateTxCompressionRatio(data, 1000000, 1700000000, params.TestChainConfig) + assert.NoError(t, err) + assert.NotNil(t, ratio) + + size, err := calculateTxCompressedSize(data, 1000000, 1700000000, params.TestChainConfig) + assert.NoError(t, err) + assert.NotNil(t, size) + + return ratio, size } t.Run("empty data", func(t *testing.T) { data := []byte{} - ratio, err := calcCompressionRatio(data) - assert.NoError(t, err) - assert.NotNil(t, ratio) + ratio, size := compress(data) assert.Equal(t, U256MAX, ratio) // empty data has max compression ratio by definition + assert.Equal(t, big.NewInt(0), size) }) t.Run("non-empty data", func(t *testing.T) { @@ -119,72 +169,80 @@ func TestEstimateTxCompressionRatio(t *testing.T) { data[i] = byte(i % 10) // Create patterns for better compression } - ratio, err := calcCompressionRatio(data) - assert.NoError(t, err) - assert.NotNil(t, ratio) - // Should return a ratio > 1.0 (since compressed size < original size) + ratio, size := compress(data) + assert.Equal(t, big.NewInt(43_478_260_869), ratio) // 43.5x + assert.Equal(t, big.NewInt(23), size) }) t.Run("eth-transfer", func(t *testing.T) { data := common.Hex2Bytes("") // empty payload - ratio, err := calcCompressionRatio(data) - assert.NoError(t, err) - assert.NotNil(t, ratio) + ratio, size := compress(data) assert.Equal(t, U256MAX, ratio) // empty data is infinitely compressible by definition + assert.Equal(t, big.NewInt(0), size) }) t.Run("scr-transfer", func(t *testing.T) { // https://scrollscan.com/tx/0x7b681ce914c9774aff364d2b099b2ba41dea44bcd59dbebb9d4c4b6853893179 data := common.Hex2Bytes("a9059cbb000000000000000000000000687b50a70d33d71f9a82dd330b8c091e4d77250800000000000000000000000000000000000000000000000ac96dda943e512bb9") - ratio, err := calcCompressionRatio(data) - assert.NoError(t, err) - assert.NotNil(t, ratio) + ratio, size := compress(data) assert.Equal(t, big.NewInt(1_387_755_102), ratio) // 1.4x + assert.Equal(t, big.NewInt(49), size) }) t.Run("syncswap-swap", func(t *testing.T) { // https://scrollscan.com/tx/0x59a7b72503400b6719f3cb670c7b1e7e45ce5076f30b98bdaad3b07a5d0fbc02 data := common.Hex2Bytes("2cc4081e00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000005ec79b80000000000000000000000000000000000000000000000000003328b944c400000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006000000000000000000000000053000000000000000000000000000000000000040000000000000000000000000000000000000000000000000091a94863ca800000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000814a23b053fd0f102aeeda0459215c2444799c7000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000600000000000000000000000005300000000000000000000000000000000000004000000000000000000000000485ca81b70255da2fe3fd0814b57d1b08fce784e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000") - ratio, err := calcCompressionRatio(data) - assert.NoError(t, err) - assert.NotNil(t, ratio) + ratio, size := compress(data) assert.Equal(t, big.NewInt(4_857_142_857), ratio) // 4.8x + assert.Equal(t, big.NewInt(126), size) }) t.Run("uniswap-swap", func(t *testing.T) { // https://scrollscan.com/tx/0x65b268bd8ef416f44983ee277d748de044243272b0f106b71ff03cc8501a05da data := common.Hex2Bytes("5023b4df00000000000000000000000006efdbff2a14a7c8e15944d1f4a48f9f95f663a4000000000000000000000000530000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000001f4000000000000000000000000485ca81b70255da2fe3fd0814b57d1b08fce784e000000000000000000000000000000000000000000000000006a94d74f43000000000000000000000000000000000000000000000000000000000000045af6750000000000000000000000000000000000000000000000000000000000000000") - ratio, err := calcCompressionRatio(data) - assert.NoError(t, err) - assert.NotNil(t, ratio) + ratio, size := compress(data) assert.Equal(t, big.NewInt(2_620_689_655), ratio) // 2.6x + assert.Equal(t, big.NewInt(87), size) }) t.Run("etherfi-deposit", func(t *testing.T) { // https://scrollscan.com/tx/0x41a77736afd54134b6c673e967c9801e326495074012b4033bd557920cbe5a71 data := common.Hex2Bytes("63baa26000000000000000000000000077a7e3215a621a9935d32a046212ebfcffa3bff900000000000000000000000006efdbff2a14a7c8e15944d1f4a48f9f95f663a400000000000000000000000008c6f91e2b681faf5e17227f2a44c307b3c1364c0000000000000000000000000000000000000000000000000000000002d4cae000000000000000000000000000000000000000000000000000000000028f7f83000000000000000000000000249e3fa81d73244f956ecd529715323b6d02f24b00000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000041a95314c3a11f86cc673f2afd60d27f559cb2edcc0da5af030adffc97f9a5edc3314efbadd32878e289017f644a4afa365da5367fefe583f7c4ff0c6047e2c1ff1b00000000000000000000000000000000000000000000000000000000000000") - ratio, err := calcCompressionRatio(data) - assert.NoError(t, err) - assert.NotNil(t, ratio) + ratio, size := compress(data) assert.Equal(t, big.NewInt(1_788_944_723), ratio) // 1.8x + assert.Equal(t, big.NewInt(199), size) + }) + + t.Run("etherfi-stargate", func(t *testing.T) { + // https://scrollscan.com/tx/0x08bf18e860d4770920ba838fe709ca202227aa9afea1b0c11314e7f41fc5f578 + data := common.Hex2Bytes("5988e7a1000000000000000000000000388325dd7c76e37cfda1ed6d8a97849a46b5512a") + ratio, size := compress(data) + assert.Equal(t, big.NewInt(1_000_000_000), ratio) // 1x + assert.Equal(t, big.NewInt(36), size) + }) + + t.Run("etherfi-openocean", func(t *testing.T) { + // https://scrollscan.com/tx/0xba29777d4135cb1b1dc462f07d486ad589dd3de74b8a5a64e9ff070cef0db35a + data := common.Hex2Bytes("052fc63500000000000000000000000088c6e32066a5ae1dba00b2ea064d30c22a21f847000000000000000000000000d29687c813d741e2f938f4ac377128810e217b1b000000000000000000000000f55bec9cafdbe8730f096aa55dad6d22d44099df0000000000000000000000000000000000000000000000051e17bd1af1999e070000000000000000000000000000000000000000000000000000000000ccefaf0000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000204000000000000000000000000000000000000000000000000000000000000020800000000000000000000000000000000000000000000000000000000000001f0490411a320000000000000000000000001aa298ae7c53d8dafa200ed49608649bfa76a446000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000d29687c813d741e2f938f4ac377128810e217b1b000000000000000000000000f55bec9cafdbe8730f096aa55dad6d22d44099df0000000000000000000000001aa298ae7c53d8dafa200ed49608649bfa76a44600000000000000000000000088c6e32066a5ae1dba00b2ea064d30c22a21f8470000000000000000000000000000000000000000000000051e17bd1af1999e070000000000000000000000000000000000000000000000000000000000ccefaf0000000000000000000000000000000000000000000000000000000000cf019f00000000000000000000000000000000000000000000000000000000000000020000000000000000000000002e0be8d3d9f1833fbacf9a5e9f2d470817ff0c0000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d00000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000003e000000000000000000000000000000000000000000000000000000000000005c0000000000000000000000000000000000000000000000000000000000000082000000000000000000000000000000000000000000000000000000000000009400000000000000000000000000000000000000000000000000000000000000ba00000000000000000000000000000000000000000000000000000000000000d8000000000000000000000000000000000000000000000000000000000000011c000000000000000000000000000000000000000000000000000000000000013a000000000000000000000000000000000000000000000000000000000000016a000000000000000000000000000000000000000000000000000000000000019a00000000000000000000000000000000000000000000000000000000000001ac000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064eb5625d9000000000000000000000000d29687c813d741e2f938f4ac377128810e217b1b0000000000000000000000007160570bb153edd0ea1775ec2b2ac9b65f1ab61b000000000000000000000000000000000000000000000004e9b0639efc6a8339000000000000000000000000000000000000000000000000000000000000000000000000000000007160570bb153edd0ea1775ec2b2ac9b65f1ab61b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064511de15b000000000000000000000000d29687c813d741e2f938f4ac377128810e217b1b000000000000000000000000054641825533d1bc3324df3c30cbc3baea812087000000000000000000000000000000000000000000000004e9b0639efc6a833900000000000000000000000000000000000000000000000000000000000000000000000000000000054641825533d1bc3324df3c30cbc3baea81208700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001247132bb7f00000000000000000000000000000000000000000000000000000000000000800000000000000000000000001aa298ae7c53d8dafa200ed49608649bfa76a446000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000d29687c813d741e2f938f4ac377128810e217b1b0000000000000000000000001aa298ae7c53d8dafa200ed49608649bfa76a4460000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001a49f865422000000000000000000000000d29687c813d741e2f938f4ac377128810e217b1b00000000000000000000000000000001000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064d1660f99000000000000000000000000d29687c813d741e2f938f4ac377128810e217b1b000000000000000000000000940f31ea73bfea357354b0263b92f3ba70eb3b6100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000643afe5f008000000000000000186a00b4940f31ea73bfea357354b0263b92f3ba70eb3b61000000000000000000000000d29687c813d741e2f938f4ac377128810e217b1b0000000000000000000000001aa298ae7c53d8dafa200ed49608649bfa76a44600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001a49f865422000000000000000000000000d29687c813d741e2f938f4ac377128810e217b1b00000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064d1660f99000000000000000000000000d29687c813d741e2f938f4ac377128810e217b1b00000000000000000000000095b0c398cf6d296faa551291a9f3bf02a68c7a300000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000095b0c398cf6d296faa551291a9f3bf02a68c7a3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001247132bb7f00000000000000000000000000000000000000000000000000000000000000800000000000000000000000001aa298ae7c53d8dafa200ed49608649bfa76a446000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000d29687c813d741e2f938f4ac377128810e217b1b0000000000000000000000001aa298ae7c53d8dafa200ed49608649bfa76a44600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000038451a74316000000000000000000000000530000000000000000000000000000000000000400000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064eb5625d900000000000000000000000053000000000000000000000000000000000000040000000000000000000000007160570bb153edd0ea1775ec2b2ac9b65f1ab61b0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000007160570bb153edd0ea1775ec2b2ac9b65f1ab61b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064511de15b0000000000000000000000005300000000000000000000000000000000000004000000000000000000000000814a23b053fd0f102aeeda0459215c2444799c7000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000000000000000000000814a23b053fd0f102aeeda0459215c2444799c7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001247132bb7f00000000000000000000000000000000000000000000000000000000000000800000000000000000000000001aa298ae7c53d8dafa200ed49608649bfa76a44600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000006000000000000000000000000053000000000000000000000000000000000000040000000000000000000000001aa298ae7c53d8dafa200ed49608649bfa76a4460000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000002449f86542200000000000000000000000006efdbff2a14a7c8e15944d1f4a48f9f95f663a4000000000000000000000000000000140000000000000000000000000000003200000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000024000000000000000000000000882f1fdd5e320e39b6baa8317ec6f0171d1f499800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001043eece7db0000000000000000000000001aa298ae7c53d8dafa200ed49608649bfa76a446000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007fffffff00000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000a7e848aca42d879ef06507fca0e7b33a0a63c1e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000002449f86542200000000000000000000000006efdbff2a14a7c8e15944d1f4a48f9f95f663a400000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000104e5b07cdb000000000000000000000000f1783f3377b3a70465c193ef33942c0803121ba0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000001aa298ae7c53d8dafa200ed49608649bfa76a44600000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002e06efdbff2a14a7c8e15944d1f4a48f9f95f663a4000064f55bec9cafdbe8730f096aa55dad6d22d44099df0000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000648a6a1e85000000000000000000000000f55bec9cafdbe8730f096aa55dad6d22d44099df000000000000000000000000922164bbbd36acf9e854acbbf32facc949fcaeef0000000000000000000000000000000000000000000000000000000000cf019f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001a49f865422000000000000000000000000f55bec9cafdbe8730f096aa55dad6d22d44099df00000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000064d1660f99000000000000000000000000f55bec9cafdbe8730f096aa55dad6d22d44099df00000000000000000000000088c6e32066a5ae1dba00b2ea064d30c22a21f84700000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000ba5f8a00c2032c01bd7ed4fb2f3c8e95982539bd000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000041eacb429b4309061c97d928fa5d671b6b881dc7f959fe98efcd40e6a749866ab7000ba6acb9da5d2268f4d2acd12164f9036995428dc9cdad753fe205e0ab00da1b00000000000000000000000000000000000000000000000000000000000000") + ratio, size := compress(data) + assert.Equal(t, big.NewInt(8_992_608_236), ratio) // 9x + assert.Equal(t, big.NewInt(947), size) }) t.Run("edgepushoracle-postupdate", func(t *testing.T) { // https://scrollscan.com/tx/0x8271c68146a3b07b1ebf52ce0b550751f49cbd72fa0596ef14ff56d1f23a0bec data := common.Hex2Bytes("49a1a4fb000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000005f725f60000000000000000000000000000000000000000000000000000000003d0cac600000000000000000000000000000000000000000000000000000000685d50cd000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000004155903b95865fc5a5dd7d4d876456140dd0b815695647fc41eb1924f4cfe267265130b5a5d77125c44cf6a5a81edba6d5850ba00f90ab83281c9b44e17528fd74010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000416f000e0498733998e6a1a6454e116c1b1f95f7e000400b6a54029406cf288bdc615b62de8e2db533d6010ca57001e0b8a4b3f05ed516a31830516c52b9df206e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000410dabc77a807d729ff62c3be740d492d884f026ad2770fa7c4bdec569e201643656b07f2009d2129173738571417734a3df051cebc7b8233bec6d9471c21c098700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041eb009614c939170e9ff3d3e06c3a2c45810fe46a364ce28ecec5e220f5fd86cd6e0f70ab9093dd6b22b69980246496b600c8fcb054047962d4128efa48b692f301000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041a31b4dd4f0a482372d75c7a8c5f11aa8084a5f358579866f1d25a26a15beb2b5153400bfa7fa3d6fba138c02dd1eb8a5a97d62178d98c5632a153396a566e5ed0000000000000000000000000000000000000000000000000000000000000000") - ratio, err := calcCompressionRatio(data) - assert.NoError(t, err) - assert.NotNil(t, ratio) + ratio, size := compress(data) assert.Equal(t, big.NewInt(2_441_805_225), ratio) // 2.4x + assert.Equal(t, big.NewInt(421), size) }) t.Run("intmax-post", func(t *testing.T) { // https://scrollscan.com/tx/0x7244e27223cdd79ba0f0e3990c746e5d524e35dbcc200f0a7e664ffdc6d08eef data := common.Hex2Bytes("9b6babf0f0372bb253e060ecbdd3dbef8b832b0e743148bd807bfcf665593a56a18bac69000000000000000000000000000000000000000000000000000000006861676d0000000000000000000000000000000000000000000000000000000000000015800000000000000000000000000000000000000000000000000000000000000029a690c4ef1e18884a11f73c8595fb721f964a3e2bee809800c474278f024bcd05a76119827e6c464cee8620f616a9a23d41305eb9f9682f9d2eaf964325fcd71147783453566f27ce103a2398d96719ee22ba51b89b92cdf952af817929329403b75ae310b23cf250041d53c82bef431fa2527e2dd68b49f45f06feb2bd09f011358fe2650b8987ea2bb39bb6e28ce770f4fc9c4f064d0ae7573a1450452b501a5b0d3454d254dbf9db7094f4ca1f5056143f5c70dee4126443a6150d9e51bd05dac7e9a2bd48a8797ac6e9379d400c5ce1815b10846eaf0d80dca3a727ffd0075387e0f1bc1b363c81ecf8d05a4b654ac6fbe1cdc7c741a5c0bbeabde4138906009129ca033af12094fd7306562d9735b2fe757f021b7eb3320f8a814a286a10130969de2783e49871b80e967cfba630e6bdef2fd1d2b1076c6c3f5fd9ae5800000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000000012a98f1556efe81340fad3e59044b8139ce62f1d5d50b44b680de9422b1ddbf1a") - ratio, err := calcCompressionRatio(data) - assert.NoError(t, err) - assert.NotNil(t, ratio) + ratio, size := compress(data) assert.Equal(t, big.NewInt(1_298_578_199), ratio) // 1.3x + assert.Equal(t, big.NewInt(422), size) }) }