Skip to content

Commit 2afa27d

Browse files
committed
new metrics for proof stat
1 parent 65fa249 commit 2afa27d

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

common/types/message/message.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,18 @@ type BlockContextV2 struct {
135135
NumL1Msgs uint16 `json:"num_l1_msgs"`
136136
}
137137

138+
// Metric data carried with OpenVMProof
139+
type OpenVMProofStat struct {
140+
TotalCycle uint64 `json:"total_cycles"`
141+
ExecutionTimeMills uint64 `json:"execution_time_mills"`
142+
ProvingTimeMills uint64 `json:"proving_time_mills"`
143+
}
144+
138145
// Proof for flatten VM proof
139146
type OpenVMProof struct {
140-
Proof []byte `json:"proofs"`
141-
PublicValues []byte `json:"public_values"`
147+
Proof []byte `json:"proofs"`
148+
PublicValues []byte `json:"public_values"`
149+
Stat *OpenVMProofStat `json:"stat,omitempty"`
142150
}
143151

144152
// Proof for flatten EVM proof
@@ -150,7 +158,8 @@ type OpenVMEvmProof struct {
150158
// OpenVMChunkProof includes the proof info that are required for chunk verification and rollup.
151159
type OpenVMChunkProof struct {
152160
MetaData struct {
153-
ChunkInfo *ChunkInfo `json:"chunk_info"`
161+
ChunkInfo *ChunkInfo `json:"chunk_info"`
162+
TotalGasUsed uint64 `json:"chunk_total_gas"`
154163
} `json:"metadata"`
155164

156165
VmProof *OpenVMProof `json:"proof"`

coordinator/internal/logic/submitproof/proof_receiver.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ type ProofReceiverLogic struct {
7171
validateFailureProverTaskStatusNotOk prometheus.Counter
7272
validateFailureProverTaskTimeout prometheus.Counter
7373
validateFailureProverTaskHaveVerifier prometheus.Counter
74+
proofTime *prometheus.GaugeVec
75+
evm_cycle_per_gas prometheus.Gauge
7476

7577
ChunkTask provertask.ProverTask
7678
BundleTask provertask.ProverTask
@@ -79,6 +81,7 @@ type ProofReceiverLogic struct {
7981

8082
// NewSubmitProofReceiverLogic create a proof receiver logic
8183
func NewSubmitProofReceiverLogic(cfg *config.ProverManager, chainCfg *params.ChainConfig, db *gorm.DB, vf *verifier.Verifier, reg prometheus.Registerer) *ProofReceiverLogic {
84+
8285
return &ProofReceiverLogic{
8386
chunkOrm: orm.NewChunk(db),
8487
batchOrm: orm.NewBatch(db),
@@ -133,6 +136,14 @@ func NewSubmitProofReceiverLogic(cfg *config.ProverManager, chainCfg *params.Cha
133136
Name: "coordinator_validate_failure_submit_have_been_verifier",
134137
Help: "Total number of submit proof validate failure proof have been verifier.",
135138
}),
139+
evm_cycle_per_gas: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
140+
Name: "evm_circuit_cycle_per_gas",
141+
Help: "VM cycles cost for a gas unit cost in evm execution",
142+
}),
143+
proofTime: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
144+
Name: "prover_proving_time",
145+
Help: "Time of prover cost for a proof",
146+
}, []string{"type", "phase"}),
136147
}
137148
}
138149

@@ -204,12 +215,31 @@ func (m *ProofReceiverLogic) HandleZkProof(ctx *gin.Context, proofParameter coor
204215
return unmarshalErr
205216
}
206217
success, verifyErr = m.verifier.VerifyChunkProof(chunkProof, hardForkName)
218+
if stat := chunkProof.VmProof.Stat; stat != nil {
219+
if g, _ := m.proofTime.GetMetricWithLabelValues("chunk", "exec"); g != nil {
220+
g.Set(float64(stat.ExecutionTimeMills) / 1000)
221+
}
222+
if g, _ := m.proofTime.GetMetricWithLabelValues("chunk", "proving"); g != nil {
223+
g.Set(float64(stat.ProvingTimeMills) / 1000)
224+
}
225+
cycle_per_gas := float64(stat.TotalCycle) / float64(chunkProof.MetaData.TotalGasUsed)
226+
m.evm_cycle_per_gas.Set(cycle_per_gas)
227+
}
228+
207229
case message.ProofTypeBatch:
208230
batchProof := &message.OpenVMBatchProof{}
209231
if unmarshalErr := json.Unmarshal([]byte(proofParameter.Proof), &batchProof); unmarshalErr != nil {
210232
return unmarshalErr
211233
}
212234
success, verifyErr = m.verifier.VerifyBatchProof(batchProof, hardForkName)
235+
if stat := batchProof.VmProof.Stat; stat != nil {
236+
if g, _ := m.proofTime.GetMetricWithLabelValues("batch", "exec"); g != nil {
237+
g.Set(float64(stat.ExecutionTimeMills) / 1000)
238+
}
239+
if g, _ := m.proofTime.GetMetricWithLabelValues("batch", "proving"); g != nil {
240+
g.Set(float64(stat.ProvingTimeMills) / 1000)
241+
}
242+
}
213243
case message.ProofTypeBundle:
214244
bundleProof := &message.OpenVMBundleProof{}
215245
if unmarshalErr := json.Unmarshal([]byte(proofParameter.Proof), &bundleProof); unmarshalErr != nil {

coordinator/test/api_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ func testTimeoutProof(t *testing.T) {
584584
err = chunkOrm.UpdateBatchHashInRange(context.Background(), 0, 100, batch.Hash)
585585
assert.NoError(t, err)
586586
encodeData, err := json.Marshal(message.OpenVMChunkProof{VmProof: &message.OpenVMProof{}, MetaData: struct {
587-
ChunkInfo *message.ChunkInfo `json:"chunk_info"`
587+
ChunkInfo *message.ChunkInfo `json:"chunk_info"`
588+
TotalGasUsed uint64 `json:"chunk_total_gas"`
588589
}{ChunkInfo: &message.ChunkInfo{}}})
589590
assert.NoError(t, err)
590591
assert.NotEmpty(t, encodeData)

crates/libzkp/src/proofs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ pub trait PersistableProof: Sized {
122122
pub struct ChunkProofMetadata {
123123
/// The chunk information describing the list of blocks contained within the chunk.
124124
pub chunk_info: ChunkInfo,
125+
/// Additional data for stat
126+
pub chunk_total_gas: u64,
125127
}
126128

127129
impl ProofMetadata for ChunkProofMetadata {

crates/libzkp/src/tasks.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ pub fn gen_universal_chunk_task(
4444
if let Some(interpreter) = interpreter {
4545
task.prepare_task_via_interpret(interpreter)?;
4646
}
47+
let chunk_total_gas = task.stats().total_gas_used;
4748
let chunk_info = task.precheck_and_build_metadata()?;
4849
let proving_task = task.try_into()?;
4950
let expected_pi_hash = chunk_info.pi_hash_by_fork(fork_name);
5051
Ok((
5152
expected_pi_hash,
52-
ChunkProofMetadata { chunk_info },
53+
ChunkProofMetadata {
54+
chunk_info,
55+
chunk_total_gas,
56+
},
5357
proving_task,
5458
))
5559
}

0 commit comments

Comments
 (0)