Skip to content

Commit

Permalink
merkle: restore 3D proof. fewer memmoves bc copying hash refs instead…
Browse files Browse the repository at this point in the history
… of vals
  • Loading branch information
sanjit-bhat committed Dec 2, 2024
1 parent af6b2a8 commit 0da4ef3
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 78 deletions.
6 changes: 3 additions & 3 deletions kt/serde.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ type Memb struct {
LabelProof []byte
EpochAdded uint64
PkOpen *CommitOpen
MerkProof []byte
MerkProof [][][]byte
}

type MembHide struct {
LabelProof []byte
MapVal []byte
MerkProof []byte
MerkProof [][][]byte
}

type NonMemb struct {
LabelProof []byte
MerkProof []byte
MerkProof [][][]byte
}

type ServerPutArg struct {
Expand Down
12 changes: 6 additions & 6 deletions kt/serde.out.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func MembEncode(b0 []byte, o *Memb) []byte {
b = marshalutil.WriteSlice1D(b, o.LabelProof)
b = marshal.WriteInt(b, o.EpochAdded)
b = CommitOpenEncode(b, o.PkOpen)
b = marshalutil.WriteSlice1D(b, o.MerkProof)
b = marshalutil.WriteSlice3D(b, o.MerkProof)
return b
}
func MembDecode(b0 []byte) (*Memb, []byte, bool) {
Expand All @@ -118,7 +118,7 @@ func MembDecode(b0 []byte) (*Memb, []byte, bool) {
if err3 {
return nil, nil, true
}
a4, b4, err4 := marshalutil.ReadSlice1D(b3)
a4, b4, err4 := marshalutil.ReadSlice3D(b3)
if err4 {
return nil, nil, true
}
Expand All @@ -128,7 +128,7 @@ func MembHideEncode(b0 []byte, o *MembHide) []byte {
var b = b0
b = marshalutil.WriteSlice1D(b, o.LabelProof)
b = marshalutil.WriteSlice1D(b, o.MapVal)
b = marshalutil.WriteSlice1D(b, o.MerkProof)
b = marshalutil.WriteSlice3D(b, o.MerkProof)
return b
}
func MembHideDecode(b0 []byte) (*MembHide, []byte, bool) {
Expand All @@ -140,7 +140,7 @@ func MembHideDecode(b0 []byte) (*MembHide, []byte, bool) {
if err2 {
return nil, nil, true
}
a3, b3, err3 := marshalutil.ReadSlice1D(b2)
a3, b3, err3 := marshalutil.ReadSlice3D(b2)
if err3 {
return nil, nil, true
}
Expand All @@ -149,15 +149,15 @@ func MembHideDecode(b0 []byte) (*MembHide, []byte, bool) {
func NonMembEncode(b0 []byte, o *NonMemb) []byte {
var b = b0
b = marshalutil.WriteSlice1D(b, o.LabelProof)
b = marshalutil.WriteSlice1D(b, o.MerkProof)
b = marshalutil.WriteSlice3D(b, o.MerkProof)
return b
}
func NonMembDecode(b0 []byte) (*NonMemb, []byte, bool) {
a1, b1, err1 := marshalutil.ReadSlice1D(b0)
if err1 {
return nil, nil, true
}
a2, b2, err2 := marshalutil.ReadSlice1D(b1)
a2, b2, err2 := marshalutil.ReadSlice3D(b1)
if err2 {
return nil, nil, true
}
Expand Down
81 changes: 41 additions & 40 deletions marshalutil/marshalutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,75 @@ import (
"github.com/tchajed/marshal"
)

type errorTy = bool

const (
errNone errorTy = false
errSome errorTy = true
)
func WriteBytes2D(b0 []byte, data [][]byte) []byte {
var b = b0
for _, x := range data {
b = marshal.WriteBytes(b, x)
}
return b
}

func ReadBool(b0 []byte) (bool, []byte, errorTy) {
func ReadBool(b0 []byte) (bool, []byte, bool) {
var b = b0
if uint64(len(b)) < 1 {
return false, nil, errSome
return false, nil, true
}
data, b := marshal.ReadBool(b)
return data, b, errNone
return data, b, false
}

func ReadConstBool(b0 []byte, cst bool) ([]byte, errorTy) {
func ReadConstBool(b0 []byte, cst bool) ([]byte, bool) {
var b = b0
res, b, err := ReadBool(b)
if err {
return nil, errSome
return nil, true
}
if res != cst {
return nil, errSome
return nil, true
}
return b, errNone
return b, false
}

func ReadInt(b0 []byte) (uint64, []byte, errorTy) {
func ReadInt(b0 []byte) (uint64, []byte, bool) {
var b = b0
if uint64(len(b)) < 8 {
return 0, nil, errSome
return 0, nil, true
}
data, b := marshal.ReadInt(b)
return data, b, errNone
return data, b, false
}

func ReadConstInt(b0 []byte, cst uint64) ([]byte, errorTy) {
func ReadConstInt(b0 []byte, cst uint64) ([]byte, bool) {
var b = b0
res, b, err := ReadInt(b)
if err {
return nil, errSome
return nil, true
}
if res != cst {
return nil, errSome
return nil, true
}
return b, errNone
return b, false
}

func ReadByte(b0 []byte) (byte, []byte, errorTy) {
func ReadByte(b0 []byte) (byte, []byte, bool) {
var b = b0
if uint64(len(b)) < 1 {
return 0, nil, errSome
return 0, nil, true
}
data, b := marshal.ReadBytes(b, 1)
return data[0], b, errNone
return data[0], b, false
}

func ReadConstByte(b0 []byte, cst byte) ([]byte, errorTy) {
func ReadConstByte(b0 []byte, cst byte) ([]byte, bool) {
var b = b0
res, b, err := ReadByte(b)
if err {
return nil, errSome
return nil, true
}
if res != cst {
return nil, errSome
return nil, true
}
return b, errNone
return b, false
}

func WriteByte(b0 []byte, data byte) []byte {
Expand All @@ -80,16 +81,16 @@ func WriteByte(b0 []byte, data byte) []byte {
return b
}

func ReadBytes(b0 []byte, length uint64) ([]byte, []byte, errorTy) {
func ReadBytes(b0 []byte, length uint64) ([]byte, []byte, bool) {
var b = b0
if uint64(len(b)) < length {
return nil, nil, errSome
return nil, nil, true
}
data, b := marshal.ReadBytes(b, length)
return data, b, errNone
return data, b, false
}

func ReadSlice1D(b0 []byte) ([]byte, []byte, errorTy) {
func ReadSlice1D(b0 []byte) ([]byte, []byte, bool) {
var b = b0
length, b, err := ReadInt(b)
if err {
Expand All @@ -99,7 +100,7 @@ func ReadSlice1D(b0 []byte) ([]byte, []byte, errorTy) {
if err {
return nil, nil, err
}
return data, b, errNone
return data, b, false
}

func WriteSlice1D(b0 []byte, data []byte) []byte {
Expand All @@ -109,18 +110,18 @@ func WriteSlice1D(b0 []byte, data []byte) []byte {
return b
}

func ReadSlice2D(b0 []byte) ([][]byte, []byte, errorTy) {
func ReadSlice2D(b0 []byte) ([][]byte, []byte, bool) {
var b = b0
length, b, err := ReadInt(b)
if err {
return nil, nil, err
}
var data0 [][]byte
var err0 errorTy
var err0 bool
var i uint64
for ; i < length; i++ {
var data1 []byte
var err1 errorTy
var err1 bool
data1, b, err1 = ReadSlice1D(b)
if err1 {
err0 = err1
Expand All @@ -131,7 +132,7 @@ func ReadSlice2D(b0 []byte) ([][]byte, []byte, errorTy) {
if err0 {
return nil, nil, err0
}
return data0, b, errNone
return data0, b, false
}

func WriteSlice2D(b0 []byte, data [][]byte) []byte {
Expand All @@ -143,18 +144,18 @@ func WriteSlice2D(b0 []byte, data [][]byte) []byte {
return b
}

func ReadSlice3D(b0 []byte) ([][][]byte, []byte, errorTy) {
func ReadSlice3D(b0 []byte) ([][][]byte, []byte, bool) {
var b = b0
length, b, err := ReadInt(b)
if err {
return nil, nil, err
}
var data0 [][][]byte
var err0 errorTy
var err0 bool
var i uint64
for ; i < length; i++ {
var data1 [][]byte
var err1 errorTy
var err1 bool
data1, b, err1 = ReadSlice2D(b)
if err1 {
err0 = err1
Expand All @@ -165,7 +166,7 @@ func ReadSlice3D(b0 []byte) ([][][]byte, []byte, errorTy) {
if err0 {
return nil, nil, err0
}
return data0, b, errNone
return data0, b, false
}

func WriteSlice3D(b0 []byte, data [][][]byte) []byte {
Expand Down
Loading

0 comments on commit 0da4ef3

Please sign in to comment.