Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 630
feat: openvm euclid v2#1613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
feat: openvm euclid v2 #1613
Changes from all commits
41606fe0c0c41778c9963940fde0ca8d930421afe9b460d4a182f8e3783b9655a479c3310abdd2efbbd7e713424f4e17bc99c0a9f8db533969a80d45f229509412c7fc3a3bad2de45f0f01af242bd0655848d3a6e5ad9c6b424cefac17696d503d4abf0843683c73f8d3acd6bf13863e8b57dd637924b0fbc14ac867fda62e9827a01fa3b350ebf17e1a0babbb9d4040125dd6121ce09ed394a6a55de1f89ede0d782e019081d28947a6c23eb5758b7353f30673777f554a233e27ab5a26a49cb8ea431555b32e1d6674e8a1c4562c8b614ff91c99982dd5e04333d51b30f4d003c63a69f4c9ee101cc46a868bc18b08a57f1ea4b3b7e7d1a94bee19f27ddb7da96331d79aaefab7038c47219f295adcc3224546e0799dd47a70e3757d50b720dffe4867307dc9f6e8c9b462e4d57e6b04d677b390d1563d98793138b3239e99a851bb6ee2caf381222cc9f65eacdc787ec6d47893bf18b3c1df7110083cfcbaa672d40f0fc743efd1ea9aca88da493b8c7ec2f28817964368f9be88ef6fe6451bbcc6b0f5cf8cda8db4e5ca6ed3217486236b9843418cf087c9996af60e82c632846ecfad2e94e0fc28cbef9e25fe3b17a086e655587e12355f8bb537d5b77a12a262a5869bfd7d4ff809f480e5459941db4546af3a3db5fcb87c7a4822d388befb842d620ddbab0e4f135073c77d6322cf4104811afeb107d162160877d39b5c42eae212a909790c40bb5314901693a3454c6cc6f02994b21c793ee2d2be3332882fb27ceb3e4667ed05728d0cb8b977dceaeb73acca1bec9648994767b59db735cfb8b601d0e4878a458d83c0a0842bfcb8d82e1092a8330c4c2a7552b318ec886af0790334719bb768ec484925917b1438f4fc9a1572680d1138650df9ede4c4cff080af426c65622b38af170f045984dced0c6File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| use super::{ProofVerifier, TaskType, VKDump}; | ||
| use anyhow::Result; | ||
| use crate::utils::panic_catch; | ||
| use euclid_prover::{BatchProof, BundleProof, ChunkProof}; | ||
| use euclid_verifier::verifier::{BatchVerifier, BundleVerifierEuclidV2, ChunkVerifier}; | ||
| use std::{fs::File, path::Path}; | ||
| pub struct EuclidV2Verifier { | ||
| chunk_verifier: ChunkVerifier, | ||
| batch_verifier: BatchVerifier, | ||
| bundle_verifier: BundleVerifierEuclidV2, | ||
| } | ||
| impl EuclidV2Verifier { | ||
| pub fn new(assets_dir: &str) -> Self { | ||
| let verifier_bin = Path::new(assets_dir).join("verifier.bin"); | ||
| let config = Path::new(assets_dir).join("root-verifier-vm-config"); | ||
| let exe = Path::new(assets_dir).join("root-verifier-committed-exe"); | ||
| Self { | ||
| chunk_verifier: ChunkVerifier::setup(&config, &exe, &verifier_bin) | ||
| .expect("Setting up chunk verifier"), | ||
| batch_verifier: BatchVerifier::setup(&config, &exe, &verifier_bin) | ||
| .expect("Setting up batch verifier"), | ||
| bundle_verifier: BundleVerifierEuclidV2::setup(&config, &exe, &verifier_bin) | ||
| .expect("Setting up bundle verifier"), | ||
| } | ||
| } | ||
| } | ||
| impl ProofVerifier for EuclidV2Verifier { | ||
| fn verify(&self, task_type: super::TaskType, proof: Vec<u8>) -> Result<bool> { | ||
| panic_catch(|| match task_type { | ||
| TaskType::Chunk => { | ||
| let proof = serde_json::from_slice::<ChunkProof>(proof.as_slice()).unwrap(); | ||
| self.chunk_verifier | ||
| .verify_proof(proof.proof.as_root_proof().unwrap()) | ||
| } | ||
| TaskType::Batch => { | ||
| let proof = serde_json::from_slice::<BatchProof>(proof.as_slice()).unwrap(); | ||
| self.batch_verifier | ||
| .verify_proof(proof.proof.as_root_proof().unwrap()) | ||
| } | ||
| TaskType::Bundle => { | ||
| let proof = serde_json::from_slice::<BundleProof>(proof.as_slice()).unwrap(); | ||
| self.bundle_verifier | ||
| .verify_proof_evm(&proof.proof.as_evm_proof().unwrap()) | ||
| } | ||
| }) | ||
| .map_err(|err_str: String| anyhow::anyhow!(err_str)) | ||
| } | ||
| fn dump_vk(&self, file: &Path) { | ||
| let f = File::create(file).expect("Failed to open file to dump VK"); | ||
| let dump = VKDump { | ||
| chunk_vk: base64::encode(self.chunk_verifier.get_app_vk()), | ||
| batch_vk: base64::encode(self.batch_verifier.get_app_vk()), | ||
| bundle_vk: base64::encode(self.bundle_verifier.get_app_vk()), | ||
| }; | ||
| serde_json::to_writer(f, &dump).expect("Failed to dump VK"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,12 +4,18 @@ import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "math/big" | ||
| "github.com/scroll-tech/go-ethereum/common" | ||
| "github.com/scroll-tech/go-ethereum/common/hexutil" | ||
| ) | ||
| const ( | ||
| euclidFork = "euclid" | ||
| EuclidFork = "euclid" | ||
| EuclidV2Fork = "euclidV2" | ||
| EuclidForkNameForProver = "euclidv1" | ||
| EuclidV2ForkNameForProver = "euclidv2" | ||
| ) | ||
| // ProofType represents the type of task. | ||
| @@ -39,38 +45,102 @@ const ( | ||
| ProofTypeBundle | ||
| ) | ||
| // ChunkTaskDetail is a type containing ChunkTask detail. | ||
| // ChunkTaskDetail is a type containing ChunkTask detail for chunk task. | ||
| type ChunkTaskDetail struct { | ||
| BlockHashes []common.Hash `json:"block_hashes"` | ||
| // use one of the string of EuclidFork / EuclidV2Fork | ||
| ForkName string `json:"fork_name"` | ||
| BlockHashes []common.Hash `json:"block_hashes"` | ||
| PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"` | ||
| } | ||
| // it is a hex encoded big with fixed length on 48 bytes | ||
| type Byte48 struct { | ||
| hexutil.Big | ||
| } | ||
| func (e Byte48) MarshalText() ([]byte, error) { | ||
| i := e.ToInt() | ||
| // overrite encode big | ||
| if sign := i.Sign(); sign < 0 { | ||
| // sanity check | ||
| return nil, errors.New("Byte48 must be positive integer") | ||
| } else { | ||
| s := i.Text(16) | ||
| if len(s) > 96 { | ||
| return nil, errors.New("integer Exceed 384bit") | ||
| } | ||
| return []byte(fmt.Sprintf("0x%0*s", 96, s)), nil | ||
| } | ||
| } | ||
| func isString(input []byte) bool { | ||
| return len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' | ||
| } | ||
| // hexutil.Big has limition of 256bit so we have to override it ... | ||
| func (e *Byte48) UnmarshalJSON(input []byte) error { | ||
| if !isString(input) { | ||
| return errors.New("not hex string") | ||
| } | ||
| b, err := hexutil.Decode(string(input[1 : len(input)-1])) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if len(b) != 48 { | ||
| return fmt.Errorf("not a 48 bytes hex string: %d", len(b)) | ||
| } | ||
| var dec big.Int | ||
| dec.SetBytes(b) | ||
| *e = Byte48{(hexutil.Big)(dec)} | ||
| return nil | ||
| } | ||
| // BatchTaskDetail is a type containing BatchTask detail. | ||
| type BatchTaskDetail struct { | ||
| ChunkInfos []*ChunkInfo `json:"chunk_infos"` | ||
| ChunkProofs []ChunkProof `json:"chunk_proofs"` | ||
| BatchHeader interface{} `json:"batch_header"` | ||
| BlobBytes []byte `json:"blob_bytes"` | ||
| KzgProof []byte `json:"kzg_proof"` | ||
| KzgCommitment []byte `json:"kzg_commitment"` | ||
| Challenge common.Hash `json:"challenge"` | ||
| // use one of the string of EuclidFork / EuclidV2Fork | ||
| ForkName string `json:"fork_name"` | ||
| ChunkInfos []*ChunkInfo `json:"chunk_infos"` | ||
| ChunkProofs []ChunkProof `json:"chunk_proofs"` | ||
| BatchHeader interface{} `json:"batch_header"` | ||
| BlobBytes []byte `json:"blob_bytes"` | ||
| KzgProof Byte48 `json:"kzg_proof,omitempty"` | ||
| KzgCommitment Byte48 `json:"kzg_commitment,omitempty"` | ||
| ChallengeDigest common.Hash `json:"challenge_digest,omitempty"` | ||
colinlyguo marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| // BundleTaskDetail consists of all the information required to describe the task to generate a proof for a bundle of batches. | ||
| type BundleTaskDetail struct { | ||
| BatchProofs []BatchProof `json:"batch_proofs"` | ||
| // use one of the string of EuclidFork / EuclidV2Fork | ||
| ForkName string `json:"fork_name"` | ||
| BatchProofs []BatchProof `json:"batch_proofs"` | ||
| BundleInfo *OpenVMBundleInfo `json:"bundle_info,omitempty"` | ||
| } | ||
| // ChunkInfo is for calculating pi_hash for chunk | ||
| type ChunkInfo struct { | ||
| ChainID uint64 `json:"chain_id"` | ||
| PrevStateRoot common.Hash `json:"prev_state_root"` | ||
| PostStateRoot common.Hash `json:"post_state_root"` | ||
| WithdrawRoot common.Hash `json:"withdraw_root"` | ||
| DataHash common.Hash `json:"data_hash"` | ||
| IsPadding bool `json:"is_padding"` | ||
| TxBytes []byte `json:"tx_bytes"` | ||
| TxBytesHash common.Hash `json:"tx_data_digest"` | ||
| PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"` | ||
| ChainID uint64 `json:"chain_id"` | ||
| PrevStateRoot common.Hash `json:"prev_state_root"` | ||
| PostStateRoot common.Hash `json:"post_state_root"` | ||
| WithdrawRoot common.Hash `json:"withdraw_root"` | ||
| DataHash common.Hash `json:"data_hash"` | ||
| IsPadding bool `json:"is_padding"` | ||
| TxBytes []byte `json:"tx_bytes"` | ||
| TxBytesHash common.Hash `json:"tx_data_digest"` | ||
| PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"` | ||
| PostMsgQueueHash common.Hash `json:"post_msg_queue_hash"` | ||
| TxDataLength uint64 `json:"tx_data_length"` | ||
| InitialBlockNumber uint64 `json:"initial_block_number"` | ||
| BlockCtxs []BlockContextV2 `json:"block_ctxs"` | ||
| } | ||
| // BlockContextV2 is the block context for euclid v2 | ||
| type BlockContextV2 struct { | ||
| Timestamp uint64 `json:"timestamp"` | ||
| BaseFee hexutil.Big `json:"base_fee"` | ||
| GasLimit uint64 `json:"gas_limit"` | ||
| NumTxs uint16 `json:"num_txs"` | ||
| NumL1Msgs uint16 `json:"num_l1_msgs"` | ||
| } | ||
| // SubCircuitRowUsage tracing info added in v0.11.0rc8 | ||
| @@ -87,7 +157,7 @@ type ChunkProof interface { | ||
| // NewChunkProof creates a new ChunkProof instance. | ||
| func NewChunkProof(hardForkName string) ChunkProof { | ||
| switch hardForkName { | ||
| case euclidFork: | ||
| case EuclidFork, EuclidV2Fork: | ||
| return &OpenVMChunkProof{} | ||
| default: | ||
| return &Halo2ChunkProof{} | ||
| @@ -121,7 +191,7 @@ type BatchProof interface { | ||
| // NewBatchProof creates a new BatchProof instance. | ||
| func NewBatchProof(hardForkName string) BatchProof { | ||
| switch hardForkName { | ||
| case euclidFork: | ||
| case EuclidFork, EuclidV2Fork: | ||
| return &OpenVMBatchProof{} | ||
| default: | ||
| return &Halo2BatchProof{} | ||
| @@ -178,7 +248,7 @@ type BundleProof interface { | ||
| // NewBundleProof creates a new BundleProof instance. | ||
| func NewBundleProof(hardForkName string) BundleProof { | ||
| switch hardForkName { | ||
| case euclidFork: | ||
| case EuclidFork, EuclidV2Fork: | ||
| return &OpenVMBundleProof{} | ||
| default: | ||
| return &Halo2BundleProof{} | ||
| @@ -258,12 +328,14 @@ func (p *OpenVMChunkProof) Proof() []byte { | ||
| // OpenVMBatchInfo is for calculating pi_hash for batch header | ||
| type OpenVMBatchInfo struct { | ||
| ParentBatchHash common.Hash `json:"parent_batch_hash"` | ||
| ParentStateRoot common.Hash `json:"parent_state_root"` | ||
| StateRoot common.Hash `json:"state_root"` | ||
| WithdrawRoot common.Hash `json:"withdraw_root"` | ||
| BatchHash common.Hash `json:"batch_hash"` | ||
| ChainID uint64 `json:"chain_id"` | ||
| ParentBatchHash common.Hash `json:"parent_batch_hash"` | ||
| ParentStateRoot common.Hash `json:"parent_state_root"` | ||
| StateRoot common.Hash `json:"state_root"` | ||
| WithdrawRoot common.Hash `json:"withdraw_root"` | ||
| BatchHash common.Hash `json:"batch_hash"` | ||
| ChainID uint64 `json:"chain_id"` | ||
| PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"` | ||
| PostMsgQueueHash common.Hash `json:"post_msg_queue_hash"` | ||
| } | ||
| // BatchProof includes the proof info that are required for batch verification and rollup. | ||
| @@ -323,6 +395,7 @@ type OpenVMBundleInfo struct { | ||
| NumBatches uint32 `json:"num_batches"` | ||
| PrevBatchHash common.Hash `json:"prev_batch_hash"` | ||
| BatchHash common.Hash `json:"batch_hash"` | ||
| MsgQueueHash common.Hash `json:"msg_queue_hash"` | ||
| } | ||
| // OpenVMBundleProof includes the proof info that are required for verification of a bundle of batch proofs. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package message | ||
| import ( | ||
| "fmt" | ||
| "testing" | ||
| ) | ||
| func TestBytes48(t *testing.T) { | ||
| ti := &Byte48{} | ||
| ti.UnmarshalText([]byte("0x1")) | ||
| if s, err := ti.MarshalText(); err == nil { | ||
| if len(s) != 98 { | ||
| panic(fmt.Sprintf("wrong str: %s", s)) | ||
| } | ||
| } | ||
| ti.UnmarshalText([]byte("0x0")) | ||
| if s, err := ti.MarshalText(); err == nil { | ||
| if len(s) != 98 { | ||
| panic(fmt.Sprintf("wrong str: %s", s)) | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.