chore(rln-relay): confirm that the provided credential is correct using onchain query

This commit is contained in:
Richard Ramos 2023-09-04 16:23:49 -04:00 committed by richΛrd
parent 7fbb9ebe42
commit def745cfba
5 changed files with 53 additions and 9 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1 +1 @@
Subproject commit 63a7856eb29f08644d1e963e3edfc2c182469257 Subproject commit 8f8dda5b7133aa8f99cbc46804972d02c22c0155

View File

@ -135,6 +135,10 @@ func (gm *DynamicGroupManager) getMembershipFee(ctx context.Context) (*big.Int,
return gm.web3Config.RLNContract.MEMBERSHIPDEPOSIT(&bind.CallOpts{Context: ctx}) return gm.web3Config.RLNContract.MEMBERSHIPDEPOSIT(&bind.CallOpts{Context: ctx})
} }
func (gm *DynamicGroupManager) memberExists(ctx context.Context, idCommitment rln.IDCommitment) (bool, error) {
return gm.web3Config.RLNContract.MemberExists(&bind.CallOpts{Context: ctx}, rln.Bytes32ToBigInt(idCommitment))
}
func (gm *DynamicGroupManager) Start(ctx context.Context, rlnInstance *rln.RLN, rootTracker *group_manager.MerkleRootTracker) error { func (gm *DynamicGroupManager) Start(ctx context.Context, rlnInstance *rln.RLN, rootTracker *group_manager.MerkleRootTracker) error {
if gm.cancel != nil { if gm.cancel != nil {
return errors.New("already started") return errors.New("already started")
@ -159,7 +163,7 @@ func (gm *DynamicGroupManager) Start(ctx context.Context, rlnInstance *rln.RLN,
return err return err
} }
err = gm.loadCredential() err = gm.loadCredential(ctx)
if err != nil { if err != nil {
return err return err
} }
@ -171,7 +175,7 @@ func (gm *DynamicGroupManager) Start(ctx context.Context, rlnInstance *rln.RLN,
return nil return nil
} }
func (gm *DynamicGroupManager) loadCredential() error { func (gm *DynamicGroupManager) loadCredential(ctx context.Context) error {
start := time.Now() start := time.Now()
credentials, err := gm.appKeystore.GetMembershipCredentials( credentials, err := gm.appKeystore.GetMembershipCredentials(
@ -187,6 +191,15 @@ func (gm *DynamicGroupManager) loadCredential() error {
return errors.New("no credentials available") return errors.New("no credentials available")
} }
exists, err := gm.memberExists(ctx, credentials.IdentityCredential.IDCommitment)
if err != nil {
return err
}
if !exists {
return errors.New("the provided commitment does not have a membership")
}
gm.identityCredential = credentials.IdentityCredential gm.identityCredential = credentials.IdentityCredential
return nil return nil

View File

@ -217,7 +217,7 @@ func (s *WakuRLNRelayDynamicSuite) TestMerkleTreeConstruction() {
credentials1 := s.generateCredentials(rlnInstance) credentials1 := s.generateCredentials(rlnInstance)
credentials2 := s.generateCredentials(rlnInstance) credentials2 := s.generateCredentials(rlnInstance)
err = rlnInstance.InsertMembers(1, []rln.IDCommitment{credentials1.IDCommitment, credentials2.IDCommitment}) err = rlnInstance.InsertMembers(0, []rln.IDCommitment{credentials1.IDCommitment, credentials2.IDCommitment})
s.Require().NoError(err) s.Require().NoError(err)
// get the Merkle root // get the Merkle root
@ -298,8 +298,8 @@ func (s *WakuRLNRelayDynamicSuite) TestCorrectRegistrationOfPeers() {
idx1 := rlnRelay1.groupManager.MembershipIndex() idx1 := rlnRelay1.groupManager.MembershipIndex()
idx2 := rlnRelay2.groupManager.MembershipIndex() idx2 := rlnRelay2.groupManager.MembershipIndex()
s.Require().NoError(err) s.Require().NoError(err)
s.Require().Equal(rln.MembershipIndex(1), idx1) s.Require().Equal(rln.MembershipIndex(0), idx1)
s.Require().Equal(rln.MembershipIndex(2), idx2) s.Require().Equal(rln.MembershipIndex(1), idx2)
} }
func (s *WakuRLNRelayDynamicSuite) tmpKeystorePath() string { func (s *WakuRLNRelayDynamicSuite) tmpKeystorePath() string {