diff --git a/encoding/bitmap.go b/encoding/bitmap.go index a4f6e02..cc0614e 100644 --- a/encoding/bitmap.go +++ b/encoding/bitmap.go @@ -80,13 +80,3 @@ func decodeBitmap(skippedL1MessageBitmap []byte, totalL1MessagePopped int) ([]*b } return skippedBitmap, nil } - -// isL1MessageSkipped checks if index is skipped in bitmap. -func isL1MessageSkipped(skippedBitmap []*big.Int, index uint64) bool { - if index > uint64(len(skippedBitmap))*256 { - return false - } - quo := index / 256 - rem := index % 256 - return skippedBitmap[quo].Bit(int(rem)) != 0 -} diff --git a/encoding/bitmap_test.go b/encoding/bitmap_test.go index 554cbb3..d5abe30 100644 --- a/encoding/bitmap_test.go +++ b/encoding/bitmap_test.go @@ -2,6 +2,7 @@ package encoding import ( "encoding/hex" + "math/big" "testing" "github.com/stretchr/testify/assert" @@ -15,6 +16,15 @@ func TestDecodeBitmap(t *testing.T) { decodedBitmap, err := decodeBitmap(skippedL1MessageBitmap, 42) assert.NoError(t, err) + isL1MessageSkipped := func(skippedBitmap []*big.Int, index uint64) bool { + if index >= uint64(len(skippedBitmap))*256 { + return false + } + quo := index / 256 + rem := index % 256 + return skippedBitmap[quo].Bit(int(rem)) == 1 + } + assert.True(t, isL1MessageSkipped(decodedBitmap, 0)) assert.True(t, isL1MessageSkipped(decodedBitmap, 9)) assert.False(t, isL1MessageSkipped(decodedBitmap, 10)) diff --git a/encoding/codecv0_test.go b/encoding/codecv0_test.go index 6a45107..f199d29 100644 --- a/encoding/codecv0_test.go +++ b/encoding/codecv0_test.go @@ -564,3 +564,56 @@ func TestCodecV0BatchL1MessagePopped(t *testing.T) { assert.Equal(t, uint64(32), daBatch.(*daBatchV0).l1MessagePopped) assert.Equal(t, uint64(42), daBatch.(*daBatchV0).totalL1MessagePopped) } + +func TestCodecV0DecodeDAChunksRawTx(t *testing.T) { + codecv0, err := CodecFromVersion(CodecV0) + assert.NoError(t, err) + + block0 := readBlockFromJSON(t, "testdata/blockTrace_02.json") + block1 := readBlockFromJSON(t, "testdata/blockTrace_03.json") + chunk0 := &Chunk{Blocks: []*Block{block0, block1}} + daChunk0, err := codecv0.NewDAChunk(chunk0, 0) + assert.NoError(t, err) + chunkBytes0, err := daChunk0.Encode() + assert.NoError(t, err) + + block2 := readBlockFromJSON(t, "testdata/blockTrace_04.json") + block3 := readBlockFromJSON(t, "testdata/blockTrace_05.json") + chunk1 := &Chunk{Blocks: []*Block{block2, block3}} + daChunk1, err := codecv0.NewDAChunk(chunk1, 0) + assert.NoError(t, err) + chunkBytes1, err := daChunk1.Encode() + assert.NoError(t, err) + + daChunksRawTx, err := codecv0.DecodeDAChunksRawTx([][]byte{chunkBytes0, chunkBytes1}) + assert.NoError(t, err) + // assert number of chunks + assert.Equal(t, 2, len(daChunksRawTx)) + + // assert block in first chunk + assert.Equal(t, 2, len(daChunksRawTx[0].Blocks)) + assert.Equal(t, daChunk0.(*daChunkV0).blocks[0], daChunksRawTx[0].Blocks[0]) + assert.Equal(t, daChunk0.(*daChunkV0).blocks[1], daChunksRawTx[0].Blocks[1]) + + // assert block in second chunk + assert.Equal(t, 2, len(daChunksRawTx[1].Blocks)) + daChunksRawTx[1].Blocks[0].(*daBlockV0).baseFee = nil + assert.Equal(t, daChunk1.(*daChunkV0).blocks[0].(*daBlockV0), daChunksRawTx[1].Blocks[0]) + daChunksRawTx[1].Blocks[1].(*daBlockV0).baseFee = nil + assert.Equal(t, daChunk1.(*daChunkV0).blocks[1].(*daBlockV0), daChunksRawTx[1].Blocks[1]) + + // assert transactions in first chunk + assert.Equal(t, 2, len(daChunksRawTx[0].Transactions)) + // here number of transactions in encoded and decoded chunks may be different, because decodec chunks doesn't contain l1msgs + assert.Equal(t, 2, len(daChunksRawTx[0].Transactions[0])) + assert.Equal(t, 1, len(daChunksRawTx[0].Transactions[1])) + + assert.EqualValues(t, daChunk0.(*daChunkV0).transactions[0][0].TxHash, daChunksRawTx[0].Transactions[0][0].Hash().String()) + assert.EqualValues(t, daChunk0.(*daChunkV0).transactions[0][1].TxHash, daChunksRawTx[0].Transactions[0][1].Hash().String()) + + // assert transactions in second chunk + assert.Equal(t, 2, len(daChunksRawTx[1].Transactions)) + // here number of transactions in encoded and decoded chunks may be different, because decodec chunks doesn't contain l1msgs + assert.Equal(t, 1, len(daChunksRawTx[1].Transactions[0])) + assert.Equal(t, 0, len(daChunksRawTx[1].Transactions[1])) +} diff --git a/encoding/codecv1_test.go b/encoding/codecv1_test.go index 4b0ffd7..c29e57e 100644 --- a/encoding/codecv1_test.go +++ b/encoding/codecv1_test.go @@ -824,3 +824,64 @@ func TestCodecV1BatchBlobDataProofForPointEvaluation(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "0b14dce4abfdeb3a69a341f7db6b1e16162c20826e6d964a829e20f671030cab35b73ddb4a78fc4a8540f1d8259512c46e606a701e7ef7742e38cc4562ef53b983bee97f95fbf2d789a8e0fb365c26e141d6a31e43403b4a469d1723128f6d5de5c54e913e143feede32d0af9b6fd6fda28e5610ca6b185d6ac30b53bd83d6366fccb1956daafa90ff6b504a966b119ebb45cb3f7085b7c1d622ee1ad27fcff9", hex.EncodeToString(verifyData)) } + +func TestCodecV1DecodeDAChunksRawTx(t *testing.T) { + codecv1, err := CodecFromVersion(CodecV1) + assert.NoError(t, err) + + block0 := readBlockFromJSON(t, "testdata/blockTrace_02.json") + block1 := readBlockFromJSON(t, "testdata/blockTrace_03.json") + chunk0 := &Chunk{Blocks: []*Block{block0, block1}} + daChunk0, err := codecv1.NewDAChunk(chunk0, 0) + assert.NoError(t, err) + chunkBytes0, err := daChunk0.Encode() + assert.NoError(t, err) + + block2 := readBlockFromJSON(t, "testdata/blockTrace_04.json") + block3 := readBlockFromJSON(t, "testdata/blockTrace_05.json") + chunk1 := &Chunk{Blocks: []*Block{block2, block3}} + daChunk1, err := codecv1.NewDAChunk(chunk1, 0) + assert.NoError(t, err) + chunkBytes1, err := daChunk1.Encode() + assert.NoError(t, err) + + originalBatch := &Batch{Chunks: []*Chunk{chunk0, chunk1}} + batch, err := codecv1.NewDABatch(originalBatch) + assert.NoError(t, err) + + daChunksRawTx, err := codecv1.DecodeDAChunksRawTx([][]byte{chunkBytes0, chunkBytes1}) + assert.NoError(t, err) + // assert number of chunks + assert.Equal(t, 2, len(daChunksRawTx)) + + // assert block in first chunk + assert.Equal(t, 2, len(daChunksRawTx[0].Blocks)) + assert.Equal(t, daChunk0.(*daChunkV1).blocks[0], daChunksRawTx[0].Blocks[0]) + assert.Equal(t, daChunk0.(*daChunkV1).blocks[1], daChunksRawTx[0].Blocks[1]) + + // assert block in second chunk + assert.Equal(t, 2, len(daChunksRawTx[1].Blocks)) + daChunksRawTx[1].Blocks[0].(*daBlockV0).baseFee = nil + assert.Equal(t, daChunk1.(*daChunkV1).blocks[0].(*daBlockV0), daChunksRawTx[1].Blocks[0]) + daChunksRawTx[1].Blocks[1].(*daBlockV0).baseFee = nil + assert.Equal(t, daChunk1.(*daChunkV1).blocks[1].(*daBlockV0), daChunksRawTx[1].Blocks[1]) + + blob := batch.Blob() + err = codecv1.DecodeTxsFromBlob(blob, daChunksRawTx) + assert.NoError(t, err) + + // assert transactions in first chunk + assert.Equal(t, 2, len(daChunksRawTx[0].Transactions)) + // here number of transactions in encoded and decoded chunks may be different, because decodec chunks doesn't contain l1msgs + assert.Equal(t, 2, len(daChunksRawTx[0].Transactions[0])) + assert.Equal(t, 1, len(daChunksRawTx[0].Transactions[1])) + + assert.EqualValues(t, daChunk0.(*daChunkV1).transactions[0][0].TxHash, daChunksRawTx[0].Transactions[0][0].Hash().String()) + assert.EqualValues(t, daChunk0.(*daChunkV1).transactions[0][1].TxHash, daChunksRawTx[0].Transactions[0][1].Hash().String()) + + // assert transactions in second chunk + assert.Equal(t, 2, len(daChunksRawTx[1].Transactions)) + // here number of transactions in encoded and decoded chunks may be different, because decodec chunks doesn't contain l1msgs + assert.Equal(t, 1, len(daChunksRawTx[1].Transactions[0])) + assert.Equal(t, 0, len(daChunksRawTx[1].Transactions[1])) +} diff --git a/encoding/codecv2_test.go b/encoding/codecv2_test.go index 698b2b5..c386d0d 100644 --- a/encoding/codecv2_test.go +++ b/encoding/codecv2_test.go @@ -5,7 +5,6 @@ import ( "strings" "testing" - "github.com/scroll-tech/da-codec/encoding/zstd" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/core/types" "github.com/stretchr/testify/assert" @@ -820,23 +819,63 @@ func TestCodecV2BatchBlobDataProofForPointEvaluation(t *testing.T) { assert.Equal(t, "1bea70cbdd3d088c0db7d3dd5a11a2934ec4e7db761195d1e62f9f38a2fd5b325910eea5d881106c394f8d9a80bac8ecc43a86e0b920c5dc93f89caa43b205c2880cc02297edda15b6a14c4481fd15db8209aa52b80aecde6fce0592093eaf0d813c2f081eacb1efa9a8030191e1b780b421b0df42cc64da5e466af6f8cbc20afcb993e6d217440b5b21f2be91abe8620e1518780aa2005ec0a80cb947ebfef9", hex.EncodeToString(verifyData)) } -func TestCodecV2BlobCompressDecompress(t *testing.T) { - blobString := "0060e7159d580094830001000016310002f9162d82cf5502843b9b0a1783119700e28080b915d260806040523480156200001157600080fd5b5060405162001400b2380380833981810160405260a0811037815160208301516040808501805100915193959294830192918464018211639083019060208201858179825181110082820188101794825250918201929091019080838360005b83c357818101510083820152602001620000a9565b50505050905090810190601f16f1578082030080516001836020036101000a0319168191508051604051939291900115012b0001460175015b01a39081015185519093508592508491620001c891600391850001906200026b565b508051620001de90600490602084506005805461ff00190060ff1990911660121716905550600680546001600160a01b0380881619928300161790925560078054928716929091169190911790556200023081620002550062010000600160b01b03191633021790555062000307915050565b60ff19160060ff929092565b828160011615610100020316600290049060005260206000002090601f016020900481019282601f10620002ae5780518380011785de016000010185558215620002de579182015b8202de5782518255916020019190600100c1565b50620002ec9291f0565b5090565b5b8002ec576000815560010162000002f1565b61119b80620003176000396000f3fe61001004361061010b576000003560e01c80635c975abb116100a257806395d89b411161007114610301578000639dc29fac14610309578063a457c2d714610335578063a9059cbb1461036100578063dd62ed3e1461038d5761010b565b1461029d57806370a0823114610200a55780638456cb59146102cb5780638e50817a146102d3313ce567116100de00571461021d578063395093511461023b5780633f4ba83a146102675780634000c10f191461027106fdde0314610110578063095ea7b31461018d5780631816000ddd146101cd57806323b872e7575b6101186103bb565b6040805160208082005283518183015283519192839290830161015261013a61017f9250508091030090f35b6101b9600480360360408110156101a381351690602001356104519100151582525190819003602001d561046e60fd81169160208101359091169060004074565b6102256104fb60ff90921640025105046f610552565b005b61026f00028705a956610654d520bb3516610662067d56e90135166106d21861075703001f07b856034b085f77c7d5a308db565b6003805420601f600260001961010000600188161502019095169490940493840181900481028201810190925282810052606093909290918301828280156104475780601f1061041c57610100808300540402835291610447565b825b8154815260200180831161042a5782900360001f16820191565b600061046561045e610906565b848461090a565b506001920002548184f6565b6104f18461048d6104ec8560405180606080602861108560002891398a166000908152600160205260408120906104cb81019190915260400001600020549190610b51565b935460ff160511016000610522908116825260002080830193909352604091820120918c168152925290205490610be8565b60000716331461059f5762461bcd60e51b60040b60248201526a1b9bdd08185b1b001bddd95960aa1b604482015290640190fd5b6105a7610c49565b61010090040060ff16156105f9106f14185d5cd8589b194e881c185d5cd9596082600606460006508282610ced909052604006ca0ddd900407260c6b6f6e6c792046616374006f727960a0079283918216179091559390921660041561080808550e65086c002511176025006108968dd491824080832093909416825233831661094f5704000180806020018281038252602401806110f36024913960400191fd821661090094223d60228084166000819487168084529482529182902085905581518581005291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200a00c8c7c3b92592819003a3508316610a3b25ce8216610a80230ff86023610a8b00838383610f61565b610ac881265f60268685808220939093559084168152200054610af7908220409490945580905191937fddf252ad1be2c89b69c2b068fc00378daa952ba7f163c4a11628f55a4df523b3ef929182900300818484111561000be08381815191508051900ba50b8d0bd2fd900300828201610c421b7f53610066654d6174683a206164646974696f6e206f766572666c6f7700610c9c147300621690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd3008aeae4b073aa610cd0a18216610d481f7f45524332303a206d696e7420746f0020746865207a65726f72657373610d546000600254610d610255902054610d008780838393519293910e2d6101001790557f62e78cea01bee320cd4e42027000b5ea74000d11b0c9f74754ebdbfc544b05a2588216610eaa6021ad6021610e00b68260000ef3221b85839020550f199082610fb540805182600091851691910020565b610f6cb07415610fb02a113c602a00610c428383401e7375627472610063815250fe7472616e736665726275726e20616d6f756e742065786365656400732062616c616e6365617070726f7665616c6c6f7766726f6d646563726561007365642062656c6f775061757361626c653a20746f6b656e7768696c652070006175736564a2646970667358221220e96342bec8f6c2bf72815a39998973b6004c3bed57770f402e9a7b7eeda0265d4c64736f6c634300060c00331c5a77d900fa7ef466951b2f01f724bca3a5820b63a0e012095745544820636f696e04c00001a0235c1a8d40e8c347890397f1a92e6eadbd6422cf7c210e3e1737f0553c00633172a02f7c0384ddd06970446e74229cd96216da62196dc62395bda5209500d44b8a9af7813ca8c134a9149a111111110549d2740105c410e61ca4d60312006013290b6398528818e2c8484081888c4890142465a631e63178f9940048f4006ba77adb9be01e898bbbfbc0afba2b64ed71162098740e35ec699633c6a84900670da2d948458ecd9f2e5dc5c5ac4afe3d62cf457cd3507b2eae71e064fab30088531f9c708fd40558dfc698511c4a68234d058c4972da28f0201c4ee550b500e36f0bb42e46bb556d6197be7ea27a3a853e5da024de5ea930350219b1638a00a1dcd41f8222f5d647291e05238c248aa4e028278ad4a9a720f5c16f637166004c4cc255e402cdf64c88e9231dd28a07b8f0ddf1dd7b388875a13dc6d447c000318bca02c54cdfa3621635af1ff932928dfde06038ac9729c301f9f3a3a395008d502ba9e137cc24c14cb4102cf6ba6708b9c812c3ba59a3cbcc5d2aafa8b50097b49fbeb704a22b6137ae9a13b600ad73748768b42756ba338f9854164b1b003f3e23255e4db853a2d3276f061093a37810212ba36db205219fab403242800009178588ad21f754085dd807b09af69e6f06bccbcef8ade3b1f0eb15a077b8005b024ecef4087f261a0d4033355c1e544bd0b0c100276008c420d6d30bc8be00a3ba741063e8b48cf152d3695c0904d477318d4ad46477cdf962443336479f00bd86fd52d4e2a1d23eeddc52463d524b44644abdcd097025bcf9cc636fc1030092cb15b81d7ea667f3ba711624bbf04e992871a6ea4f9d367ba6d46142176f00cdf03e4e19549d2eea45ca804421f6bc33933aab6d478b291bf3619fe15bc900975409d8f3677a87d1b1f7acdb3071b752f3d95c9363ac9c83752f223e45e50079308f554787b4d1f74e389823923f5d268be545466a2dd449963ad25407bd003a18601410b91ca081537f67ea8d527a49adf256f2363346ea35a2fe2768a900091a184f59680df81982c6087efc651f54693a7870aa7c13dcf054c39536c500de8a2dd66955567ff1730dac8533de482aed706ed3417823dd65d058b98899008d54917fd1f70735f7a6a8b1a053c08aac96fb04" - blobBytes, err := hex.DecodeString(blobString) +func TestCodecV2DecodeDAChunksRawTx(t *testing.T) { + codecv2, err := CodecFromVersion(CodecV2) + assert.NoError(t, err) + + block0 := readBlockFromJSON(t, "testdata/blockTrace_02.json") + block1 := readBlockFromJSON(t, "testdata/blockTrace_03.json") + chunk0 := &Chunk{Blocks: []*Block{block0, block1}} + daChunk0, err := codecv2.NewDAChunk(chunk0, 0) + assert.NoError(t, err) + chunkBytes0, err := daChunk0.Encode() + assert.NoError(t, err) + + block2 := readBlockFromJSON(t, "testdata/blockTrace_04.json") + block3 := readBlockFromJSON(t, "testdata/blockTrace_05.json") + chunk1 := &Chunk{Blocks: []*Block{block2, block3}} + daChunk1, err := codecv2.NewDAChunk(chunk1, 0) + assert.NoError(t, err) + chunkBytes1, err := daChunk1.Encode() assert.NoError(t, err) - compressed, err := zstd.CompressScrollBatchBytes(blobBytes) + originalBatch := &Batch{Chunks: []*Chunk{chunk0, chunk1}} + batch, err := codecv2.NewDABatch(originalBatch) assert.NoError(t, err) - blob, err := makeBlobCanonical(compressed) + daChunksRawTx, err := codecv2.DecodeDAChunksRawTx([][]byte{chunkBytes0, chunkBytes1}) assert.NoError(t, err) + // assert number of chunks + assert.Equal(t, 2, len(daChunksRawTx)) + + // assert block in first chunk + assert.Equal(t, 2, len(daChunksRawTx[0].Blocks)) + assert.Equal(t, daChunk0.(*daChunkV1).blocks[0], daChunksRawTx[0].Blocks[0]) + assert.Equal(t, daChunk0.(*daChunkV1).blocks[1], daChunksRawTx[0].Blocks[1]) - res := bytesFromBlobCanonical(blob) - compressedBytes := res[:] - magics := []byte{0x28, 0xb5, 0x2f, 0xfd} - compressedBytes = append(magics, compressedBytes...) + // assert block in second chunk + assert.Equal(t, 2, len(daChunksRawTx[1].Blocks)) + daChunksRawTx[1].Blocks[0].(*daBlockV0).baseFee = nil + assert.Equal(t, daChunk1.(*daChunkV1).blocks[0].(*daBlockV0), daChunksRawTx[1].Blocks[0]) + daChunksRawTx[1].Blocks[1].(*daBlockV0).baseFee = nil + assert.Equal(t, daChunk1.(*daChunkV1).blocks[1].(*daBlockV0), daChunksRawTx[1].Blocks[1]) - decompressedBlobBytes, err := decompressScrollBlobToBatch(compressedBytes) + blob := batch.Blob() + err = codecv2.DecodeTxsFromBlob(blob, daChunksRawTx) assert.NoError(t, err) - assert.Equal(t, blobBytes, decompressedBlobBytes) + + // assert transactions in first chunk + assert.Equal(t, 2, len(daChunksRawTx[0].Transactions)) + // here number of transactions in encoded and decoded chunks may be different, because decodec chunks doesn't contain l1msgs + assert.Equal(t, 2, len(daChunksRawTx[0].Transactions[0])) + assert.Equal(t, 1, len(daChunksRawTx[0].Transactions[1])) + + assert.EqualValues(t, daChunk0.(*daChunkV1).transactions[0][0].TxHash, daChunksRawTx[0].Transactions[0][0].Hash().String()) + assert.EqualValues(t, daChunk0.(*daChunkV1).transactions[0][1].TxHash, daChunksRawTx[0].Transactions[0][1].Hash().String()) + + // assert transactions in second chunk + assert.Equal(t, 2, len(daChunksRawTx[1].Transactions)) + // here number of transactions in encoded and decoded chunks may be different, because decodec chunks doesn't contain l1msgs + assert.Equal(t, 1, len(daChunksRawTx[1].Transactions[0])) + assert.Equal(t, 0, len(daChunksRawTx[1].Transactions[1])) } diff --git a/encoding/codecv3_test.go b/encoding/codecv3_test.go index d1ff50b..4703f2e 100644 --- a/encoding/codecv3_test.go +++ b/encoding/codecv3_test.go @@ -6,7 +6,6 @@ import ( "strings" "testing" - "github.com/scroll-tech/da-codec/encoding/zstd" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/core/types" "github.com/stretchr/testify/assert" @@ -961,23 +960,63 @@ func TestCodecV3BatchBlobDataProofForPointEvaluation(t *testing.T) { assert.Equal(t, "1bea70cbdd3d088c0db7d3dd5a11a2934ec4e7db761195d1e62f9f38a2fd5b325910eea5d881106c394f8d9a80bac8ecc43a86e0b920c5dc93f89caa43b205c2880cc02297edda15b6a14c4481fd15db8209aa52b80aecde6fce0592093eaf0d813c2f081eacb1efa9a8030191e1b780b421b0df42cc64da5e466af6f8cbc20afcb993e6d217440b5b21f2be91abe8620e1518780aa2005ec0a80cb947ebfef9", hex.EncodeToString(verifyData)) } -func TestCodecV3BlobCompressDecompress(t *testing.T) { - blobString := "0060e7159d580094830001000016310002f9162d82cf5502843b9b0a1783119700e28080b915d260806040523480156200001157600080fd5b5060405162001400b2380380833981810160405260a0811037815160208301516040808501805100915193959294830192918464018211639083019060208201858179825181110082820188101794825250918201929091019080838360005b83c357818101510083820152602001620000a9565b50505050905090810190601f16f1578082030080516001836020036101000a0319168191508051604051939291900115012b0001460175015b01a39081015185519093508592508491620001c891600391850001906200026b565b508051620001de90600490602084506005805461ff00190060ff1990911660121716905550600680546001600160a01b0380881619928300161790925560078054928716929091169190911790556200023081620002550062010000600160b01b03191633021790555062000307915050565b60ff19160060ff929092565b828160011615610100020316600290049060005260206000002090601f016020900481019282601f10620002ae5780518380011785de016000010185558215620002de579182015b8202de5782518255916020019190600100c1565b50620002ec9291f0565b5090565b5b8002ec576000815560010162000002f1565b61119b80620003176000396000f3fe61001004361061010b576000003560e01c80635c975abb116100a257806395d89b411161007114610301578000639dc29fac14610309578063a457c2d714610335578063a9059cbb1461036100578063dd62ed3e1461038d5761010b565b1461029d57806370a0823114610200a55780638456cb59146102cb5780638e50817a146102d3313ce567116100de00571461021d578063395093511461023b5780633f4ba83a146102675780634000c10f191461027106fdde0314610110578063095ea7b31461018d5780631816000ddd146101cd57806323b872e7575b6101186103bb565b6040805160208082005283518183015283519192839290830161015261013a61017f9250508091030090f35b6101b9600480360360408110156101a381351690602001356104519100151582525190819003602001d561046e60fd81169160208101359091169060004074565b6102256104fb60ff90921640025105046f610552565b005b61026f00028705a956610654d520bb3516610662067d56e90135166106d21861075703001f07b856034b085f77c7d5a308db565b6003805420601f600260001961010000600188161502019095169490940493840181900481028201810190925282810052606093909290918301828280156104475780601f1061041c57610100808300540402835291610447565b825b8154815260200180831161042a5782900360001f16820191565b600061046561045e610906565b848461090a565b506001920002548184f6565b6104f18461048d6104ec8560405180606080602861108560002891398a166000908152600160205260408120906104cb81019190915260400001600020549190610b51565b935460ff160511016000610522908116825260002080830193909352604091820120918c168152925290205490610be8565b60000716331461059f5762461bcd60e51b60040b60248201526a1b9bdd08185b1b001bddd95960aa1b604482015290640190fd5b6105a7610c49565b61010090040060ff16156105f9106f14185d5cd8589b194e881c185d5cd9596082600606460006508282610ced909052604006ca0ddd900407260c6b6f6e6c792046616374006f727960a0079283918216179091559390921660041561080808550e65086c002511176025006108968dd491824080832093909416825233831661094f5704000180806020018281038252602401806110f36024913960400191fd821661090094223d60228084166000819487168084529482529182902085905581518581005291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200a00c8c7c3b92592819003a3508316610a3b25ce8216610a80230ff86023610a8b00838383610f61565b610ac881265f60268685808220939093559084168152200054610af7908220409490945580905191937fddf252ad1be2c89b69c2b068fc00378daa952ba7f163c4a11628f55a4df523b3ef929182900300818484111561000be08381815191508051900ba50b8d0bd2fd900300828201610c421b7f53610066654d6174683a206164646974696f6e206f766572666c6f7700610c9c147300621690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd3008aeae4b073aa610cd0a18216610d481f7f45524332303a206d696e7420746f0020746865207a65726f72657373610d546000600254610d610255902054610d008780838393519293910e2d6101001790557f62e78cea01bee320cd4e42027000b5ea74000d11b0c9f74754ebdbfc544b05a2588216610eaa6021ad6021610e00b68260000ef3221b85839020550f199082610fb540805182600091851691910020565b610f6cb07415610fb02a113c602a00610c428383401e7375627472610063815250fe7472616e736665726275726e20616d6f756e742065786365656400732062616c616e6365617070726f7665616c6c6f7766726f6d646563726561007365642062656c6f775061757361626c653a20746f6b656e7768696c652070006175736564a2646970667358221220e96342bec8f6c2bf72815a39998973b6004c3bed57770f402e9a7b7eeda0265d4c64736f6c634300060c00331c5a77d900fa7ef466951b2f01f724bca3a5820b63a0e012095745544820636f696e04c00001a0235c1a8d40e8c347890397f1a92e6eadbd6422cf7c210e3e1737f0553c00633172a02f7c0384ddd06970446e74229cd96216da62196dc62395bda5209500d44b8a9af7813ca8c134a9149a111111110549d2740105c410e61ca4d60312006013290b6398528818e2c8484081888c4890142465a631e63178f9940048f4006ba77adb9be01e898bbbfbc0afba2b64ed71162098740e35ec699633c6a84900670da2d948458ecd9f2e5dc5c5ac4afe3d62cf457cd3507b2eae71e064fab30088531f9c708fd40558dfc698511c4a68234d058c4972da28f0201c4ee550b500e36f0bb42e46bb556d6197be7ea27a3a853e5da024de5ea930350219b1638a00a1dcd41f8222f5d647291e05238c248aa4e028278ad4a9a720f5c16f637166004c4cc255e402cdf64c88e9231dd28a07b8f0ddf1dd7b388875a13dc6d447c000318bca02c54cdfa3621635af1ff932928dfde06038ac9729c301f9f3a3a395008d502ba9e137cc24c14cb4102cf6ba6708b9c812c3ba59a3cbcc5d2aafa8b50097b49fbeb704a22b6137ae9a13b600ad73748768b42756ba338f9854164b1b003f3e23255e4db853a2d3276f061093a37810212ba36db205219fab403242800009178588ad21f754085dd807b09af69e6f06bccbcef8ade3b1f0eb15a077b8005b024ecef4087f261a0d4033355c1e544bd0b0c100276008c420d6d30bc8be00a3ba741063e8b48cf152d3695c0904d477318d4ad46477cdf962443336479f00bd86fd52d4e2a1d23eeddc52463d524b44644abdcd097025bcf9cc636fc1030092cb15b81d7ea667f3ba711624bbf04e992871a6ea4f9d367ba6d46142176f00cdf03e4e19549d2eea45ca804421f6bc33933aab6d478b291bf3619fe15bc900975409d8f3677a87d1b1f7acdb3071b752f3d95c9363ac9c83752f223e45e50079308f554787b4d1f74e389823923f5d268be545466a2dd449963ad25407bd003a18601410b91ca081537f67ea8d527a49adf256f2363346ea35a2fe2768a900091a184f59680df81982c6087efc651f54693a7870aa7c13dcf054c39536c500de8a2dd66955567ff1730dac8533de482aed706ed3417823dd65d058b98899008d54917fd1f70735f7a6a8b1a053c08aac96fb04" - blobBytes, err := hex.DecodeString(blobString) +func TestCodecV3DecodeDAChunksRawTx(t *testing.T) { + codecv3, err := CodecFromVersion(CodecV3) + assert.NoError(t, err) + + block0 := readBlockFromJSON(t, "testdata/blockTrace_02.json") + block1 := readBlockFromJSON(t, "testdata/blockTrace_03.json") + chunk0 := &Chunk{Blocks: []*Block{block0, block1}} + daChunk0, err := codecv3.NewDAChunk(chunk0, 0) + assert.NoError(t, err) + chunkBytes0, err := daChunk0.Encode() + assert.NoError(t, err) + + block2 := readBlockFromJSON(t, "testdata/blockTrace_04.json") + block3 := readBlockFromJSON(t, "testdata/blockTrace_05.json") + chunk1 := &Chunk{Blocks: []*Block{block2, block3}} + daChunk1, err := codecv3.NewDAChunk(chunk1, 0) + assert.NoError(t, err) + chunkBytes1, err := daChunk1.Encode() assert.NoError(t, err) - compressed, err := zstd.CompressScrollBatchBytes(blobBytes) + originalBatch := &Batch{Chunks: []*Chunk{chunk0, chunk1}} + batch, err := codecv3.NewDABatch(originalBatch) assert.NoError(t, err) - blob, err := makeBlobCanonical(compressed) + daChunksRawTx, err := codecv3.DecodeDAChunksRawTx([][]byte{chunkBytes0, chunkBytes1}) assert.NoError(t, err) + // assert number of chunks + assert.Equal(t, 2, len(daChunksRawTx)) + + // assert block in first chunk + assert.Equal(t, 2, len(daChunksRawTx[0].Blocks)) + assert.Equal(t, daChunk0.(*daChunkV1).blocks[0], daChunksRawTx[0].Blocks[0]) + assert.Equal(t, daChunk0.(*daChunkV1).blocks[1], daChunksRawTx[0].Blocks[1]) - res := bytesFromBlobCanonical(blob) - compressedBytes := res[:] - magics := []byte{0x28, 0xb5, 0x2f, 0xfd} - compressedBytes = append(magics, compressedBytes...) + // assert block in second chunk + assert.Equal(t, 2, len(daChunksRawTx[1].Blocks)) + daChunksRawTx[1].Blocks[0].(*daBlockV0).baseFee = nil + assert.Equal(t, daChunk1.(*daChunkV1).blocks[0].(*daBlockV0), daChunksRawTx[1].Blocks[0]) + daChunksRawTx[1].Blocks[1].(*daBlockV0).baseFee = nil + assert.Equal(t, daChunk1.(*daChunkV1).blocks[1].(*daBlockV0), daChunksRawTx[1].Blocks[1]) - decompressedBlobBytes, err := decompressScrollBlobToBatch(compressedBytes) + blob := batch.Blob() + err = codecv3.DecodeTxsFromBlob(blob, daChunksRawTx) assert.NoError(t, err) - assert.Equal(t, blobBytes, decompressedBlobBytes) + + // assert transactions in first chunk + assert.Equal(t, 2, len(daChunksRawTx[0].Transactions)) + // here number of transactions in encoded and decoded chunks may be different, because decodec chunks doesn't contain l1msgs + assert.Equal(t, 2, len(daChunksRawTx[0].Transactions[0])) + assert.Equal(t, 1, len(daChunksRawTx[0].Transactions[1])) + + assert.EqualValues(t, daChunk0.(*daChunkV1).transactions[0][0].TxHash, daChunksRawTx[0].Transactions[0][0].Hash().String()) + assert.EqualValues(t, daChunk0.(*daChunkV1).transactions[0][1].TxHash, daChunksRawTx[0].Transactions[0][1].Hash().String()) + + // assert transactions in second chunk + assert.Equal(t, 2, len(daChunksRawTx[1].Transactions)) + // here number of transactions in encoded and decoded chunks may be different, because decodec chunks doesn't contain l1msgs + assert.Equal(t, 1, len(daChunksRawTx[1].Transactions[0])) + assert.Equal(t, 0, len(daChunksRawTx[1].Transactions[1])) } diff --git a/encoding/codecv4.go b/encoding/codecv4.go index 82fe7c0..3011336 100644 --- a/encoding/codecv4.go +++ b/encoding/codecv4.go @@ -1,19 +1,24 @@ package encoding import ( + "crypto/sha256" "encoding/binary" + "encoding/hex" "errors" "fmt" + "math/big" "github.com/scroll-tech/go-ethereum/common" + "github.com/scroll-tech/go-ethereum/core/types" + "github.com/scroll-tech/go-ethereum/crypto" "github.com/scroll-tech/go-ethereum/crypto/kzg4844" + "github.com/scroll-tech/go-ethereum/log" "github.com/scroll-tech/da-codec/encoding/zstd" ) type DACodecV4 struct { DACodecV3 - enableCompress bool } // Version returns the codec version. @@ -65,20 +70,20 @@ func (d *DACodecV4) NewDABatch(batch *Batch) (DABatch, error) { return nil, err } - // blob payload - blob, blobVersionedHash, z, blobBytes, err := d.constructBlobPayload(batch.Chunks, int(d.MaxNumChunksPerBatch()), false /* no mock */) + enableCompress, err := d.CheckBatchCompressedDataCompatibility(batch) if err != nil { return nil, err } - lastChunk := batch.Chunks[len(batch.Chunks)-1] - lastBlock := lastChunk.Blocks[len(lastChunk.Blocks)-1] - - d.enableCompress, err = d.CheckBatchCompressedDataCompatibility(batch) + // blob payload + blob, blobVersionedHash, z, blobBytes, err := d.constructBlobPayload(batch.Chunks, int(d.MaxNumChunksPerBatch()), enableCompress, false /* no mock */) if err != nil { return nil, err } + lastChunk := batch.Chunks[len(batch.Chunks)-1] + lastBlock := lastChunk.Blocks[len(lastChunk.Blocks)-1] + return newDABatchV3( uint8(CodecV4), // version batch.Index, // batchIndex @@ -128,6 +133,120 @@ func (d *DACodecV4) NewDABatchFromBytes(data []byte) (DABatch, error) { return b, nil } +// constructBlobPayload constructs the 4844 blob payload. +func (d *DACodecV4) constructBlobPayload(chunks []*Chunk, maxNumChunksPerBatch int, enableCompress bool, useMockTxData bool) (*kzg4844.Blob, common.Hash, *kzg4844.Point, []byte, error) { + // metadata consists of num_chunks (2 bytes) and chunki_size (4 bytes per chunk) + metadataLength := 2 + maxNumChunksPerBatch*4 + + // batchBytes represents the raw (un-compressed and un-padded) blob payload + batchBytes := make([]byte, metadataLength) + + // challenge digest preimage + // 1 hash for metadata, 1 hash for each chunk, 1 hash for blob versioned hash + challengePreimage := make([]byte, (1+maxNumChunksPerBatch+1)*32) + + // the chunk data hash used for calculating the challenge preimage + var chunkDataHash common.Hash + + // blob metadata: num_chunks + binary.BigEndian.PutUint16(batchBytes[0:], uint16(len(chunks))) + + // encode blob metadata and L2 transactions, + // and simultaneously also build challenge preimage + for chunkID, chunk := range chunks { + currentChunkStartIndex := len(batchBytes) + + for _, block := range chunk.Blocks { + for _, tx := range block.Transactions { + if tx.Type == types.L1MessageTxType { + continue + } + + // encode L2 txs into blob payload + rlpTxData, err := convertTxDataToRLPEncoding(tx, useMockTxData) + if err != nil { + return nil, common.Hash{}, nil, nil, err + } + batchBytes = append(batchBytes, rlpTxData...) + } + } + + // blob metadata: chunki_size + if chunkSize := len(batchBytes) - currentChunkStartIndex; chunkSize != 0 { + binary.BigEndian.PutUint32(batchBytes[2+4*chunkID:], uint32(chunkSize)) + } + + // challenge: compute chunk data hash + chunkDataHash = crypto.Keccak256Hash(batchBytes[currentChunkStartIndex:]) + copy(challengePreimage[32+chunkID*32:], chunkDataHash[:]) + } + + // if we have fewer than maxNumChunksPerBatch chunks, the rest + // of the blob metadata is correctly initialized to 0, + // but we need to add padding to the challenge preimage + for chunkID := len(chunks); chunkID < maxNumChunksPerBatch; chunkID++ { + // use the last chunk's data hash as padding + copy(challengePreimage[32+chunkID*32:], chunkDataHash[:]) + } + + // challenge: compute metadata hash + hash := crypto.Keccak256Hash(batchBytes[0:metadataLength]) + copy(challengePreimage[0:], hash[:]) + + var blobBytes []byte + if enableCompress { + // blobBytes represents the compressed blob payload (batchBytes) + var err error + blobBytes, err = zstd.CompressScrollBatchBytes(batchBytes) + if err != nil { + return nil, common.Hash{}, nil, nil, err + } + if !useMockTxData { + // Check compressed data compatibility. + if err = CheckCompressedDataCompatibility(blobBytes); err != nil { + log.Error("ConstructBlobPayload: compressed data compatibility check failed", "err", err, "batchBytes", hex.EncodeToString(batchBytes), "blobBytes", hex.EncodeToString(blobBytes)) + return nil, common.Hash{}, nil, nil, err + } + } + blobBytes = append([]byte{1}, blobBytes...) + } else { + blobBytes = append([]byte{0}, batchBytes...) + } + + if len(blobBytes) > 126976 { + log.Error("ConstructBlobPayload: Blob payload exceeds maximum size", "size", len(blobBytes), "blobBytes", hex.EncodeToString(blobBytes)) + return nil, common.Hash{}, nil, nil, errors.New("Blob payload exceeds maximum size") + } + + // convert raw data to BLSFieldElements + blob, err := makeBlobCanonical(blobBytes) + if err != nil { + return nil, common.Hash{}, nil, nil, err + } + + // compute blob versioned hash + c, err := kzg4844.BlobToCommitment(blob) + if err != nil { + return nil, common.Hash{}, nil, nil, errors.New("failed to create blob commitment") + } + blobVersionedHash := kzg4844.CalcBlobHashV1(sha256.New(), &c) + + // challenge: append blob versioned hash + copy(challengePreimage[(1+maxNumChunksPerBatch)*32:], blobVersionedHash[:]) + + // compute z = challenge_digest % BLS_MODULUS + challengeDigest := crypto.Keccak256Hash(challengePreimage) + pointBigInt := new(big.Int).Mod(new(big.Int).SetBytes(challengeDigest[:]), blsModulus) + pointBytes := pointBigInt.Bytes() + + // the challenge point z + var z kzg4844.Point + start := 32 - len(pointBytes) + copy(z[start:], pointBytes) + + return blob, blobVersionedHash, &z, blobBytes, nil +} + // EstimateChunkL1CommitBatchSizeAndBlobSize estimates the L1 commit uncompressed batch size and compressed blob size for a single chunk. func (d *DACodecV4) EstimateChunkL1CommitBatchSizeAndBlobSize(c *Chunk) (uint64, uint64, error) { batchBytes, err := constructBatchPayloadInBlob([]*Chunk{c}, d) @@ -173,3 +292,39 @@ func (d *DACodecV4) EstimateBatchL1CommitBatchSizeAndBlobSize(b *Batch) (uint64, } return uint64(len(batchBytes)), calculatePaddedBlobSize(blobBytesLength), nil } + +// CheckChunkCompressedDataCompatibility checks the compressed data compatibility for a batch built from a single chunk. +// It constructs a batch payload, compresses the data, and checks the compressed data compatibility if the uncompressed data exceeds 128 KiB. +func (d *DACodecV4) CheckChunkCompressedDataCompatibility(c *Chunk) (bool, error) { + batchBytes, err := constructBatchPayloadInBlob([]*Chunk{c}, d) + if err != nil { + return false, err + } + blobBytes, err := zstd.CompressScrollBatchBytes(batchBytes) + if err != nil { + return false, err + } + if err = CheckCompressedDataCompatibility(blobBytes); err != nil { + log.Warn("CheckChunkCompressedDataCompatibility: compressed data compatibility check failed", "err", err, "batchBytes", hex.EncodeToString(batchBytes), "blobBytes", hex.EncodeToString(blobBytes)) + return false, nil + } + return true, nil +} + +// CheckBatchCompressedDataCompatibility checks the compressed data compatibility for a batch. +// It constructs a batch payload, compresses the data, and checks the compressed data compatibility if the uncompressed data exceeds 128 KiB. +func (d *DACodecV4) CheckBatchCompressedDataCompatibility(b *Batch) (bool, error) { + batchBytes, err := constructBatchPayloadInBlob(b.Chunks, d) + if err != nil { + return false, err + } + blobBytes, err := zstd.CompressScrollBatchBytes(batchBytes) + if err != nil { + return false, err + } + if err = CheckCompressedDataCompatibility(blobBytes); err != nil { + log.Warn("CheckBatchCompressedDataCompatibility: compressed data compatibility check failed", "err", err, "batchBytes", hex.EncodeToString(batchBytes), "blobBytes", hex.EncodeToString(blobBytes)) + return false, nil + } + return true, nil +} diff --git a/encoding/codecv4_test.go b/encoding/codecv4_test.go index 726ae81..4576997 100644 --- a/encoding/codecv4_test.go +++ b/encoding/codecv4_test.go @@ -6,7 +6,6 @@ import ( "strings" "testing" - "github.com/scroll-tech/da-codec/encoding/zstd" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/core/types" "github.com/stretchr/testify/assert" @@ -254,7 +253,7 @@ func TestCodecV4BatchEncode(t *testing.T) { daBatch, err := codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = hex.EncodeToString(daBatch.Encode()) - assert.Equal(t, "040000000000000000000000000000000000000000000000009f81f6879f121da5b7a37535cdb21b3d53099266de57b1fdf603ce32100ed54101bbc6b98d7d3783730b6208afac839ad37dcf211b9d9e7c83a5f9d02125ddd700000000000000000000000000000000000000000000000000000000000000000000000063807b2a098f1f136f5734039818bee35222d35a96acd7d17120ce8816307527d19badea17d013be5ef696cfbc05b97bb322a587432c2cb23c4848d4d7cb8453c475b38d", encoded) + assert.Equal(t, "040000000000000000000000000000000000000000000000009f81f6879f121da5b7a37535cdb21b3d53099266de57b1fdf603ce32100ed54101e5c897e0f98f6addd6c99bb51ff927cde93851b0d407aae3d7d5de75a31f2900000000000000000000000000000000000000000000000000000000000000000000000063807b2a26451ed31542ed15543973f8bc8c3b6382ba0cba5650a7faf14625377029203c1b6db22aa24613cb68dee10ca50bbbc88fc15b8a6abf9dcf3ad382a2642e480d", encoded) block3 := readBlockFromJSON(t, "testdata/blockTrace_03.json") chunk3 := &Chunk{Blocks: []*Block{block3}} @@ -262,7 +261,7 @@ func TestCodecV4BatchEncode(t *testing.T) { daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = hex.EncodeToString(daBatch.Encode()) - assert.Equal(t, "04000000000000000000000000000000000000000000000000d46d19f6d48083dc7905a68e6a20ea6a8fbcd445d56b549b324a8485b5b574a601fae670a781fb1ea366dad9c02caf4ea1de4f699214c8171f9219b0c72f6ad400000000000000000000000000000000000000000000000000000000000000000000000063807b2d2c440817c5d20c385554774de3fa5d9f32da1dcba228e5cf04f627a41b4b779203f4ef0f3161a3a812523673119d90fb5303248b9fc58c3031a7f4b0937912b8", encoded) + assert.Equal(t, "04000000000000000000000000000000000000000000000000d46d19f6d48083dc7905a68e6a20ea6a8fbcd445d56b549b324a8485b5b574a601ad8c8eee24cc98ab1ca9c0a4c92bf20f488f06dedbc22f1312bd389df7105000000000000000000000000000000000000000000000000000000000000000000000000063807b2d30702c0ea39553a0601a9c6fc5b27c076ddfc1044001fb0a8ad1fd9016304a61233de2770e0fb9a5578e5f633846ef9fa4c2ab8b80b8f9a30f09be07cda8d725", encoded) block4 := readBlockFromJSON(t, "testdata/blockTrace_04.json") chunk4 := &Chunk{Blocks: []*Block{block4}} @@ -270,7 +269,7 @@ func TestCodecV4BatchEncode(t *testing.T) { daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = hex.EncodeToString(daBatch.Encode()) - assert.Equal(t, "040000000000000000000000000000000b000000000000000bcaece1705bf2ce5e94154469d910ffe8d102419c5eb3152c0c6d237cf35c885f012e15203534ae3f4cbe1b0f58fe6db6e5c29432115a8ece6ef5550bf2ffce4c000000000000000000000000000000000000000000000000000000000000000000000000646b6e133e935190ba34184cc7bf61a54e030b0ec229292b3025c14c3ef7672b259521cf27c007dc51295c1fe2e05882128a62ef03fb30aaaa4415505929eac7f35424f2", encoded) + assert.Equal(t, "040000000000000000000000000000000b000000000000000bcaece1705bf2ce5e94154469d910ffe8d102419c5eb3152c0c6d237cf35c885f01c6a9a7d06425dbfad42697e4ce5bc8562d7c5ffe1f62d57fcb51240e33af93000000000000000000000000000000000000000000000000000000000000000000000000646b6e1338122423f3cebb92645f9ac93c8ee50edb75ea93a951f278007e721a7b9f995824895b00195499dfe77d201cf3627050d866abb2685f87e10466c4fcaf3a8588", encoded) block5 := readBlockFromJSON(t, "testdata/blockTrace_05.json") chunk5 := &Chunk{Blocks: []*Block{block5}} @@ -278,7 +277,7 @@ func TestCodecV4BatchEncode(t *testing.T) { daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = hex.EncodeToString(daBatch.Encode()) - assert.Equal(t, "040000000000000000000000000000002a000000000000002a93255aa24dd468c5645f1e6901b8131a7a78a0eeb2a17cbb09ba64688a8de6b4015b4e3d3dcd64cc0eb6a5ad535d7a1844a8c4cdad366ec73557bcc533941370000000000000000000000000000000000000000000000000000000000000000000000000646b6ed030ba77ffda1712a0cfbbfce9facbc25a2370dc67d6480c686da47b7f181d527e132f281fd2bc8409114826d70e3148c93b9b4fee7b21c7680e750b3b0c5f6df2", encoded) + assert.Equal(t, "040000000000000000000000000000002a000000000000002a93255aa24dd468c5645f1e6901b8131a7a78a0eeb2a17cbb09ba64688a8de6b4016ac24dabb9e1bbb3ec3c65b50a829564c2f56160ba92fbdb03ed7e4a0c439a000000000000000000000000000000000000000000000000000000000000000000000000646b6ed004e124536a56f650b0994e58647e59087bf99ecadbd7bc730ad6290f229fb0715885a06aad250ef3594c65a7a6a0e282175b1ad4d8b4063dac48e282bb5a9213", encoded) block6 := readBlockFromJSON(t, "testdata/blockTrace_06.json") chunk6 := &Chunk{Blocks: []*Block{block6}} @@ -286,7 +285,7 @@ func TestCodecV4BatchEncode(t *testing.T) { daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = hex.EncodeToString(daBatch.Encode()) - assert.Equal(t, "040000000000000000000000000000000a000000000000000ac7bcc8da943dd83404e84d9ce7e894ab97ce4829df4eb51ebbbe13c90b5a3f4d015b4e3d3dcd64cc0eb6a5ad535d7a1844a8c4cdad366ec73557bcc533941370000000000000000000000000000000000000000000000000000000000000000000000000646b6ed030ba77ffda1712a0cfbbfce9facbc25a2370dc67d6480c686da47b7f181d527e132f281fd2bc8409114826d70e3148c93b9b4fee7b21c7680e750b3b0c5f6df2", encoded) + assert.Equal(t, "040000000000000000000000000000000a000000000000000ac7bcc8da943dd83404e84d9ce7e894ab97ce4829df4eb51ebbbe13c90b5a3f4d016ac24dabb9e1bbb3ec3c65b50a829564c2f56160ba92fbdb03ed7e4a0c439a000000000000000000000000000000000000000000000000000000000000000000000000646b6ed004e124536a56f650b0994e58647e59087bf99ecadbd7bc730ad6290f229fb0715885a06aad250ef3594c65a7a6a0e282175b1ad4d8b4063dac48e282bb5a9213", encoded) block7 := readBlockFromJSON(t, "testdata/blockTrace_07.json") chunk7 := &Chunk{Blocks: []*Block{block7}} @@ -294,13 +293,13 @@ func TestCodecV4BatchEncode(t *testing.T) { daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = hex.EncodeToString(daBatch.Encode()) - assert.Equal(t, "04000000000000000000000000000001010000000000000101899a411a3309c6491701b7b955c7b1115ac015414bbb71b59a0ca561668d5208015b4e3d3dcd64cc0eb6a5ad535d7a1844a8c4cdad366ec73557bcc533941370000000000000000000000000000000000000000000000000000000000000000000000000646b6ed030ba77ffda1712a0cfbbfce9facbc25a2370dc67d6480c686da47b7f181d527e132f281fd2bc8409114826d70e3148c93b9b4fee7b21c7680e750b3b0c5f6df2", encoded) + assert.Equal(t, "04000000000000000000000000000001010000000000000101899a411a3309c6491701b7b955c7b1115ac015414bbb71b59a0ca561668d5208016ac24dabb9e1bbb3ec3c65b50a829564c2f56160ba92fbdb03ed7e4a0c439a000000000000000000000000000000000000000000000000000000000000000000000000646b6ed004e124536a56f650b0994e58647e59087bf99ecadbd7bc730ad6290f229fb0715885a06aad250ef3594c65a7a6a0e282175b1ad4d8b4063dac48e282bb5a9213", encoded) originalBatch = &Batch{Chunks: []*Chunk{chunk2, chunk3, chunk4, chunk5}} daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = hex.EncodeToString(daBatch.Encode()) - assert.Equal(t, "040000000000000000000000000000002a000000000000002ae7740182b0948139505b6b296d0c6c6f7717708323e6e687917acad823b559d8013750f6cb783ce2e8fec5a8aff6c45512f2496d6861204b11b6010fb4aa0029000000000000000000000000000000000000000000000000000000000000000000000000646b6ed073c21fcf521e068860a235a4b8f2cdf4a67966ccee1bb46b804b1e7d85333b516c079a4f68903dd18292f1bbdb36b2c94fcefe676931073c2340b2545a504de4", encoded) + assert.Equal(t, "040000000000000000000000000000002a000000000000002ae7740182b0948139505b6b296d0c6c6f7717708323e6e687917acad823b559d80113ba3d5c53a035f4b4ec6f8a2ba9ab521bccab9f90e3a713ab5fffc0adec57000000000000000000000000000000000000000000000000000000000000000000000000646b6ed012e49b70b64652e5cab5dfdd1f58958d863de1d7fcb959e09f147a98b0b895171560f81b17ec3a2fe1c8ed2d308ca5bf002d7e3c18db9682a8d0f5379bf213aa", encoded) chunk8 := &Chunk{Blocks: []*Block{block2, block3, block4}} chunk9 := &Chunk{Blocks: []*Block{block5}} @@ -308,7 +307,7 @@ func TestCodecV4BatchEncode(t *testing.T) { daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = hex.EncodeToString(daBatch.Encode()) - assert.Equal(t, "040000000000000000000000000000002a000000000000002a9b0f37c563d27d9717ab16d47075df996c54fe110130df6b11bfd7230e1347670128f90d5edbcb10d13521824ccc7f47f85aff6e2da01004f9a402854eb33632000000000000000000000000000000000000000000000000000000000000000000000000646b6ed01bea70cbdd3d088c0db7d3dd5a11a2934ec4e7db761195d1e62f9f38a2fd5b325910eea5d881106c394f8d9a80bac8ecc43a86e0b920c5dc93f89caa43b205c2", encoded) + assert.Equal(t, "040000000000000000000000000000002a000000000000002a9b0f37c563d27d9717ab16d47075df996c54fe110130df6b11bfd7230e1347670121388d141bd439af8447db5d00bacbfe1587fea6581f795e98588d95ba7f26000000000000000000000000000000000000000000000000000000000000000000000000646b6ed046aedf214a661b6b37b9c325fef4484ff3613a6fb52719609bf02a66bc7ba23b6e9b7bcbe3be0ba95654f16f715bf7e39ef87a84199340423f6487cf56058085", encoded) } func TestCodecV4BatchHash(t *testing.T) { @@ -328,54 +327,54 @@ func TestCodecV4BatchHash(t *testing.T) { originalBatch := &Batch{Chunks: []*Chunk{chunk2}} daBatch, err := codecv4.NewDABatch(originalBatch) assert.NoError(t, err) - assert.Equal(t, common.HexToHash("0x0684ec7f79e1950823f3aff20c6a3cde03357eb72027ee663347ac77d46f7565"), daBatch.Hash()) + assert.Equal(t, common.HexToHash("0x53d6da35c9b6f0413b6ebb80f4a8c19b0e3279481ddf602398a54d3b4e5d4f2c"), daBatch.Hash()) block3 := readBlockFromJSON(t, "testdata/blockTrace_03.json") chunk3 := &Chunk{Blocks: []*Block{block3}} originalBatch = &Batch{Chunks: []*Chunk{chunk3}} daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) - assert.Equal(t, common.HexToHash("0x094d6fb43f3bc4af387c8494f5b4d7ba82c9895a0122fbbe34f6a02cb512c564"), daBatch.Hash()) + assert.Equal(t, common.HexToHash("0x08feefdb19215bb0f51f85a3b02a0954ac7da67681e274db49b9102f4c6e0857"), daBatch.Hash()) block4 := readBlockFromJSON(t, "testdata/blockTrace_04.json") chunk4 := &Chunk{Blocks: []*Block{block4}} originalBatch = &Batch{Chunks: []*Chunk{chunk4}} daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) - assert.Equal(t, common.HexToHash("0xda211c0402d1546fe4964c0e3d61621f6f020c851fd255a2c55419a4e091eae9"), daBatch.Hash()) + assert.Equal(t, common.HexToHash("0xc56c5e51993342232193d1d93124bae30a5b1444eebf49b2dd5f2c5962d4d54d"), daBatch.Hash()) block5 := readBlockFromJSON(t, "testdata/blockTrace_05.json") chunk5 := &Chunk{Blocks: []*Block{block5}} originalBatch = &Batch{Chunks: []*Chunk{chunk5}} daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) - assert.Equal(t, common.HexToHash("0x6bc8b8a6125c4f82afcbf8f190cefd002a61606fb751aca04b99f34a7459f678"), daBatch.Hash()) + assert.Equal(t, common.HexToHash("0x2c32177c8b4c6289d977361c7fd0f1a6ea15add64da2eb8caf0420ac9b35231e"), daBatch.Hash()) block6 := readBlockFromJSON(t, "testdata/blockTrace_06.json") chunk6 := &Chunk{Blocks: []*Block{block6}} originalBatch = &Batch{Chunks: []*Chunk{chunk6}} daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) - assert.Equal(t, common.HexToHash("0x985335548d6816cf955f39baa9e62ffec7068ac8591f7c7ea5a39d5b4929c29f"), daBatch.Hash()) + assert.Equal(t, common.HexToHash("0x909bebbebdbf5ba9c85c6894e839c0b044d2878c457c4942887e3d64469ad342"), daBatch.Hash()) block7 := readBlockFromJSON(t, "testdata/blockTrace_07.json") chunk7 := &Chunk{Blocks: []*Block{block7}} originalBatch = &Batch{Chunks: []*Chunk{chunk7}} daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) - assert.Equal(t, common.HexToHash("0x4ae2e62edaf78d4c9278c170b3ea2b0fb81c95c8875f523dbe889fe5035791ab"), daBatch.Hash()) + assert.Equal(t, common.HexToHash("0x53765a37bbd72655df586b530d79cb4ad0fb814d72ddc95e01e0ede579f45117"), daBatch.Hash()) originalBatch = &Batch{Chunks: []*Chunk{chunk2, chunk3, chunk4, chunk5}} daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) - assert.Equal(t, common.HexToHash("0xc4120eefe42981b827f5c9a67b8f9b14007bf624694e5702f0f8a665b68832ad"), daBatch.Hash()) + assert.Equal(t, common.HexToHash("0x74ccf9cc265f423cc6e6e53ed294000637a832cdc93c76485855289bebb6764a"), daBatch.Hash()) chunk8 := &Chunk{Blocks: []*Block{block2, block3, block4}} chunk9 := &Chunk{Blocks: []*Block{block5}} originalBatch = &Batch{Chunks: []*Chunk{chunk8, chunk9}} daBatch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) - assert.Equal(t, common.HexToHash("0xa152b2e1594032ce70be219cfa9781f0840120ac2bf3fcad24893d77c4b74077"), daBatch.Hash()) + assert.Equal(t, common.HexToHash("0x8d5ee00a80d7dbdc083d0cdedd35c2cb722e5944f9d88f7450c9186f3ef3da44"), daBatch.Hash()) } func TestCodecV4BatchDataHash(t *testing.T) { @@ -819,8 +818,8 @@ func TestCodecV4BlobEncodingAndHashing(t *testing.T) { batch, err := codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded := strings.TrimRight(hex.EncodeToString(batch.(*daBatchV3).blob[:]), "0") - assert.Equal(t, "00609c00fd0600240d0001000000e600f87180843b9aec2e8307a12094c0c4c800baea3f6acb49b6e1fb9e2adeceeacb0ca28a152d02c7e14af6000000808301009ecea0ab07ae99c67aa78e7ba5cf6781e90cc32b219b1de102513d56548a4100e86df514a034cbd19feacd73e8ce64d00c4d1996b9b5243c578fd7f51bfaec00288bbaf42a8bf8710101bae6bf68e9a03fb2bc0615b1bf0d69ce9411edf03900985866d8256f10c1be4f7b2cace28d8f20bde27e2604393eb095b7f77316a0005a3e6e81065f2b4604bcec5bd4aba684835996fc3f879380aac1c09c6eed3200f1030060b26d07d8b028b005", encoded) - assert.Equal(t, common.HexToHash("0x01bbc6b98d7d3783730b6208afac839ad37dcf211b9d9e7c83a5f9d02125ddd7"), batch.(*daBatchV3).blobVersionedHash) + assert.Equal(t, "0001609c00fd0600240d0001000000e600f87180843b9aec2e8307a12094c0c400c8baea3f6acb49b6e1fb9e2adeceeacb0ca28a152d02c7e14af6000000808300019ecea0ab07ae99c67aa78e7ba5cf6781e90cc32b219b1de102513d56548a0041e86df514a034cbd19feacd73e8ce64d00c4d1996b9b5243c578fd7f51bfa00ec288bbaf42a8bf8710101bae6bf68e9a03fb2bc0615b1bf0d69ce9411edf00039985866d8256f10c1be4f7b2cace28d8f20bde27e2604393eb095b7f7731600a05a3e6e81065f2b4604bcec5bd4aba684835996fc3f879380aac1c09c6eed0032f1030060b26d07d8b028b005", encoded) + assert.Equal(t, common.HexToHash("0x01e5c897e0f98f6addd6c99bb51ff927cde93851b0d407aae3d7d5de75a31f29"), batch.(*daBatchV3).blobVersionedHash) block3 := readBlockFromJSON(t, "testdata/blockTrace_03.json") chunk3 := &Chunk{Blocks: []*Block{block3}} @@ -828,8 +827,8 @@ func TestCodecV4BlobEncodingAndHashing(t *testing.T) { batch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = strings.TrimRight(hex.EncodeToString(batch.(*daBatchV3).blob[:]), "0") - assert.Equal(t, "0060e7159d580094830001000016310002f9162d82cf5502843b9b0a1783119700e28080b915d260806040523480156200001157600080fd5b5060405162001400b2380380833981810160405260a0811037815160208301516040808501805100915193959294830192918464018211639083019060208201858179825181110082820188101794825250918201929091019080838360005b83c357818101510083820152602001620000a9565b50505050905090810190601f16f1578082030080516001836020036101000a0319168191508051604051939291900115012b0001460175015b01a39081015185519093508592508491620001c891600391850001906200026b565b508051620001de90600490602084506005805461ff00190060ff1990911660121716905550600680546001600160a01b0380881619928300161790925560078054928716929091169190911790556200023081620002550062010000600160b01b03191633021790555062000307915050565b60ff19160060ff929092565b828160011615610100020316600290049060005260206000002090601f016020900481019282601f10620002ae5780518380011785de016000010185558215620002de579182015b8202de5782518255916020019190600100c1565b50620002ec9291f0565b5090565b5b8002ec576000815560010162000002f1565b61119b80620003176000396000f3fe61001004361061010b576000003560e01c80635c975abb116100a257806395d89b411161007114610301578000639dc29fac14610309578063a457c2d714610335578063a9059cbb1461036100578063dd62ed3e1461038d5761010b565b1461029d57806370a0823114610200a55780638456cb59146102cb5780638e50817a146102d3313ce567116100de00571461021d578063395093511461023b5780633f4ba83a146102675780634000c10f191461027106fdde0314610110578063095ea7b31461018d5780631816000ddd146101cd57806323b872e7575b6101186103bb565b6040805160208082005283518183015283519192839290830161015261013a61017f9250508091030090f35b6101b9600480360360408110156101a381351690602001356104519100151582525190819003602001d561046e60fd81169160208101359091169060004074565b6102256104fb60ff90921640025105046f610552565b005b61026f00028705a956610654d520bb3516610662067d56e90135166106d21861075703001f07b856034b085f77c7d5a308db565b6003805420601f600260001961010000600188161502019095169490940493840181900481028201810190925282810052606093909290918301828280156104475780601f1061041c57610100808300540402835291610447565b825b8154815260200180831161042a5782900360001f16820191565b600061046561045e610906565b848461090a565b506001920002548184f6565b6104f18461048d6104ec8560405180606080602861108560002891398a166000908152600160205260408120906104cb81019190915260400001600020549190610b51565b935460ff160511016000610522908116825260002080830193909352604091820120918c168152925290205490610be8565b60000716331461059f5762461bcd60e51b60040b60248201526a1b9bdd08185b1b001bddd95960aa1b604482015290640190fd5b6105a7610c49565b61010090040060ff16156105f9106f14185d5cd8589b194e881c185d5cd9596082600606460006508282610ced909052604006ca0ddd900407260c6b6f6e6c792046616374006f727960a0079283918216179091559390921660041561080808550e65086c002511176025006108968dd491824080832093909416825233831661094f5704000180806020018281038252602401806110f36024913960400191fd821661090094223d60228084166000819487168084529482529182902085905581518581005291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200a00c8c7c3b92592819003a3508316610a3b25ce8216610a80230ff86023610a8b00838383610f61565b610ac881265f60268685808220939093559084168152200054610af7908220409490945580905191937fddf252ad1be2c89b69c2b068fc00378daa952ba7f163c4a11628f55a4df523b3ef929182900300818484111561000be08381815191508051900ba50b8d0bd2fd900300828201610c421b7f53610066654d6174683a206164646974696f6e206f766572666c6f7700610c9c147300621690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd3008aeae4b073aa610cd0a18216610d481f7f45524332303a206d696e7420746f0020746865207a65726f72657373610d546000600254610d610255902054610d008780838393519293910e2d6101001790557f62e78cea01bee320cd4e42027000b5ea74000d11b0c9f74754ebdbfc544b05a2588216610eaa6021ad6021610e00b68260000ef3221b85839020550f199082610fb540805182600091851691910020565b610f6cb07415610fb02a113c602a00610c428383401e7375627472610063815250fe7472616e736665726275726e20616d6f756e742065786365656400732062616c616e6365617070726f7665616c6c6f7766726f6d646563726561007365642062656c6f775061757361626c653a20746f6b656e7768696c652070006175736564a2646970667358221220e96342bec8f6c2bf72815a39998973b6004c3bed57770f402e9a7b7eeda0265d4c64736f6c634300060c00331c5a77d900fa7ef466951b2f01f724bca3a5820b63a0e012095745544820636f696e04c00001a0235c1a8d40e8c347890397f1a92e6eadbd6422cf7c210e3e1737f0553c00633172a02f7c0384ddd06970446e74229cd96216da62196dc62395bda5209500d44b8a9af7813ca8c134a9149a111111110549d2740105c410e61ca4d60312006013290b6398528818e2c8484081888c4890142465a631e63178f9940048f4006ba77adb9be01e898bbbfbc0afba2b64ed71162098740e35ec699633c6a84900670da2d948458ecd9f2e5dc5c5ac4afe3d62cf457cd3507b2eae71e064fab30088531f9c708fd40558dfc698511c4a68234d058c4972da28f0201c4ee550b500e36f0bb42e46bb556d6197be7ea27a3a853e5da024de5ea930350219b1638a00a1dcd41f8222f5d647291e05238c248aa4e028278ad4a9a720f5c16f637166004c4cc255e402cdf64c88e9231dd28a07b8f0ddf1dd7b388875a13dc6d447c000318bca02c54cdfa3621635af1ff932928dfde06038ac9729c301f9f3a3a395008d502ba9e137cc24c14cb4102cf6ba6708b9c812c3ba59a3cbcc5d2aafa8b50097b49fbeb704a22b6137ae9a13b600ad73748768b42756ba338f9854164b1b003f3e23255e4db853a2d3276f061093a37810212ba36db205219fab403242800009178588ad21f754085dd807b09af69e6f06bccbcef8ade3b1f0eb15a077b8005b024ecef4087f261a0d4033355c1e544bd0b0c100276008c420d6d30bc8be00a3ba741063e8b48cf152d3695c0904d477318d4ad46477cdf962443336479f00bd86fd52d4e2a1d23eeddc52463d524b44644abdcd097025bcf9cc636fc1030092cb15b81d7ea667f3ba711624bbf04e992871a6ea4f9d367ba6d46142176f00cdf03e4e19549d2eea45ca804421f6bc33933aab6d478b291bf3619fe15bc900975409d8f3677a87d1b1f7acdb3071b752f3d95c9363ac9c83752f223e45e50079308f554787b4d1f74e389823923f5d268be545466a2dd449963ad25407bd003a18601410b91ca081537f67ea8d527a49adf256f2363346ea35a2fe2768a900091a184f59680df81982c6087efc651f54693a7870aa7c13dcf054c39536c500de8a2dd66955567ff1730dac8533de482aed706ed3417823dd65d058b98899008d54917fd1f70735f7a6a8b1a053c08aac96fb04", encoded) - assert.Equal(t, common.HexToHash("0x01fae670a781fb1ea366dad9c02caf4ea1de4f699214c8171f9219b0c72f6ad4"), batch.(*daBatchV3).blobVersionedHash) + assert.Equal(t, "000160e7159d580094830001000016310002f9162d82cf5502843b9b0a1783110097e28080b915d260806040523480156200001157600080fd5b5060405162000014b2380380833981810160405260a0811037815160208301516040808501800051915193959294830192918464018211639083019060208201858179825181001182820188101794825250918201929091019080838360005b83c357818101005183820152602001620000a9565b50505050905090810190601f16f1578082000380516001836020036101000a031916819150805160405193929190011501002b01460175015b01a39081015185519093508592508491620001c891600391008501906200026b565b508051620001de90600490602084506005805461ff00001960ff1990911660121716905550600680546001600160a01b0380881619920083161790925560078054928716929091169190911790556200023081620002005562010000600160b01b03191633021790555062000307915050565b60ff19001660ff929092565b828160011615610100020316600290049060005260206000002090601f016020900481019282601f10620002ae5780518380011785de010060010185558215620002de579182015b8202de5782518255916020019190600001c1565b50620002ec9291f0565b5090565b5b8002ec576000815560010162000002f1565b61119b80620003176000396000f3fe61001004361061010b576000003560e01c80635c975abb116100a257806395d89b411161007114610301570080639dc29fac14610309578063a457c2d714610335578063a9059cbb1461030061578063dd62ed3e1461038d5761010b565b1461029d57806370a0823114610002a55780638456cb59146102cb5780638e50817a146102d3313ce56711610000de571461021d578063395093511461023b5780633f4ba83a146102675780630040c10f191461027106fdde0314610110578063095ea7b31461018d5780631800160ddd146101cd57806323b872e7575b6101186103bb565b6040805160208000825283518183015283519192839290830161015261013a61017f9250508091000390f35b6101b9600480360360408110156101a381351690602001356104510091151582525190819003602001d561046e60fd81169160208101359091169000604074565b6102256104fb60ff90921640025105046f610552565b005b6102006f028705a956610654d520bb3516610662067d56e90135166106d21861075700031f07b856034b085f77c7d5a308db565b6003805420601f600260001961010000600188161502019095169490940493840181900481028201810190925282008152606093909290918301828280156104475780601f1061041c57610100800083540402835291610447565b825b8154815260200180831161042a5782900300601f16820191565b600061046561045e610906565b848461090a565b506001009202548184f6565b6104f18461048d6104ec8560405180606080602861108500602891398a166000908152600160205260408120906104cb81019190915260004001600020549190610b51565b935460ff160511016000610522908116825200602080830193909352604091820120918c168152925290205490610be8565b00600716331461059f5762461bcd60e51b60040b60248201526a1b9bdd08185b001b1bddd95960aa1b604482015290640190fd5b6105a7610c49565b61010090000460ff16156105f9106f14185d5cd8589b194e881c185d5cd9596082600606004606508282610ced909052604006ca0ddd900407260c6b6f6e6c792046616300746f727960a0079283918216179091559390921660041561080808550e6508006c2511176025006108968dd491824080832093909416825233831661094f5700040180806020018281038252602401806110f36024913960400191fd821661000994223d60228084166000819487168084529482529182902085905581518500815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b20000ac8c7c3b92592819003a3508316610a3b25ce8216610a80230ff86023610a008b838383610f61565b610ac881265f60268685808220939093559084168152002054610af7908220409490945580905191937fddf252ad1be2c89b69c2b06800fc378daa952ba7f163c4a11628f55a4df523b3ef929182900300818484111500610be08381815191508051900ba50b8d0bd2fd900300828201610c421b7f53006166654d6174683a206164646974696f6e206f766572666c6f7700610c9c140073621690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537b00d38aeae4b073aa610cd0a18216610d481f7f45524332303a206d696e742074006f20746865207a65726f72657373610d546000600254610d61025590205461000d8780838393519293910e2d6101001790557f62e78cea01bee320cd4e42020070b5ea74000d11b0c9f74754ebdbfc544b05a2588216610eaa6021ad602161000eb68260000ef3221b85839020550f199082610fb540805182600091851691009120565b610f6cb07415610fb02a113c602a00610c428383401e7375627472006163815250fe7472616e736665726275726e20616d6f756e742065786365650064732062616c616e6365617070726f7665616c6c6f7766726f6d646563726500617365642062656c6f775061757361626c653a20746f6b656e7768696c652000706175736564a2646970667358221220e96342bec8f6c2bf72815a3999897300b64c3bed57770f402e9a7b7eeda0265d4c64736f6c634300060c00331c5a7700d9fa7ef466951b2f01f724bca3a5820b63a0e012095745544820636f696e0400c001a0235c1a8d40e8c347890397f1a92e6eadbd6422cf7c210e3e1737f055003c633172a02f7c0384ddd06970446e74229cd96216da62196dc62395bda5200095d44b8a9af7813ca8c134a9149a111111110549d2740105c410e61ca4d60300126013290b6398528818e2c8484081888c4890142465a631e63178f994004800f46ba77adb9be01e898bbbfbc0afba2b64ed71162098740e35ec699633c6a80049670da2d948458ecd9f2e5dc5c5ac4afe3d62cf457cd3507b2eae71e064fa00b388531f9c708fd40558dfc698511c4a68234d058c4972da28f0201c4ee55000b5e36f0bb42e46bb556d6197be7ea27a3a853e5da024de5ea930350219b163008aa1dcd41f8222f5d647291e05238c248aa4e028278ad4a9a720f5c16f637100664c4cc255e402cdf64c88e9231dd28a07b8f0ddf1dd7b388875a13dc6d44700c0318bca02c54cdfa3621635af1ff932928dfde06038ac9729c301f9f3a3a300958d502ba9e137cc24c14cb4102cf6ba6708b9c812c3ba59a3cbcc5d2aafa800b597b49fbeb704a22b6137ae9a13b600ad73748768b42756ba338f9854164b001b3f3e23255e4db853a2d3276f061093a37810212ba36db205219fab403242008009178588ad21f754085dd807b09af69e6f06bccbcef8ade3b1f0eb15a07700b85b024ecef4087f261a0d4033355c1e544bd0b0c100276008c420d6d30bc800bea3ba741063e8b48cf152d3695c0904d477318d4ad46477cdf96244333647009fbd86fd52d4e2a1d23eeddc52463d524b44644abdcd097025bcf9cc636fc1000392cb15b81d7ea667f3ba711624bbf04e992871a6ea4f9d367ba6d4614217006fcdf03e4e19549d2eea45ca804421f6bc33933aab6d478b291bf3619fe15b00c9975409d8f3677a87d1b1f7acdb3071b752f3d95c9363ac9c83752f223e4500e579308f554787b4d1f74e389823923f5d268be545466a2dd449963ad2540700bd3a18601410b91ca081537f67ea8d527a49adf256f2363346ea35a2fe276800a9091a184f59680df81982c6087efc651f54693a7870aa7c13dcf054c3953600c5de8a2dd66955567ff1730dac8533de482aed706ed3417823dd65d058b98800998d54917fd1f70735f7a6a8b1a053c08aac96fb04", encoded) + assert.Equal(t, common.HexToHash("0x01ad8c8eee24cc98ab1ca9c0a4c92bf20f488f06dedbc22f1312bd389df71050"), batch.(*daBatchV3).blobVersionedHash) block4 := readBlockFromJSON(t, "testdata/blockTrace_04.json") chunk4 := &Chunk{Blocks: []*Block{block4}} @@ -837,8 +836,8 @@ func TestCodecV4BlobEncodingAndHashing(t *testing.T) { batch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = strings.TrimRight(hex.EncodeToString(batch.(*daBatchV3).blob[:]), "0") - assert.Equal(t, "0020d67d0100740200010000002000df0b80825dc0941a258d17bf244c4df02d0040343a7626a9d321e105808080808001002c0a1801", encoded) - assert.Equal(t, common.HexToHash("0x012e15203534ae3f4cbe1b0f58fe6db6e5c29432115a8ece6ef5550bf2ffce4c"), batch.(*daBatchV3).blobVersionedHash) + assert.Equal(t, "000120d67d0100740200010000002000df0b80825dc0941a258d17bf244c4df0002d40343a7626a9d321e105808080808001002c0a1801", encoded) + assert.Equal(t, common.HexToHash("0x01c6a9a7d06425dbfad42697e4ce5bc8562d7c5ffe1f62d57fcb51240e33af93"), batch.(*daBatchV3).blobVersionedHash) // this batch only contains L1 txs block5 := readBlockFromJSON(t, "testdata/blockTrace_05.json") @@ -847,8 +846,8 @@ func TestCodecV4BlobEncodingAndHashing(t *testing.T) { batch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = strings.TrimRight(hex.EncodeToString(batch.(*daBatchV3).blob[:]), "0") - assert.Equal(t, "0020b6550000180001000100300a0c01", encoded) - assert.Equal(t, common.HexToHash("0x015b4e3d3dcd64cc0eb6a5ad535d7a1844a8c4cdad366ec73557bcc533941370"), batch.(*daBatchV3).blobVersionedHash) + assert.Equal(t, "00000001", encoded) + assert.Equal(t, common.HexToHash("0x016ac24dabb9e1bbb3ec3c65b50a829564c2f56160ba92fbdb03ed7e4a0c439a"), batch.(*daBatchV3).blobVersionedHash) block6 := readBlockFromJSON(t, "testdata/blockTrace_06.json") chunk6 := &Chunk{Blocks: []*Block{block6}} @@ -856,8 +855,8 @@ func TestCodecV4BlobEncodingAndHashing(t *testing.T) { batch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = strings.TrimRight(hex.EncodeToString(batch.(*daBatchV3).blob[:]), "0") - assert.Equal(t, "0020b6550000180001000100300a0c01", encoded) - assert.Equal(t, common.HexToHash("0x015b4e3d3dcd64cc0eb6a5ad535d7a1844a8c4cdad366ec73557bcc533941370"), batch.(*daBatchV3).blobVersionedHash) + assert.Equal(t, "00000001", encoded) + assert.Equal(t, common.HexToHash("0x016ac24dabb9e1bbb3ec3c65b50a829564c2f56160ba92fbdb03ed7e4a0c439a"), batch.(*daBatchV3).blobVersionedHash) block7 := readBlockFromJSON(t, "testdata/blockTrace_07.json") chunk7 := &Chunk{Blocks: []*Block{block7}} @@ -865,16 +864,16 @@ func TestCodecV4BlobEncodingAndHashing(t *testing.T) { batch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = strings.TrimRight(hex.EncodeToString(batch.(*daBatchV3).blob[:]), "0") - assert.Equal(t, "0020b6550000180001000100300a0c01", encoded) - assert.Equal(t, common.HexToHash("0x015b4e3d3dcd64cc0eb6a5ad535d7a1844a8c4cdad366ec73557bcc533941370"), batch.(*daBatchV3).blobVersionedHash) + assert.Equal(t, "00000001", encoded) + assert.Equal(t, common.HexToHash("0x016ac24dabb9e1bbb3ec3c65b50a829564c2f56160ba92fbdb03ed7e4a0c439a"), batch.(*daBatchV3).blobVersionedHash) // 45 chunks originalBatch = &Batch{Chunks: []*Chunk{chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2}} batch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = strings.TrimRight(hex.EncodeToString(batch.(*daBatchV3).blob[:]), "0") - assert.Equal(t, "006024281d0700140d002d000000e6f87180843b9aec2e8307a12094c0c4c8ba00ea3f6acb49b6e1fb9e2adeceeacb0ca28a152d02c7e14af60000008083019e00cea0ab07ae99c67aa78e7ba5cf6781e90cc32b219b1de102513d56548a41e8006df514a034cbd19feacd73e8ce64d00c4d1996b9b5243c578fd7f51bfaec28008bbaf42a8bf8710101bae6bf68e9a03fb2bc0615b1bf0d69ce9411edf03998005866d8256f10c1be4f7b2cace28d8f20bde27e2604393eb095b7f77316a05a003e6e81065f2b4604bcec5bd4aba684835996fc3f879380aac1c09c6eed32f100040041e1491b3e82c9b61d60d39a727", encoded) - assert.Equal(t, common.HexToHash("0x01fc79efca1213db1aa0183865b0a360dc152662cde34ee6a34e7607b96c1c89"), batch.(*daBatchV3).blobVersionedHash) + assert.Equal(t, "00016024281d0700140d002d000000e6f87180843b9aec2e8307a12094c0c4c800baea3f6acb49b6e1fb9e2adeceeacb0ca28a152d02c7e14af6000000808301009ecea0ab07ae99c67aa78e7ba5cf6781e90cc32b219b1de102513d56548a4100e86df514a034cbd19feacd73e8ce64d00c4d1996b9b5243c578fd7f51bfaec00288bbaf42a8bf8710101bae6bf68e9a03fb2bc0615b1bf0d69ce9411edf03900985866d8256f10c1be4f7b2cace28d8f20bde27e2604393eb095b7f77316a0005a3e6e81065f2b4604bcec5bd4aba684835996fc3f879380aac1c09c6eed3200f1040041e1491b3e82c9b61d60d39a727", encoded) + assert.Equal(t, common.HexToHash("0x0128a4e122c179a7c34ab1f22ceadf6fa66d2bb0d229933fe1ed061dd8b1fb5f"), batch.(*daBatchV3).blobVersionedHash) chunk8 := &Chunk{Blocks: []*Block{block2, block3, block4}} chunk9 := &Chunk{Blocks: []*Block{block5}} @@ -882,8 +881,8 @@ func TestCodecV4BlobEncodingAndHashing(t *testing.T) { batch, err = codecv4.NewDABatch(originalBatch) assert.NoError(t, err) encoded = strings.TrimRight(hex.EncodeToString(batch.(*daBatchV3).blob[:]), "0") - assert.Equal(t, "0060ed16256000449200020000173700f87180843b9aec2e8307a12094c0c4c800baea3f6acb49b6e1fb9e2adeceeacb0ca28a152d02c7e14af6000000808301009ecea0ab07ae99c67aa78e7ba5cf6781e90cc32b219b1de102513d56548a4100e86df514a034cbd19feacd73e8ce64d00c4d1996b9b5243c578fd7f51bfaec00288bbaf42a8bf8710101bae6bf68e9a03fb2bc0615b1bf0d69ce9411edf03900985866d8256f10c1be4f7b2cace28d8f20bde27e2604393eb095b7f77316a0005a3e6e81065f2b4604bcec5bd4aba684835996fc3f879380aac1c09c6eed3200f102f9162d82cf5502843b9b0a17831197e28080b915d26080604052348015006200001157600080fd5b50604051620014b2380380833981810160405260a000811037815160208301516040808501805191519395929483019291846401820011639083019060208201858179825181118282018810179482525091820192009091019080838360005b83c3578181015183820152602001620000a9565b5000505050905090810190601f16f15780820380516001836020036101000a031900168191508051604051939291900115012b01460175015b01a3908101518551009093508592508491620001c8916003918501906200026b565b50805162000100de90600490602084506005805461ff001960ff199091166012171690555060000680546001600160a01b03808816199283161790925560078054928716929000911691909117905562000230816200025562010000600160b01b0319163302001790555062000307915050565b60ff191660ff929092565b828160011615610001000203166002900490600052602060002090601f01602090048101928260001f10620002ae5780518380011785de0160010185558215620002de57918201005b8202de57825182559160200191906001c1565b50620002ec9291f0565b500090565b5b8002ec5760008155600101620002f1565b61119b8062000317600000396000f3fe61001004361061010b5760003560e01c80635c975abb116100a20057806395d89b4111610071146103015780639dc29fac14610309578063a45700c2d714610335578063a9059cbb14610361578063dd62ed3e1461038d576101000b565b1461029d57806370a08231146102a55780638456cb59146102cb578000638e50817a146102d3313ce567116100de571461021d57806339509351146100023b5780633f4ba83a1461026757806340c10f191461027106fdde031461010010578063095ea7b31461018d57806318160ddd146101cd57806323b872e757005b6101186103bb565b6040805160208082528351818301528351919283929000830161015261013a61017f92505080910390f35b6101b960048036036040810010156101a3813516906020013561045191151582525190819003602001d56100046e60fd811691602081013590911690604074565b6102256104fb60ff9092001640025105046f610552565b005b61026f028705a956610654d520bb351661000662067d56e90135166106d218610757031f07b856034b085f77c7d5a308db00565b6003805420601f600260001961010060018816150201909516949094040093840181900481028201810190925282815260609390929091830182828015006104475780601f1061041c576101008083540402835291610447565b825b810054815260200180831161042a57829003601f16820191565b60006104656104005e610906565b848461090a565b5060019202548184f6565b6104f18461048d006104ec85604051806060806028611085602891398a16600090815260016020005260408120906104cb810191909152604001600020549190610b51565b93540060ff160511016000610522908116825260208083019390935260409182012000918c168152925290205490610be8565b600716331461059f5762461bcd60e5001b60040b60248201526a1b9bdd08185b1b1bddd95960aa1b60448201529064000190fd5b6105a7610c49565b610100900460ff16156105f9106f14185d5cd800589b194e881c185d5cd95960826006064606508282610ced909052604006ca000ddd900407260c6b6f6e6c7920466163746f727960a007928391821617909100559390921660041561080808550e65086c2511176025006108968dd49182400080832093909416825233831661094f5704018080602001828103825260240100806110f36024913960400191fd8216610994223d60228084166000819487160080845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f0071427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92592819003a350831661000a3b25ce8216610a80230ff86023610a8b838383610f61565b610ac881265f00602686858082209390935590841681522054610af790822040949094558090005191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a004df523b3ef9291829003008184841115610be08381815191508051900ba50b008d0bd2fd900300828201610c421b7f536166654d6174683a20616464697469006f6e206f766572666c6f7700610c9c1473621690557f5db9ee0a495bf2e6ff009c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa610cd0a18216610d00481f7f45524332303a206d696e7420746f20746865207a65726f7265737361000d546000600254610d610255902054610d8780838393519293910e2d610100001790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc00544b05a2588216610eaa6021ad6021610eb68260000ef3221b85839020550f00199082610fb5408051826000918516919120565b610f6cb07415610fb02a11003c602a00610c428383401e73756274726163815250fe7472616e73666572620075726e20616d6f756e7420657863656564732062616c616e6365617070726f007665616c6c6f7766726f6d6465637265617365642062656c6f77506175736100626c653a20746f6b656e7768696c6520706175736564a264697066735822120020e96342bec8f6c2bf72815a39998973b64c3bed57770f402e9a7b7eeda026005d4c64736f6c634300060c00331c5a77d9fa7ef466951b2f01f724bca3a582000b63a0e012095745544820636f696e04c001a0235c1a8d40e8c347890397f100a92e6eadbd6422cf7c210e3e1737f0553c633172a02f7c0384ddd06970446e0074229cd96216da62196dc62395bda52095d44b8a9af7df0b80825dc0941a25008d17bf244c4df02d40343a7626a9d321e1058080808080813ea8c134a9149a00111111110549d2740105c410e61ca4d603126013290b6398528818e2c848400081888c4890142465a631e63178f9940048f46ba77adb9be01e898bbbfb80cc00ba2b64ed71162098740e35ec699633c6a849670da2d948458ecd9f2e5dc5c500ac4afe3d62cf457cd3507b2eae71e064fab388531f9c708fd40558dfc69851001c4a68234d058c4972da28f0201c4ee550b5e36f0bb42e46bb556d6197be7e00a27a3a853e5da024de5ea930350219b1638aa1dcd41f8222f5d647291e0523008c248aa4e028278ad4a9a720f5c16f6371664c4cc255e402cdf64c88e9231d00d28a07b8f0ddf1dd7b388875a13dc6d447c0318bca02c54cdfa3621635af1f00f932928dfde06038ac9729c301f9f3a3a3958d502ba9e137cc24c14cb4102c00f6ba6708b9c812c3ba59a3cbcc5d2aafa8b597b49fbeb704a22b6137ae9a1300b600ad73748768b42756ba338f9854164b1b3f3e23255e4db853a2d3276f06001093a37810212ba36db205219fab4032428009178588ad21f754085dd807b0009af69e6f06bccbcef8ade3b1f0eb15a077b85b024ecef4087f261a0d403335005c1e544bd0b0c100276008c420d6d30bc8bea3ba741063e8b48cf152d3695c000904d477318d4ad46477cdf962443336479fbd86fd52d4e2a1d23eeddc5246003d524b44644abdcd097025bcf9cc636fc10392cb15b81d7ea667f3ba71162400bbf04e992871a6ea4f9d367ba6d46142176fcdf03e4e19549d2eea45ca80440021f6bc33933aab6d478b291bf3619fe15bc9975409d8f3677a87d1b1f7acdb003071b752f3d95c9363ac9c83752f223e45e579308f554787b4d1f74e38982300923f5d268be545466a2dd449963ad25407bd3a18601410b91ca081537f67ea008d527a49adf256f2363346ea35a2fe2768a9091a184f59680df81982c6087e00fc651f54693a7870aa7c13dcf054c39536c5de8a2dd66955567ff1730dac850033de482aed706ed3417823dd65d058b988998d54917fe9bb80f5ee4d5c636d00a70ee60a586fdb282babf53e01", encoded) - assert.Equal(t, common.HexToHash("0x0128f90d5edbcb10d13521824ccc7f47f85aff6e2da01004f9a402854eb33632"), batch.(*daBatchV3).blobVersionedHash) + assert.Equal(t, "000160ed16256000449200020000173700f87180843b9aec2e8307a12094c0c400c8baea3f6acb49b6e1fb9e2adeceeacb0ca28a152d02c7e14af6000000808300019ecea0ab07ae99c67aa78e7ba5cf6781e90cc32b219b1de102513d56548a0041e86df514a034cbd19feacd73e8ce64d00c4d1996b9b5243c578fd7f51bfa00ec288bbaf42a8bf8710101bae6bf68e9a03fb2bc0615b1bf0d69ce9411edf00039985866d8256f10c1be4f7b2cace28d8f20bde27e2604393eb095b7f7731600a05a3e6e81065f2b4604bcec5bd4aba684835996fc3f879380aac1c09c6eed0032f102f9162d82cf5502843b9b0a17831197e28080b915d26080604052348000156200001157600080fd5b50604051620014b238038083398181016040526000a0811037815160208301516040808501805191519395929483019291846401008211639083019060208201858179825181118282018810179482525091820100929091019080838360005b83c3578181015183820152602001620000a9565b0050505050905090810190601f16f15780820380516001836020036101000a030019168191508051604051939291900115012b01460175015b01a3908101518500519093508592508491620001c8916003918501906200026b565b50805162000001de90600490602084506005805461ff001960ff199091166012171690555000600680546001600160a01b03808816199283161790925560078054928716920090911691909117905562000230816200025562010000600160b01b0319163300021790555062000307915050565b60ff191660ff929092565b828160011615006101000203166002900490600052602060002090601f01602090048101928200601f10620002ae5780518380011785de0160010185558215620002de57918200015b8202de57825182559160200191906001c1565b50620002ec9291f0565b005090565b5b8002ec5760008155600101620002f1565b61119b8062000317600000396000f3fe61001004361061010b5760003560e01c80635c975abb11610000a257806395d89b4111610071146103015780639dc29fac14610309578063a40057c2d714610335578063a9059cbb14610361578063dd62ed3e1461038d576100010b565b1461029d57806370a08231146102a55780638456cb59146102cb570080638e50817a146102d3313ce567116100de571461021d57806339509351140061023b5780633f4ba83a1461026757806340c10f191461027106fdde031461000110578063095ea7b31461018d57806318160ddd146101cd57806323b872e700575b6101186103bb565b6040805160208082528351818301528351919283920090830161015261013a61017f92505080910390f35b6101b960048036036040008110156101a3813516906020013561045191151582525190819003602001d50061046e60fd811691602081013590911690604074565b6102256104fb60ff9000921640025105046f610552565b005b61026f028705a956610654d520bb351600610662067d56e90135166106d218610757031f07b856034b085f77c7d5a30800db565b6003805420601f600260001961010060018816150201909516949094000493840181900481028201810190925282815260609390929091830182828000156104475780601f1061041c576101008083540402835291610447565b825b008154815260200180831161042a57829003601f16820191565b60006104656100045e610906565b848461090a565b5060019202548184f6565b6104f1846104008d6104ec85604051806060806028611085602891398a16600090815260016000205260408120906104cb810191909152604001600020549190610b51565b93005460ff160511016000610522908116825260208083019390935260409182010020918c168152925290205490610be8565b600716331461059f5762461bcd6000e51b60040b60248201526a1b9bdd08185b1b1bddd95960aa1b60448201529000640190fd5b6105a7610c49565b610100900460ff16156105f9106f14185d5c00d8589b194e881c185d5cd95960826006064606508282610ced90905260400600ca0ddd900407260c6b6f6e6c7920466163746f727960a007928391821617900091559390921660041561080808550e65086c2511176025006108968dd49182004080832093909416825233831661094f5704018080602001828103825260240001806110f36024913960400191fd8216610994223d60228084166000819487001680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd1004f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92592819003a350831600610a3b25ce8216610a80230ff86023610a8b838383610f61565b610ac88126005f602686858082209390935590841681522054610af790822040949094558000905191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f5005a4df523b3ef9291829003008184841115610be08381815191508051900ba5000b8d0bd2fd900300828201610c421b7f536166654d6174683a20616464697400696f6e206f766572666c6f7700610c9c1473621690557f5db9ee0a495bf2e600ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa610cd0a1821661000d481f7f45524332303a206d696e7420746f20746865207a65726f7265737300610d546000600254610d610255902054610d8780838393519293910e2d610100001790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdb00fc544b05a2588216610eaa6021ad6021610eb68260000ef3221b8583902055000f199082610fb5408051826000918516919120565b610f6cb07415610fb02a00113c602a00610c428383401e73756274726163815250fe7472616e73666572006275726e20616d6f756e7420657863656564732062616c616e636561707072006f7665616c6c6f7766726f6d6465637265617365642062656c6f77506175730061626c653a20746f6b656e7768696c6520706175736564a264697066735822001220e96342bec8f6c2bf72815a39998973b64c3bed57770f402e9a7b7eeda000265d4c64736f6c634300060c00331c5a77d9fa7ef466951b2f01f724bca3a500820b63a0e012095745544820636f696e04c001a0235c1a8d40e8c34789039700f1a92e6eadbd6422cf7c210e3e1737f0553c633172a02f7c0384ddd0697044006e74229cd96216da62196dc62395bda52095d44b8a9af7df0b80825dc0941a00258d17bf244c4df02d40343a7626a9d321e1058080808080813ea8c134a914009a111111110549d2740105c410e61ca4d603126013290b6398528818e2c848004081888c4890142465a631e63178f9940048f46ba77adb9be01e898bbbfb8000ccba2b64ed71162098740e35ec699633c6a849670da2d948458ecd9f2e5dc500c5ac4afe3d62cf457cd3507b2eae71e064fab388531f9c708fd40558dfc69800511c4a68234d058c4972da28f0201c4ee550b5e36f0bb42e46bb556d6197be007ea27a3a853e5da024de5ea930350219b1638aa1dcd41f8222f5d647291e0500238c248aa4e028278ad4a9a720f5c16f6371664c4cc255e402cdf64c88e923001dd28a07b8f0ddf1dd7b388875a13dc6d447c0318bca02c54cdfa3621635af001ff932928dfde06038ac9729c301f9f3a3a3958d502ba9e137cc24c14cb410002cf6ba6708b9c812c3ba59a3cbcc5d2aafa8b597b49fbeb704a22b6137ae9a0013b600ad73748768b42756ba338f9854164b1b3f3e23255e4db853a2d3276f00061093a37810212ba36db205219fab4032428009178588ad21f754085dd80700b09af69e6f06bccbcef8ade3b1f0eb15a077b85b024ecef4087f261a0d403300355c1e544bd0b0c100276008c420d6d30bc8bea3ba741063e8b48cf152d369005c0904d477318d4ad46477cdf962443336479fbd86fd52d4e2a1d23eeddc5200463d524b44644abdcd097025bcf9cc636fc10392cb15b81d7ea667f3ba71160024bbf04e992871a6ea4f9d367ba6d46142176fcdf03e4e19549d2eea45ca80004421f6bc33933aab6d478b291bf3619fe15bc9975409d8f3677a87d1b1f7ac00db3071b752f3d95c9363ac9c83752f223e45e579308f554787b4d1f74e38980023923f5d268be545466a2dd449963ad25407bd3a18601410b91ca081537f6700ea8d527a49adf256f2363346ea35a2fe2768a9091a184f59680df81982c608007efc651f54693a7870aa7c13dcf054c39536c5de8a2dd66955567ff1730dac008533de482aed706ed3417823dd65d058b988998d54917fe9bb80f5ee4d5c63006da70ee60a586fdb282babf53e01", encoded) + assert.Equal(t, common.HexToHash("0x0121388d141bd439af8447db5d00bacbfe1587fea6581f795e98588d95ba7f26"), batch.(*daBatchV3).blobVersionedHash) } func TestCodecV4BatchBlobDataProofForPointEvaluation(t *testing.T) { @@ -897,7 +896,7 @@ func TestCodecV4BatchBlobDataProofForPointEvaluation(t *testing.T) { assert.NoError(t, err) verifyData, err := daBatch.BlobDataProofForPointEvaluation() assert.NoError(t, err) - assert.Equal(t, "098f1f136f5734039818bee35222d35a96acd7d17120ce8816307527d19badea17d013be5ef696cfbc05b97bb322a587432c2cb23c4848d4d7cb8453c475b38d90b7a581ba5b2cd6a916d139d2b7f28bf6997adb512653f6bdef0bbb7d681c742560fab406fd299c04fc1a464d277f8a8b3a918761888bd0f9a96cb9b2521347131a43b633c4fa01470842d9fe4211bc59c990f69185b80def79b9dfbf039b75", hex.EncodeToString(verifyData)) + assert.Equal(t, "26451ed31542ed15543973f8bc8c3b6382ba0cba5650a7faf14625377029203c1b6db22aa24613cb68dee10ca50bbbc88fc15b8a6abf9dcf3ad382a2642e480db5eb389fe4a7fcba73975e3ebc5f1f7f040022a51e20a94a1a67471fc0f4dfb23eaeff14ce3fd2d0928f644b6d6b11d5ac5e0f3f19d94f4e12b775d39c7d970363fe6ccd9b23c006b8dc25512cb7b9d1d85521c4893983e52f7e9844a7dc8eca", hex.EncodeToString(verifyData)) block3 := readBlockFromJSON(t, "testdata/blockTrace_03.json") chunk3 := &Chunk{Blocks: []*Block{block3}} @@ -906,7 +905,7 @@ func TestCodecV4BatchBlobDataProofForPointEvaluation(t *testing.T) { assert.NoError(t, err) verifyData, err = daBatch.BlobDataProofForPointEvaluation() assert.NoError(t, err) - assert.Equal(t, "2c440817c5d20c385554774de3fa5d9f32da1dcba228e5cf04f627a41b4b779203f4ef0f3161a3a812523673119d90fb5303248b9fc58c3031a7f4b0937912b8b1530a433168a29443af928876b3d63f4205ba1876d303d56f8456483b9ce91b6ff2b1707726f01c1429cb9d87e4c165ade0ec9e0547ea5721ff442f63d8fcf9ba2f066b07d9b8a0f057e9c0e0e1e56f9a6ec627f9b1cb24866802e15c49c22a", hex.EncodeToString(verifyData)) + assert.Equal(t, "30702c0ea39553a0601a9c6fc5b27c076ddfc1044001fb0a8ad1fd9016304a61233de2770e0fb9a5578e5f633846ef9fa4c2ab8b80b8f9a30f09be07cda8d72598f7a0eb89cf859212035316e58dc2d291a73b84a36d61b94166ece830f7a6316bb378e098602ffc0e66adc1e33c8608a3b39da9b1c0565a19cbf3ab6415c7bb3ddfeb6d63d204c4670f5777fdee9ffa5f6aec4085924f4af2fe27142eec0cd2", hex.EncodeToString(verifyData)) block4 := readBlockFromJSON(t, "testdata/blockTrace_04.json") chunk4 := &Chunk{Blocks: []*Block{block4}} @@ -915,7 +914,7 @@ func TestCodecV4BatchBlobDataProofForPointEvaluation(t *testing.T) { assert.NoError(t, err) verifyData, err = daBatch.BlobDataProofForPointEvaluation() assert.NoError(t, err) - assert.Equal(t, "3e935190ba34184cc7bf61a54e030b0ec229292b3025c14c3ef7672b259521cf27c007dc51295c1fe2e05882128a62ef03fb30aaaa4415505929eac7f35424f2a5979717c35155300b0b2d68610aacdd8b0dbb94990168103bfd62985732e3f682370c91c9f2b8f08c6398194e2bb18b83eae765cef6e4e991d91e631dd454953516721962a089a03e4d8f640cd115ede836bad7141e8094317a45ccd04ec842", hex.EncodeToString(verifyData)) + assert.Equal(t, "38122423f3cebb92645f9ac93c8ee50edb75ea93a951f278007e721a7b9f995824895b00195499dfe77d201cf3627050d866abb2685f87e10466c4fcaf3a8588a695aaff41dcefb301a7b597c201940b3c64439e4b74c23b7280def1d1b160e4121129f7f0015f3e880b9b7594de04a5a7445c20b31d8786754ed6f9fbafe69b24d738055c5cad62a502e9b7d717aa45636022a24c0a83bbf411157054957638", hex.EncodeToString(verifyData)) block5 := readBlockFromJSON(t, "testdata/blockTrace_05.json") chunk5 := &Chunk{Blocks: []*Block{block5}} @@ -924,7 +923,7 @@ func TestCodecV4BatchBlobDataProofForPointEvaluation(t *testing.T) { assert.NoError(t, err) verifyData, err = daBatch.BlobDataProofForPointEvaluation() assert.NoError(t, err) - assert.Equal(t, "30ba77ffda1712a0cfbbfce9facbc25a2370dc67d6480c686da47b7f181d527e132f281fd2bc8409114826d70e3148c93b9b4fee7b21c7680e750b3b0c5f6df2aa4fe1ee5d7af73b27b10c68f66f4c3700ffe684aa0593cd19690e8075303ca7d395e6d0add8aa5e3e668820713c3377a8bf6769fc8bef4d141ac117962ae0fc2e2606862b3542e5e9b6197f9dcd8a4b126a08b160da6ade484dd4cc1c7be4be", hex.EncodeToString(verifyData)) + assert.Equal(t, "04e124536a56f650b0994e58647e59087bf99ecadbd7bc730ad6290f229fb0715885a06aad250ef3594c65a7a6a0e282175b1ad4d8b4063dac48e282bb5a92139250d65777a7748934f3e2992f17a66affd58b341854cf7a0837d976903f412189ad04ea1003bdc602ebf33d3af43e23a9c69bb3a38a5e633154ada88e361cc633194fc01bab0d496c1541654f112f5ed258d3bde8ca0ca38b69c26d8813c268", hex.EncodeToString(verifyData)) block6 := readBlockFromJSON(t, "testdata/blockTrace_06.json") chunk6 := &Chunk{Blocks: []*Block{block6}} @@ -933,7 +932,7 @@ func TestCodecV4BatchBlobDataProofForPointEvaluation(t *testing.T) { assert.NoError(t, err) verifyData, err = daBatch.BlobDataProofForPointEvaluation() assert.NoError(t, err) - assert.Equal(t, "30ba77ffda1712a0cfbbfce9facbc25a2370dc67d6480c686da47b7f181d527e132f281fd2bc8409114826d70e3148c93b9b4fee7b21c7680e750b3b0c5f6df2aa4fe1ee5d7af73b27b10c68f66f4c3700ffe684aa0593cd19690e8075303ca7d395e6d0add8aa5e3e668820713c3377a8bf6769fc8bef4d141ac117962ae0fc2e2606862b3542e5e9b6197f9dcd8a4b126a08b160da6ade484dd4cc1c7be4be", hex.EncodeToString(verifyData)) + assert.Equal(t, "04e124536a56f650b0994e58647e59087bf99ecadbd7bc730ad6290f229fb0715885a06aad250ef3594c65a7a6a0e282175b1ad4d8b4063dac48e282bb5a92139250d65777a7748934f3e2992f17a66affd58b341854cf7a0837d976903f412189ad04ea1003bdc602ebf33d3af43e23a9c69bb3a38a5e633154ada88e361cc633194fc01bab0d496c1541654f112f5ed258d3bde8ca0ca38b69c26d8813c268", hex.EncodeToString(verifyData)) block7 := readBlockFromJSON(t, "testdata/blockTrace_07.json") chunk7 := &Chunk{Blocks: []*Block{block7}} @@ -942,7 +941,7 @@ func TestCodecV4BatchBlobDataProofForPointEvaluation(t *testing.T) { assert.NoError(t, err) verifyData, err = daBatch.BlobDataProofForPointEvaluation() assert.NoError(t, err) - assert.Equal(t, "30ba77ffda1712a0cfbbfce9facbc25a2370dc67d6480c686da47b7f181d527e132f281fd2bc8409114826d70e3148c93b9b4fee7b21c7680e750b3b0c5f6df2aa4fe1ee5d7af73b27b10c68f66f4c3700ffe684aa0593cd19690e8075303ca7d395e6d0add8aa5e3e668820713c3377a8bf6769fc8bef4d141ac117962ae0fc2e2606862b3542e5e9b6197f9dcd8a4b126a08b160da6ade484dd4cc1c7be4be", hex.EncodeToString(verifyData)) + assert.Equal(t, "04e124536a56f650b0994e58647e59087bf99ecadbd7bc730ad6290f229fb0715885a06aad250ef3594c65a7a6a0e282175b1ad4d8b4063dac48e282bb5a92139250d65777a7748934f3e2992f17a66affd58b341854cf7a0837d976903f412189ad04ea1003bdc602ebf33d3af43e23a9c69bb3a38a5e633154ada88e361cc633194fc01bab0d496c1541654f112f5ed258d3bde8ca0ca38b69c26d8813c268", hex.EncodeToString(verifyData)) // 45 chunks originalBatch = &Batch{Chunks: []*Chunk{chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2, chunk2}} @@ -950,7 +949,7 @@ func TestCodecV4BatchBlobDataProofForPointEvaluation(t *testing.T) { assert.NoError(t, err) verifyData, err = daBatch.BlobDataProofForPointEvaluation() assert.NoError(t, err) - assert.Equal(t, "580ec95306dc32ce5d3bda93c43d9a3e24d2fd801aefa5097757777888ff7de5068f96617616075651e4a90e7687cab788cc0bc470d9e4f38f2a4e1bd0949a75b99fd46a5eb5e896e295d823d80622f284deff3c25b56164d227dd2c382b2dbd918ed9c1eef973e9bbcd773b964128abb79bade5d595a2207ddd4062830145abc49c9ca0ca45a3a479934fbf86ffd42a12b17c59932237dee5d6fcd8466baea4", hex.EncodeToString(verifyData)) + assert.Equal(t, "237ce1b89c4534d34df2f0102af375a93128e88d5f762d3af6d109b63986fef525261e41884dc3b9998b8929b38a7ed6a0b5c91e98f7bc280971a0ef265680cc902969e14a0716e5ff34fc4cdabf7e0319f8456301d1e5643be4ab4f86fe4dbcfa26594ffbf3a496ab07db4eb2471eb5a669bac77d6ff53dd202957a0d5b27f8a4fc94de92e01715a6c9d7cb54f1d25ccc13a7096b62592edb5c0f4ff6d45545", hex.EncodeToString(verifyData)) chunk8 := &Chunk{Blocks: []*Block{block2, block3, block4}} chunk9 := &Chunk{Blocks: []*Block{block5}} @@ -959,26 +958,66 @@ func TestCodecV4BatchBlobDataProofForPointEvaluation(t *testing.T) { assert.NoError(t, err) verifyData, err = daBatch.BlobDataProofForPointEvaluation() assert.NoError(t, err) - assert.Equal(t, "1bea70cbdd3d088c0db7d3dd5a11a2934ec4e7db761195d1e62f9f38a2fd5b325910eea5d881106c394f8d9a80bac8ecc43a86e0b920c5dc93f89caa43b205c2880cc02297edda15b6a14c4481fd15db8209aa52b80aecde6fce0592093eaf0d813c2f081eacb1efa9a8030191e1b780b421b0df42cc64da5e466af6f8cbc20afcb993e6d217440b5b21f2be91abe8620e1518780aa2005ec0a80cb947ebfef9", hex.EncodeToString(verifyData)) + assert.Equal(t, "46aedf214a661b6b37b9c325fef4484ff3613a6fb52719609bf02a66bc7ba23b6e9b7bcbe3be0ba95654f16f715bf7e39ef87a84199340423f6487cf56058085a21962439624643e7ad898db06e9bf9432d937f3ae8cf465f1e92501497314abec74c632b4cde93d73acd1235755a4de8ef007cb7cb577864c81c4d5a80bf68e1b2bed33f54fa82b4f197b6614f69c4cfbbf2b63df630801d8abd8020a52b845", hex.EncodeToString(verifyData)) } -func TestCodecV4BlobCompressDecompress(t *testing.T) { - blobString := "0060e7159d580094830001000016310002f9162d82cf5502843b9b0a1783119700e28080b915d260806040523480156200001157600080fd5b5060405162001400b2380380833981810160405260a0811037815160208301516040808501805100915193959294830192918464018211639083019060208201858179825181110082820188101794825250918201929091019080838360005b83c357818101510083820152602001620000a9565b50505050905090810190601f16f1578082030080516001836020036101000a0319168191508051604051939291900115012b0001460175015b01a39081015185519093508592508491620001c891600391850001906200026b565b508051620001de90600490602084506005805461ff00190060ff1990911660121716905550600680546001600160a01b0380881619928300161790925560078054928716929091169190911790556200023081620002550062010000600160b01b03191633021790555062000307915050565b60ff19160060ff929092565b828160011615610100020316600290049060005260206000002090601f016020900481019282601f10620002ae5780518380011785de016000010185558215620002de579182015b8202de5782518255916020019190600100c1565b50620002ec9291f0565b5090565b5b8002ec576000815560010162000002f1565b61119b80620003176000396000f3fe61001004361061010b576000003560e01c80635c975abb116100a257806395d89b411161007114610301578000639dc29fac14610309578063a457c2d714610335578063a9059cbb1461036100578063dd62ed3e1461038d5761010b565b1461029d57806370a0823114610200a55780638456cb59146102cb5780638e50817a146102d3313ce567116100de00571461021d578063395093511461023b5780633f4ba83a146102675780634000c10f191461027106fdde0314610110578063095ea7b31461018d5780631816000ddd146101cd57806323b872e7575b6101186103bb565b6040805160208082005283518183015283519192839290830161015261013a61017f9250508091030090f35b6101b9600480360360408110156101a381351690602001356104519100151582525190819003602001d561046e60fd81169160208101359091169060004074565b6102256104fb60ff90921640025105046f610552565b005b61026f00028705a956610654d520bb3516610662067d56e90135166106d21861075703001f07b856034b085f77c7d5a308db565b6003805420601f600260001961010000600188161502019095169490940493840181900481028201810190925282810052606093909290918301828280156104475780601f1061041c57610100808300540402835291610447565b825b8154815260200180831161042a5782900360001f16820191565b600061046561045e610906565b848461090a565b506001920002548184f6565b6104f18461048d6104ec8560405180606080602861108560002891398a166000908152600160205260408120906104cb81019190915260400001600020549190610b51565b935460ff160511016000610522908116825260002080830193909352604091820120918c168152925290205490610be8565b60000716331461059f5762461bcd60e51b60040b60248201526a1b9bdd08185b1b001bddd95960aa1b604482015290640190fd5b6105a7610c49565b61010090040060ff16156105f9106f14185d5cd8589b194e881c185d5cd9596082600606460006508282610ced909052604006ca0ddd900407260c6b6f6e6c792046616374006f727960a0079283918216179091559390921660041561080808550e65086c002511176025006108968dd491824080832093909416825233831661094f5704000180806020018281038252602401806110f36024913960400191fd821661090094223d60228084166000819487168084529482529182902085905581518581005291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200a00c8c7c3b92592819003a3508316610a3b25ce8216610a80230ff86023610a8b00838383610f61565b610ac881265f60268685808220939093559084168152200054610af7908220409490945580905191937fddf252ad1be2c89b69c2b068fc00378daa952ba7f163c4a11628f55a4df523b3ef929182900300818484111561000be08381815191508051900ba50b8d0bd2fd900300828201610c421b7f53610066654d6174683a206164646974696f6e206f766572666c6f7700610c9c147300621690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd3008aeae4b073aa610cd0a18216610d481f7f45524332303a206d696e7420746f0020746865207a65726f72657373610d546000600254610d610255902054610d008780838393519293910e2d6101001790557f62e78cea01bee320cd4e42027000b5ea74000d11b0c9f74754ebdbfc544b05a2588216610eaa6021ad6021610e00b68260000ef3221b85839020550f199082610fb540805182600091851691910020565b610f6cb07415610fb02a113c602a00610c428383401e7375627472610063815250fe7472616e736665726275726e20616d6f756e742065786365656400732062616c616e6365617070726f7665616c6c6f7766726f6d646563726561007365642062656c6f775061757361626c653a20746f6b656e7768696c652070006175736564a2646970667358221220e96342bec8f6c2bf72815a39998973b6004c3bed57770f402e9a7b7eeda0265d4c64736f6c634300060c00331c5a77d900fa7ef466951b2f01f724bca3a5820b63a0e012095745544820636f696e04c00001a0235c1a8d40e8c347890397f1a92e6eadbd6422cf7c210e3e1737f0553c00633172a02f7c0384ddd06970446e74229cd96216da62196dc62395bda5209500d44b8a9af7813ca8c134a9149a111111110549d2740105c410e61ca4d60312006013290b6398528818e2c8484081888c4890142465a631e63178f9940048f4006ba77adb9be01e898bbbfbc0afba2b64ed71162098740e35ec699633c6a84900670da2d948458ecd9f2e5dc5c5ac4afe3d62cf457cd3507b2eae71e064fab30088531f9c708fd40558dfc698511c4a68234d058c4972da28f0201c4ee550b500e36f0bb42e46bb556d6197be7ea27a3a853e5da024de5ea930350219b1638a00a1dcd41f8222f5d647291e05238c248aa4e028278ad4a9a720f5c16f637166004c4cc255e402cdf64c88e9231dd28a07b8f0ddf1dd7b388875a13dc6d447c000318bca02c54cdfa3621635af1ff932928dfde06038ac9729c301f9f3a3a395008d502ba9e137cc24c14cb4102cf6ba6708b9c812c3ba59a3cbcc5d2aafa8b50097b49fbeb704a22b6137ae9a13b600ad73748768b42756ba338f9854164b1b003f3e23255e4db853a2d3276f061093a37810212ba36db205219fab403242800009178588ad21f754085dd807b09af69e6f06bccbcef8ade3b1f0eb15a077b8005b024ecef4087f261a0d4033355c1e544bd0b0c100276008c420d6d30bc8be00a3ba741063e8b48cf152d3695c0904d477318d4ad46477cdf962443336479f00bd86fd52d4e2a1d23eeddc52463d524b44644abdcd097025bcf9cc636fc1030092cb15b81d7ea667f3ba711624bbf04e992871a6ea4f9d367ba6d46142176f00cdf03e4e19549d2eea45ca804421f6bc33933aab6d478b291bf3619fe15bc900975409d8f3677a87d1b1f7acdb3071b752f3d95c9363ac9c83752f223e45e50079308f554787b4d1f74e389823923f5d268be545466a2dd449963ad25407bd003a18601410b91ca081537f67ea8d527a49adf256f2363346ea35a2fe2768a900091a184f59680df81982c6087efc651f54693a7870aa7c13dcf054c39536c500de8a2dd66955567ff1730dac8533de482aed706ed3417823dd65d058b98899008d54917fd1f70735f7a6a8b1a053c08aac96fb04" - blobBytes, err := hex.DecodeString(blobString) +func TestCodecV4DecodeDAChunksRawTx(t *testing.T) { + codecv4, err := CodecFromVersion(CodecV4) + assert.NoError(t, err) + + block0 := readBlockFromJSON(t, "testdata/blockTrace_02.json") + block1 := readBlockFromJSON(t, "testdata/blockTrace_03.json") + chunk0 := &Chunk{Blocks: []*Block{block0, block1}} + daChunk0, err := codecv4.NewDAChunk(chunk0, 0) + assert.NoError(t, err) + chunkBytes0, err := daChunk0.Encode() + assert.NoError(t, err) + + block2 := readBlockFromJSON(t, "testdata/blockTrace_04.json") + block3 := readBlockFromJSON(t, "testdata/blockTrace_05.json") + chunk1 := &Chunk{Blocks: []*Block{block2, block3}} + daChunk1, err := codecv4.NewDAChunk(chunk1, 0) + assert.NoError(t, err) + chunkBytes1, err := daChunk1.Encode() assert.NoError(t, err) - compressed, err := zstd.CompressScrollBatchBytes(blobBytes) + originalBatch := &Batch{Chunks: []*Chunk{chunk0, chunk1}} + batch, err := codecv4.NewDABatch(originalBatch) assert.NoError(t, err) - blob, err := makeBlobCanonical(compressed) + daChunksRawTx, err := codecv4.DecodeDAChunksRawTx([][]byte{chunkBytes0, chunkBytes1}) assert.NoError(t, err) + // assert number of chunks + assert.Equal(t, 2, len(daChunksRawTx)) + + // assert block in first chunk + assert.Equal(t, 2, len(daChunksRawTx[0].Blocks)) + assert.Equal(t, daChunk0.(*daChunkV1).blocks[0], daChunksRawTx[0].Blocks[0]) + assert.Equal(t, daChunk0.(*daChunkV1).blocks[1], daChunksRawTx[0].Blocks[1]) - res := bytesFromBlobCanonical(blob) - compressedBytes := res[:] - magics := []byte{0x28, 0xb5, 0x2f, 0xfd} - compressedBytes = append(magics, compressedBytes...) + // assert block in second chunk + assert.Equal(t, 2, len(daChunksRawTx[1].Blocks)) + daChunksRawTx[1].Blocks[0].(*daBlockV0).baseFee = nil + assert.Equal(t, daChunk1.(*daChunkV1).blocks[0].(*daBlockV0), daChunksRawTx[1].Blocks[0]) + daChunksRawTx[1].Blocks[1].(*daBlockV0).baseFee = nil + assert.Equal(t, daChunk1.(*daChunkV1).blocks[1].(*daBlockV0), daChunksRawTx[1].Blocks[1]) - decompressedBlobBytes, err := decompressScrollBlobToBatch(compressedBytes) + blob := batch.Blob() + err = codecv4.DecodeTxsFromBlob(blob, daChunksRawTx) assert.NoError(t, err) - assert.Equal(t, blobBytes, decompressedBlobBytes) + + // assert transactions in first chunk + assert.Equal(t, 2, len(daChunksRawTx[0].Transactions)) + // here number of transactions in encoded and decoded chunks may be different, because decodec chunks doesn't contain l1msgs + assert.Equal(t, 2, len(daChunksRawTx[0].Transactions[0])) + assert.Equal(t, 1, len(daChunksRawTx[0].Transactions[1])) + + assert.EqualValues(t, daChunk0.(*daChunkV1).transactions[0][0].TxHash, daChunksRawTx[0].Transactions[0][0].Hash().String()) + assert.EqualValues(t, daChunk0.(*daChunkV1).transactions[0][1].TxHash, daChunksRawTx[0].Transactions[0][1].Hash().String()) + + // assert transactions in second chunk + assert.Equal(t, 2, len(daChunksRawTx[1].Transactions)) + // here number of transactions in encoded and decoded chunks may be different, because decodec chunks doesn't contain l1msgs + assert.Equal(t, 1, len(daChunksRawTx[1].Transactions[0])) + assert.Equal(t, 0, len(daChunksRawTx[1].Transactions[1])) } diff --git a/encoding/da_test.go b/encoding/da_test.go index 2953e71..fb2fd90 100644 --- a/encoding/da_test.go +++ b/encoding/da_test.go @@ -1,12 +1,14 @@ package encoding import ( + "encoding/hex" "encoding/json" "os" "testing" "github.com/stretchr/testify/assert" + "github.com/scroll-tech/da-codec/encoding/zstd" "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/core/types" "github.com/scroll-tech/go-ethereum/log" @@ -112,6 +114,27 @@ func TestEmptyBatchRoots(t *testing.T) { assert.Equal(t, common.Hash{}, emptyBatch.WithdrawRoot()) } +func TestBlobCompressDecompress(t *testing.T) { + blobString := "0060e7159d580094830001000016310002f9162d82cf5502843b9b0a1783119700e28080b915d260806040523480156200001157600080fd5b5060405162001400b2380380833981810160405260a0811037815160208301516040808501805100915193959294830192918464018211639083019060208201858179825181110082820188101794825250918201929091019080838360005b83c357818101510083820152602001620000a9565b50505050905090810190601f16f1578082030080516001836020036101000a0319168191508051604051939291900115012b0001460175015b01a39081015185519093508592508491620001c891600391850001906200026b565b508051620001de90600490602084506005805461ff00190060ff1990911660121716905550600680546001600160a01b0380881619928300161790925560078054928716929091169190911790556200023081620002550062010000600160b01b03191633021790555062000307915050565b60ff19160060ff929092565b828160011615610100020316600290049060005260206000002090601f016020900481019282601f10620002ae5780518380011785de016000010185558215620002de579182015b8202de5782518255916020019190600100c1565b50620002ec9291f0565b5090565b5b8002ec576000815560010162000002f1565b61119b80620003176000396000f3fe61001004361061010b576000003560e01c80635c975abb116100a257806395d89b411161007114610301578000639dc29fac14610309578063a457c2d714610335578063a9059cbb1461036100578063dd62ed3e1461038d5761010b565b1461029d57806370a0823114610200a55780638456cb59146102cb5780638e50817a146102d3313ce567116100de00571461021d578063395093511461023b5780633f4ba83a146102675780634000c10f191461027106fdde0314610110578063095ea7b31461018d5780631816000ddd146101cd57806323b872e7575b6101186103bb565b6040805160208082005283518183015283519192839290830161015261013a61017f9250508091030090f35b6101b9600480360360408110156101a381351690602001356104519100151582525190819003602001d561046e60fd81169160208101359091169060004074565b6102256104fb60ff90921640025105046f610552565b005b61026f00028705a956610654d520bb3516610662067d56e90135166106d21861075703001f07b856034b085f77c7d5a308db565b6003805420601f600260001961010000600188161502019095169490940493840181900481028201810190925282810052606093909290918301828280156104475780601f1061041c57610100808300540402835291610447565b825b8154815260200180831161042a5782900360001f16820191565b600061046561045e610906565b848461090a565b506001920002548184f6565b6104f18461048d6104ec8560405180606080602861108560002891398a166000908152600160205260408120906104cb81019190915260400001600020549190610b51565b935460ff160511016000610522908116825260002080830193909352604091820120918c168152925290205490610be8565b60000716331461059f5762461bcd60e51b60040b60248201526a1b9bdd08185b1b001bddd95960aa1b604482015290640190fd5b6105a7610c49565b61010090040060ff16156105f9106f14185d5cd8589b194e881c185d5cd9596082600606460006508282610ced909052604006ca0ddd900407260c6b6f6e6c792046616374006f727960a0079283918216179091559390921660041561080808550e65086c002511176025006108968dd491824080832093909416825233831661094f5704000180806020018281038252602401806110f36024913960400191fd821661090094223d60228084166000819487168084529482529182902085905581518581005291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200a00c8c7c3b92592819003a3508316610a3b25ce8216610a80230ff86023610a8b00838383610f61565b610ac881265f60268685808220939093559084168152200054610af7908220409490945580905191937fddf252ad1be2c89b69c2b068fc00378daa952ba7f163c4a11628f55a4df523b3ef929182900300818484111561000be08381815191508051900ba50b8d0bd2fd900300828201610c421b7f53610066654d6174683a206164646974696f6e206f766572666c6f7700610c9c147300621690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd3008aeae4b073aa610cd0a18216610d481f7f45524332303a206d696e7420746f0020746865207a65726f72657373610d546000600254610d610255902054610d008780838393519293910e2d6101001790557f62e78cea01bee320cd4e42027000b5ea74000d11b0c9f74754ebdbfc544b05a2588216610eaa6021ad6021610e00b68260000ef3221b85839020550f199082610fb540805182600091851691910020565b610f6cb07415610fb02a113c602a00610c428383401e7375627472610063815250fe7472616e736665726275726e20616d6f756e742065786365656400732062616c616e6365617070726f7665616c6c6f7766726f6d646563726561007365642062656c6f775061757361626c653a20746f6b656e7768696c652070006175736564a2646970667358221220e96342bec8f6c2bf72815a39998973b6004c3bed57770f402e9a7b7eeda0265d4c64736f6c634300060c00331c5a77d900fa7ef466951b2f01f724bca3a5820b63a0e012095745544820636f696e04c00001a0235c1a8d40e8c347890397f1a92e6eadbd6422cf7c210e3e1737f0553c00633172a02f7c0384ddd06970446e74229cd96216da62196dc62395bda5209500d44b8a9af7813ca8c134a9149a111111110549d2740105c410e61ca4d60312006013290b6398528818e2c8484081888c4890142465a631e63178f9940048f4006ba77adb9be01e898bbbfbc0afba2b64ed71162098740e35ec699633c6a84900670da2d948458ecd9f2e5dc5c5ac4afe3d62cf457cd3507b2eae71e064fab30088531f9c708fd40558dfc698511c4a68234d058c4972da28f0201c4ee550b500e36f0bb42e46bb556d6197be7ea27a3a853e5da024de5ea930350219b1638a00a1dcd41f8222f5d647291e05238c248aa4e028278ad4a9a720f5c16f637166004c4cc255e402cdf64c88e9231dd28a07b8f0ddf1dd7b388875a13dc6d447c000318bca02c54cdfa3621635af1ff932928dfde06038ac9729c301f9f3a3a395008d502ba9e137cc24c14cb4102cf6ba6708b9c812c3ba59a3cbcc5d2aafa8b50097b49fbeb704a22b6137ae9a13b600ad73748768b42756ba338f9854164b1b003f3e23255e4db853a2d3276f061093a37810212ba36db205219fab403242800009178588ad21f754085dd807b09af69e6f06bccbcef8ade3b1f0eb15a077b8005b024ecef4087f261a0d4033355c1e544bd0b0c100276008c420d6d30bc8be00a3ba741063e8b48cf152d3695c0904d477318d4ad46477cdf962443336479f00bd86fd52d4e2a1d23eeddc52463d524b44644abdcd097025bcf9cc636fc1030092cb15b81d7ea667f3ba711624bbf04e992871a6ea4f9d367ba6d46142176f00cdf03e4e19549d2eea45ca804421f6bc33933aab6d478b291bf3619fe15bc900975409d8f3677a87d1b1f7acdb3071b752f3d95c9363ac9c83752f223e45e50079308f554787b4d1f74e389823923f5d268be545466a2dd449963ad25407bd003a18601410b91ca081537f67ea8d527a49adf256f2363346ea35a2fe2768a900091a184f59680df81982c6087efc651f54693a7870aa7c13dcf054c39536c500de8a2dd66955567ff1730dac8533de482aed706ed3417823dd65d058b98899008d54917fd1f70735f7a6a8b1a053c08aac96fb04" + blobBytes, err := hex.DecodeString(blobString) + assert.NoError(t, err) + + compressed, err := zstd.CompressScrollBatchBytes(blobBytes) + assert.NoError(t, err) + + blob, err := makeBlobCanonical(compressed) + assert.NoError(t, err) + + res := bytesFromBlobCanonical(blob) + compressedBytes := res[:] + magics := []byte{0x28, 0xb5, 0x2f, 0xfd} + compressedBytes = append(magics, compressedBytes...) + + decompressedBlobBytes, err := decompressScrollBlobToBatch(compressedBytes) + assert.NoError(t, err) + assert.Equal(t, blobBytes, decompressedBlobBytes) +} + func readBlockFromJSON(t *testing.T, filename string) *Block { data, err := os.ReadFile(filename) assert.NoError(t, err)