mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-14 16:37:56 -05:00
Compare commits
4 Commits
develop
...
chunk-info
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
628df733ee | ||
|
|
938f05064c | ||
|
|
28fa44d3b8 | ||
|
|
6b7ca50599 |
@@ -48,6 +48,9 @@ pub unsafe extern "C" fn gen_batch_proof(
|
|||||||
let chunk_proofs = serde_json::from_slice::<Vec<ChunkProof>>(&chunk_proofs).unwrap();
|
let chunk_proofs = serde_json::from_slice::<Vec<ChunkProof>>(&chunk_proofs).unwrap();
|
||||||
assert_eq!(chunk_hashes.len(), chunk_proofs.len());
|
assert_eq!(chunk_hashes.len(), chunk_proofs.len());
|
||||||
|
|
||||||
|
log::error!("gupeng - rust - 1 - chunk_hashes = {chunk_hashes:#?}");
|
||||||
|
log::error!("gupeng - rust - 1 - chunk_proofs = {chunk_proofs:?}");
|
||||||
|
|
||||||
let chunk_hashes_proofs = chunk_hashes
|
let chunk_hashes_proofs = chunk_hashes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(chunk_proofs.into_iter())
|
.zip(chunk_proofs.into_iter())
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/scroll-tech/go-ethereum/core/types"
|
"github.com/scroll-tech/go-ethereum/core/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
scrollTypes "scroll-tech/common/types"
|
|
||||||
"scroll-tech/common/types/message"
|
"scroll-tech/common/types/message"
|
||||||
|
|
||||||
"scroll-tech/prover/config"
|
"scroll-tech/prover/config"
|
||||||
@@ -25,64 +24,12 @@ var (
|
|||||||
proofDumpPath = flag.String("dump", "/assets/proof_data", "the path proofs dump to")
|
proofDumpPath = flag.String("dump", "/assets/proof_data", "the path proofs dump to")
|
||||||
tracePath1 = flag.String("trace1", "/assets/traces/1_transfer.json", "chunk trace 1")
|
tracePath1 = flag.String("trace1", "/assets/traces/1_transfer.json", "chunk trace 1")
|
||||||
tracePath2 = flag.String("trace2", "/assets/traces/10_transfer.json", "chunk trace 2")
|
tracePath2 = flag.String("trace2", "/assets/traces/10_transfer.json", "chunk trace 2")
|
||||||
|
batchDetailPath = flag.String("batch_detail", "/assets/traces/full_proof_3.json", "batch detail")
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFFI(t *testing.T) {
|
func TestFFI(t *testing.T) {
|
||||||
as := assert.New(t)
|
as := assert.New(t)
|
||||||
|
|
||||||
chunkProverConfig := &config.ProverCoreConfig{
|
|
||||||
DumpDir: *proofDumpPath,
|
|
||||||
ParamsPath: *paramsPath,
|
|
||||||
ProofType: message.ProofTypeChunk,
|
|
||||||
}
|
|
||||||
chunkProverCore, err := core.NewProverCore(chunkProverConfig)
|
|
||||||
as.NoError(err)
|
|
||||||
t.Log("Constructed chunk prover")
|
|
||||||
|
|
||||||
chunkTrace1 := readChunkTrace(*tracePath1, as)
|
|
||||||
chunkTrace2 := readChunkTrace(*tracePath2, as)
|
|
||||||
t.Log("Loaded chunk traces")
|
|
||||||
|
|
||||||
chunkInfo1, err := chunkProverCore.TracesToChunkInfo(chunkTrace1)
|
|
||||||
as.NoError(err)
|
|
||||||
chunkInfo2, err := chunkProverCore.TracesToChunkInfo(chunkTrace2)
|
|
||||||
as.NoError(err)
|
|
||||||
t.Log("Converted to chunk infos")
|
|
||||||
|
|
||||||
wrappedBlock1 := &scrollTypes.WrappedBlock{
|
|
||||||
Header: chunkTrace1[0].Header,
|
|
||||||
Transactions: chunkTrace1[0].Transactions,
|
|
||||||
WithdrawRoot: chunkTrace1[0].WithdrawTrieRoot,
|
|
||||||
}
|
|
||||||
chunk1 := &scrollTypes.Chunk{Blocks: []*scrollTypes.WrappedBlock{wrappedBlock1}}
|
|
||||||
chunkHash1, err := chunk1.Hash(0)
|
|
||||||
as.NoError(err)
|
|
||||||
as.Equal(chunkInfo1.PostStateRoot, wrappedBlock1.Header.Root)
|
|
||||||
as.Equal(chunkInfo1.WithdrawRoot, wrappedBlock1.WithdrawRoot)
|
|
||||||
as.Equal(chunkInfo1.DataHash, chunkHash1)
|
|
||||||
t.Log("Successful to check chunk info 1")
|
|
||||||
|
|
||||||
wrappedBlock2 := &scrollTypes.WrappedBlock{
|
|
||||||
Header: chunkTrace2[0].Header,
|
|
||||||
Transactions: chunkTrace2[0].Transactions,
|
|
||||||
WithdrawRoot: chunkTrace2[0].WithdrawTrieRoot,
|
|
||||||
}
|
|
||||||
chunk2 := &scrollTypes.Chunk{Blocks: []*scrollTypes.WrappedBlock{wrappedBlock2}}
|
|
||||||
chunkHash2, err := chunk2.Hash(chunk1.NumL1Messages(0))
|
|
||||||
as.NoError(err)
|
|
||||||
as.Equal(chunkInfo2.PostStateRoot, wrappedBlock2.Header.Root)
|
|
||||||
as.Equal(chunkInfo2.WithdrawRoot, wrappedBlock2.WithdrawRoot)
|
|
||||||
as.Equal(chunkInfo2.DataHash, chunkHash2)
|
|
||||||
t.Log("Successful to check chunk info 2")
|
|
||||||
|
|
||||||
chunkProof1, err := chunkProverCore.ProveChunk("chunk_proof1", chunkTrace1)
|
|
||||||
as.NoError(err)
|
|
||||||
t.Log("Generated and dumped chunk proof 1")
|
|
||||||
|
|
||||||
chunkProof2, err := chunkProverCore.ProveChunk("chunk_proof2", chunkTrace2)
|
|
||||||
as.NoError(err)
|
|
||||||
t.Log("Generated and dumped chunk proof 2")
|
|
||||||
|
|
||||||
batchProverConfig := &config.ProverCoreConfig{
|
batchProverConfig := &config.ProverCoreConfig{
|
||||||
DumpDir: *proofDumpPath,
|
DumpDir: *proofDumpPath,
|
||||||
ParamsPath: *paramsPath,
|
ParamsPath: *paramsPath,
|
||||||
@@ -91,13 +38,27 @@ func TestFFI(t *testing.T) {
|
|||||||
batchProverCore, err := core.NewProverCore(batchProverConfig)
|
batchProverCore, err := core.NewProverCore(batchProverConfig)
|
||||||
as.NoError(err)
|
as.NoError(err)
|
||||||
|
|
||||||
chunkInfos := []*message.ChunkInfo{chunkInfo1, chunkInfo2}
|
// gupeng
|
||||||
chunkProofs := []*message.ChunkProof{chunkProof1, chunkProof2}
|
batchDetail := readBatchDetail(*batchDetailPath, as)
|
||||||
|
chunkInfos := batchDetail.ChunkInfos
|
||||||
|
chunkProofs := batchDetail.ChunkProofs
|
||||||
|
|
||||||
_, err = batchProverCore.ProveBatch("batch_proof", chunkInfos, chunkProofs)
|
_, err = batchProverCore.ProveBatch("batch_proof", chunkInfos, chunkProofs)
|
||||||
as.NoError(err)
|
as.NoError(err)
|
||||||
t.Log("Generated and dumped batch proof")
|
t.Log("Generated and dumped batch proof")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readBatchDetail(filePat string, as *assert.Assertions) *message.BatchTaskDetail {
|
||||||
|
f, err := os.Open(filePat)
|
||||||
|
as.NoError(err)
|
||||||
|
byt, err := io.ReadAll(f)
|
||||||
|
as.NoError(err)
|
||||||
|
|
||||||
|
batchDetail := &message.BatchTaskDetail{}
|
||||||
|
as.NoError(json.Unmarshal(byt, batchDetail))
|
||||||
|
|
||||||
|
return batchDetail
|
||||||
|
}
|
||||||
func readChunkTrace(filePat string, as *assert.Assertions) []*types.BlockTrace {
|
func readChunkTrace(filePat string, as *assert.Assertions) []*types.BlockTrace {
|
||||||
f, err := os.Open(filePat)
|
f, err := os.Open(filePat)
|
||||||
as.NoError(err)
|
as.NoError(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user