55// the call() helper which returns a promise resolved when the worker replies.
66
77import { normalizeChoices , packBallotMode } from './ballot_config.js' ;
8+ import { bytesToHex , formatProofPreview , summarizeTimings } from './proof_ui.js' ;
89
910const logEl = document . getElementById ( 'log' ) ;
1011const metricKeygenEl = document . getElementById ( 'metric-keygen' ) ;
@@ -71,11 +72,6 @@ function hexToBytes(hex) {
7172 return bytes ;
7273}
7374
74- // Convert Uint8Array to lowercase hex string.
75- function bytesToHex ( bytes ) {
76- return Array . from ( bytes ) . map ( b => b . toString ( 16 ) . padStart ( 2 , '0' ) ) . join ( '' ) ;
77- }
78-
7975// Encode a JS number as 8 bytes in little-endian u64 format.
8076function u64ToLeBytes ( val ) {
8177 const buf = new ArrayBuffer ( 8 ) ;
@@ -142,6 +138,7 @@ window.doProve = async function() {
142138 setMetric ( metricKeygenEl , `${ keygenMs . toFixed ( 1 ) } ms` ) ;
143139
144140 // Build binary inputs
141+ const packStart = performance . now ( ) ;
145142 const kBytes = hexToBytes ( kHex ) ;
146143 const fields = new Uint8Array ( 8 * 8 ) ;
147144 for ( let i = 0 ; i < 8 ; i ++ ) {
@@ -158,6 +155,7 @@ window.doProve = async function() {
158155
159156 const weightBytes = u64ToLeBytes ( weight ) ;
160157 const ballotMode = packBallotMode ( config ) ;
158+ const inputPackMs = performance . now ( ) - packStart ;
161159
162160 log ( '\n--- Full Ballot Proof ---' , 'info' ) ;
163161 log ( `Choices: [${ choices . slice ( 0 , config . numFields ) . join ( ', ' ) } ]` ) ;
@@ -172,17 +170,35 @@ window.doProve = async function() {
172170 } ) ;
173171 proofData = result . proofData ;
174172 const elapsed = performance . now ( ) - start ;
173+ const renderStart = performance . now ( ) ;
174+ const timings = summarizeTimings ( {
175+ inputPackMs,
176+ workerWallMs : result . timings ?. workerWallMs ?? elapsed ,
177+ wasmDecodeMs : result . timings ?. wasmDecodeMs ?? 0 ,
178+ wasmTraceMs : result . timings ?. wasmTraceMs ?? 0 ,
179+ wasmProveMs : result . timings ?. wasmProveMs ?? 0 ,
180+ wasmSerializeMs : result . timings ?. wasmSerializeMs ?? 0 ,
181+ mainRenderMs : 0 ,
182+ } ) ;
175183
176184 log ( `✅ Proof generated!` , 'success' ) ;
177185 log ( `Proof size: ${ proofData . length } bytes (${ ( proofData . length / 1024 ) . toFixed ( 1 ) } KB)` ) ;
178186 log ( `⏱ ${ ( elapsed / 1000 ) . toFixed ( 1 ) } s` , 'timing' ) ;
187+ log (
188+ `Timing breakdown: pack=${ timings . inputPackMs } ms worker=${ timings . workerWallMs } ms ` +
189+ `decode=${ timings . wasmDecodeMs } ms trace=${ timings . wasmTraceMs } ms ` +
190+ `prove=${ timings . wasmProveMs } ms serialize=${ timings . wasmSerializeMs } ms` ,
191+ 'timing' ,
192+ ) ;
179193 setMetric ( metricProveEl , `${ ( elapsed / 1000 ) . toFixed ( 2 ) } s` ) ;
180194 metricNoteEl . textContent =
181195 `FRI config: blowup 8, 34 queries, 0 PoW bits. Last proof size: ${ ( proofData . length / 1024 ) . toFixed ( 1 ) } KB.` ;
182196
183197 // Show proof data
184198 document . getElementById ( 'proof-card' ) . style . display = 'block' ;
185- document . getElementById ( 'proof-data' ) . textContent = bytesToHex ( proofData ) ;
199+ document . getElementById ( 'proof-data' ) . textContent = formatProofPreview ( proofData ) ;
200+ timings . mainRenderMs = ( performance . now ( ) - renderStart ) . toFixed ( 2 ) ;
201+ log ( `Render=${ timings . mainRenderMs } ms` , 'timing' ) ;
186202
187203 document . getElementById ( 'btn-prove' ) . disabled = false ;
188204 document . getElementById ( 'btn-verify' ) . disabled = false ;
0 commit comments