Skip to content

Commit c830451

Browse files
committed
fix: openvm proof (base64) | evm proof (encoding for on-chain)
1 parent bb9d404 commit c830451

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

common/types/message/message.go

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -223,30 +223,14 @@ func (ap *Halo2BundleProof) SanityCheck() error {
223223

224224
// Proof for flatten VM proof
225225
type OpenVMProof struct {
226-
Proof interface{} `json:"proofs"`
227-
PublicValues []uint32 `json:"public_values"`
228-
}
229-
230-
type ByteArray []byte
231-
232-
// MarshalJSON marshals a ByteArray to JSON
233-
func (b ByteArray) MarshalJSON() ([]byte, error) {
234-
builder := strings.Builder{}
235-
builder.WriteString("[")
236-
for i, v := range b {
237-
builder.WriteString(fmt.Sprintf("%d", v))
238-
if i != len(b)-1 {
239-
builder.WriteString(",")
240-
}
241-
}
242-
builder.WriteString("]")
243-
return []byte(builder.String()), nil
226+
Proof []byte `json:"proofs"`
227+
PublicValues []byte `json:"public_values"`
244228
}
245229

246230
// Proof for flatten EVM proof
247231
type OpenVMEvmProof struct {
248-
Proof ByteArray `json:"proof"`
249-
Instances [][]string `json:"instances"`
232+
Proof []byte `json:"proof"`
233+
Instances []byte `json:"instances"`
250234
}
251235

252236
// OpenVMChunkProof includes the proof info that are required for chunk verification and rollup.
@@ -350,8 +334,21 @@ type OpenVMBundleProof struct {
350334
GitVersion string `json:"git_version,omitempty"`
351335
}
352336

337+
// Proof returns the proof bytes that are eventually passed as calldata for on-chain bundle proof verification.
338+
//
339+
// There are 12 accumulators for a SNARK proof. The accumulators are the first 12 elements of the EvmProof's
340+
// Instances field. The remaining items in Instances are supplied on-chain by the ScrollChain contract.
341+
//
342+
// The structure of these bytes is:
343+
// | byte index start | byte length | value | description |
344+
// |------------------|----------------|----------|---------------------|
345+
// | 0 | 32 | accs[0] | accumulator 1 |
346+
// | 32 | 32 | accs[1] | accumulator 2 |
347+
// | 32*i ... | 32 | accs[i] | accumulator i ... |
348+
// | 352 | 32 | accs[11] | accumulator 12 |
349+
// | 384 | dynamic | proof | proof bytes |
353350
func (p *OpenVMBundleProof) Proof() []byte {
354-
return p.EvmProof.Proof
351+
append(p.EvmProof.Instances[0:384], p.EvmProof.Proof)
355352
}
356353

357354
// SanityCheck checks whether a BundleProof is in a legal format

0 commit comments

Comments
 (0)