Skip to content

Commit f9de393

Browse files
committed
fix byte48 type required in prover
Signed-off-by: noelwei <[email protected]>
1 parent 2d620dd commit f9de393

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

common/types/message/message.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,35 @@ type EuclidV2ChunkTaskDetail struct {
5353
PrevMsgQueueHash common.Hash `json:"prev_msg_queue_hash"`
5454
}
5555

56+
// it is a hex encoded big with fixed length on 48 bytes
57+
type Byte48 struct {
58+
hexutil.Big
59+
}
60+
61+
func (e Byte48) MarshalText() ([]byte, error) {
62+
i := e.ToInt()
63+
// overrite encode big
64+
if sign := i.Sign(); sign < 0 {
65+
// sanity check
66+
return nil, fmt.Errorf("Byte48 must be positive integer")
67+
} else {
68+
s := i.Text(16)
69+
if len(s) > 96 {
70+
return nil, fmt.Errorf("Integer Exceed 384bit")
71+
}
72+
return []byte(fmt.Sprintf("0x%0*s", 96, s)), nil
73+
}
74+
}
75+
5676
// BatchTaskDetail is a type containing BatchTask detail.
5777
type BatchTaskDetail struct {
5878
ChunkInfos []*ChunkInfo `json:"chunk_infos"`
5979
ChunkProofs []ChunkProof `json:"chunk_proofs"`
6080
BatchHeader interface{} `json:"batch_header"`
6181
BlobBytes []byte `json:"blob_bytes"`
62-
KzgProof hexutil.Big `json:"kzg_proof"`
63-
KzgCommitment hexutil.Big `json:"kzg_commitment"`
64-
ChallengeDigest hexutil.Big `json:"challenge_digest"`
82+
KzgProof Byte48 `json:"kzg_proof"`
83+
KzgCommitment Byte48 `json:"kzg_commitment"`
84+
ChallengeDigest Byte48 `json:"challenge_digest"`
6585
}
6686

6787
// BundleTaskDetail consists of all the information required to describe the task to generate a proof for a bundle of batches.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package message
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
)
7+
8+
func TestBytes48(t *testing.T) {
9+
ti := &Byte48{}
10+
ti.UnmarshalText([]byte("0x1"))
11+
if s, err := ti.MarshalText(); err == nil {
12+
if len(s) != 98 {
13+
panic(fmt.Sprintf("wrong str: %s", s))
14+
}
15+
}
16+
ti.UnmarshalText([]byte("0x0"))
17+
if s, err := ti.MarshalText(); err == nil {
18+
if len(s) != 98 {
19+
panic(fmt.Sprintf("wrong str: %s", s))
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)