Skip to content

Commit

Permalink
add post values to the proof
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Aug 31, 2023
1 parent d62cdcc commit 9b27f34
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions proof_ipa.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ type Proof struct {
Cs []*Point // commitments, sorted by their path in the tree
PoaStems [][]byte // stems proving another stem is absent
Keys [][]byte
Values [][]byte
PreValues [][]byte
PostValues [][]byte
}

type SuffixStateDiff struct {
Suffix byte `json:"suffix"`
CurrentValue *[32]byte `json:"currentValue"`
NewValue *[32]byte `json:"new_value"`
}

type SuffixStateDiffs []SuffixStateDiff
Expand Down Expand Up @@ -102,6 +104,7 @@ func MakeVerkleMultiProof(pre_root, post_root VerkleNode, keys [][]byte, resolve
proof_cis []*Point
proof_fs [][]Fr
proof_zs []uint8
postvals = make([][]byte, len(keys))
)
for i := range pe.Cis {
proof_cis = append(proof_cis, pe.Cis[i])
Expand All @@ -120,6 +123,13 @@ func MakeVerkleMultiProof(pre_root, post_root VerkleNode, keys [][]byte, resolve
proof_fs = append(proof_fs, pe_post.Fis[i])
proof_zs = append(proof_zs, pe_post.Zis[i])
}

// Set the post values, if they are untouched, leave them `nil`
for i, v := range pe.Vals {
if !bytes.Equal(v, pe_post.Vals[i]) {
postvals[i] = v
}
}
}

cfg := GetConfig()
Expand All @@ -141,13 +151,15 @@ func MakeVerkleMultiProof(pre_root, post_root VerkleNode, keys [][]byte, resolve
for i, path := range paths {
cis[i] = pe.ByPath[path]
}

proof := &Proof{
Multipoint: mpArg,
Cs: cis,
ExtStatus: es,
PoaStems: poas,
Keys: keys,
Values: pe.Vals,
PreValues: pe.Vals,
PostValues: postvals,
}
return proof, pe.Cis, pe.Zis, pe.Yis, nil
}
Expand Down Expand Up @@ -192,26 +204,34 @@ func SerializeProof(proof *Proof) (*VerkleProof, StateDiff, error) {
stemdiff = &statediff[len(statediff)-1]
copy(stemdiff.Stem[:], key[:31])
}
var valueLen = len(proof.Values[i])
newsd := SuffixStateDiff{Suffix: key[31]}
stemdiff.SuffixDiffs = append(stemdiff.SuffixDiffs, newsd)

var valueLen = len(proof.PreValues[i])
switch valueLen {
case 0:
stemdiff.SuffixDiffs = append(stemdiff.SuffixDiffs, SuffixStateDiff{
Suffix: key[31],
})
// null value
case 32:
stemdiff.SuffixDiffs = append(stemdiff.SuffixDiffs, SuffixStateDiff{
Suffix: key[31],
CurrentValue: (*[32]byte)(proof.Values[i]),
})
newsd.CurrentValue = (*[32]byte)(proof.PreValues[i])
default:
var aligned [32]byte
copy(aligned[:valueLen], proof.Values[i])
stemdiff.SuffixDiffs = append(stemdiff.SuffixDiffs, SuffixStateDiff{
Suffix: key[31],
CurrentValue: (*[32]byte)(unsafe.Pointer(&aligned[0])),
})
copy(aligned[:valueLen], proof.PreValues[i])
newsd.CurrentValue = (*[32]byte)(unsafe.Pointer(&aligned[0]))
}

valueLen = len(proof.PostValues[i])
switch valueLen {
case 0:
// null value
case 32:
newsd.NewValue = (*[32]byte)(proof.PostValues[i])
default:
var aligned [32]byte
copy(aligned[:valueLen], proof.PostValues[i])
newsd.NewValue = (*[32]byte)(unsafe.Pointer(&aligned[0]))
}
}

return &VerkleProof{
OtherStems: otherstems,
DepthExtensionPresent: proof.ExtStatus,
Expand Down

0 comments on commit 9b27f34

Please sign in to comment.