mirror of
https://github.com/logos-messaging/go-zerokit-rln.git
synced 2026-01-02 13:13:11 +00:00
feat: atomic_write
This commit is contained in:
parent
f3f2c16093
commit
00cc03aa04
6
go.mod
6
go.mod
@ -4,9 +4,9 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/stretchr/testify v1.7.2
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331231302-258cacb91327
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230331223149-f90e66aebb0d
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230331181847-cba74520bae9
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230517215159-cea56434b07a
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230517214322-89b514ad7697
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230517190629-6d0c983d1080
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
6
go.sum
6
go.sum
@ -17,10 +17,16 @@ github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331223042-3d24f0c813c3 h1:9
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331223042-3d24f0c813c3/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48=
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331231302-258cacb91327 h1:Q5XQqo+PEmvrybT8D7BEsKCwIYDi80s+00Q49cfm9Gs=
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331231302-258cacb91327/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48=
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230517215159-cea56434b07a h1:YnpxsRnmQlFwouAdgtj95L/az32rlQ1Jtjx08CVx8tc=
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230517215159-cea56434b07a/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48=
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230331223149-f90e66aebb0d h1:Kcg85Y2xGU6hqZ/kMfkLQF2jAog8vt+tw1/VNidzNtE=
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230331223149-f90e66aebb0d/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4=
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230517214322-89b514ad7697 h1:ogFZsxT02kIbo5qHmGBiYPLmfduFVNJYKfz0ozQxI5E=
|
||||
github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230517214322-89b514ad7697/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4=
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230331181847-cba74520bae9 h1:u+YUlWDltHiK5upSb7M6mStc84zdc4vTCNNOz7R5RaY=
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230331181847-cba74520bae9/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y=
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230517190629-6d0c983d1080 h1:AO3Sv0ECsxGKdSUOuC4cfqVYtyjXZcKKwrY8lqQk+3g=
|
||||
github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230517190629-6d0c983d1080/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
|
||||
@ -62,3 +62,7 @@ func (i RLNWrapper) GenerateRLNProof(input []byte) ([]byte, error) {
|
||||
func (i RLNWrapper) VerifyWithRoots(input []byte, roots []byte) (bool, error) {
|
||||
return i.ffi.VerifyWithRoots(input, roots)
|
||||
}
|
||||
|
||||
func (i RLNWrapper) AtomicOperation(index uint, leaves []byte, indices []byte) bool {
|
||||
return i.ffi.AtomicOperation(index, leaves, indices)
|
||||
}
|
||||
|
||||
@ -61,3 +61,7 @@ func (i RLNWrapper) GenerateRLNProof(input []byte) ([]byte, error) {
|
||||
func (i RLNWrapper) VerifyWithRoots(input []byte, roots []byte) (bool, error) {
|
||||
return i.ffi.VerifyWithRoots(input, roots)
|
||||
}
|
||||
|
||||
func (i RLNWrapper) AtomicOperation(index uint, leaves []byte, indices []byte) bool {
|
||||
return i.ffi.AtomicOperation(index, leaves, indices)
|
||||
}
|
||||
|
||||
@ -62,3 +62,7 @@ func (i RLNWrapper) GenerateRLNProof(input []byte) ([]byte, error) {
|
||||
func (i RLNWrapper) VerifyWithRoots(input []byte, roots []byte) (bool, error) {
|
||||
return i.ffi.VerifyWithRoots(input, roots)
|
||||
}
|
||||
|
||||
func (i RLNWrapper) AtomicOperation(index uint, leaves []byte, indices []byte) bool {
|
||||
return i.ffi.AtomicOperation(index, leaves, indices)
|
||||
}
|
||||
|
||||
28
rln/rln.go
28
rln/rln.go
@ -242,6 +242,20 @@ func serializeCommitments(commitments []IDCommitment) []byte {
|
||||
return result
|
||||
}
|
||||
|
||||
func serializeIndices(indices []MembershipIndex) []byte {
|
||||
var result []byte
|
||||
|
||||
inputLen := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(inputLen, uint64(len(indices)))
|
||||
result = append(result, inputLen...)
|
||||
|
||||
for _, index := range indices {
|
||||
result = binary.LittleEndian.AppendUint64(result, uint64(index))
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// proof [ proof<128>| root<32>| epoch<32>| share_x<32>| share_y<32>| nullifier<32> | signal_len<8> | signal<var> ]
|
||||
// validRoots should contain a sequence of roots in the acceptable windows.
|
||||
// As default, it is set to an empty sequence of roots. This implies that the validity check for the proof's root is skipped
|
||||
@ -270,7 +284,8 @@ func (r *RLN) InsertMember(idComm IDCommitment) error {
|
||||
// This proc is atomic, i.e., if any of the insertions fails, all the previous insertions are rolled back
|
||||
func (r *RLN) InsertMembers(index MembershipIndex, idComms []IDCommitment) error {
|
||||
idCommBytes := serializeCommitments(idComms)
|
||||
insertionSuccess := r.w.SetLeavesFrom(index, idCommBytes)
|
||||
indicesBytes := serializeIndices(nil)
|
||||
insertionSuccess := r.w.AtomicOperation(index, idCommBytes, indicesBytes)
|
||||
if !insertionSuccess {
|
||||
return errors.New("could not insert members")
|
||||
}
|
||||
@ -288,6 +303,17 @@ func (r *RLN) DeleteMember(index MembershipIndex) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete multiple members
|
||||
func (r *RLN) DeleteMembers(indices []MembershipIndex) error {
|
||||
idCommBytes := serializeCommitments(nil)
|
||||
indicesBytes := serializeIndices(indices)
|
||||
insertionSuccess := r.w.AtomicOperation(0, idCommBytes, indicesBytes)
|
||||
if !insertionSuccess {
|
||||
return errors.New("could not insert members")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetMerkleRoot reads the Merkle Tree root after insertion
|
||||
func (r *RLN) GetMerkleRoot() (MerkleNode, error) {
|
||||
b, err := r.w.GetRoot()
|
||||
|
||||
@ -78,6 +78,12 @@ func (s *RLNSuite) TestRemoveMember() {
|
||||
rln, err := NewRLN()
|
||||
s.NoError(err)
|
||||
|
||||
keypair, err := rln.MembershipKeyGen()
|
||||
s.NoError(err)
|
||||
|
||||
err = rln.InsertMember(keypair.IDCommitment)
|
||||
s.NoError(err)
|
||||
|
||||
err = rln.DeleteMember(MembershipIndex(0))
|
||||
s.NoError(err)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user