group manager updates

This commit is contained in:
stubbsta 2025-03-28 16:34:52 +02:00
parent 8e9cbb53e8
commit a447c1a91a
2 changed files with 23 additions and 21 deletions

View File

@ -22,12 +22,12 @@ proc TheWakuNetworkConf*(T: type ClusterConf): ClusterConf =
maxMessageSize: "150KiB",
clusterId: 1,
rlnRelay: true,
rlnRelayEthContractAddress: "0xCB33Aa5B38d79E3D9Fa8B10afF38AA201399a7e3",
rlnRelayEthContractAddress: "0xB9cd878C90E49F797B4431fBF4fb333108CB90e6",
rlnRelayDynamic: true,
rlnRelayChainId: 11155111,
rlnRelayChainId: 59141,
rlnRelayBandwidthThreshold: 0,
rlnEpochSizeSec: 600,
rlnRelayUserMessageLimit: 100,
rlnRelayUserMessageLimit: 20,
numShardsInNetwork: 8,
discv5Discovery: true,
discv5BootstrapNodes:

View File

@ -32,21 +32,21 @@ logScope:
# using the when predicate does not work within the contract macro, hence need to dupe
contract(WakuRlnContract):
# this serves as an entrypoint into the rln membership set
proc register(idCommitment: UInt256, userMessageLimit: EthereumUInt32)
proc register(idCommitment: UInt256, userMessageLimit: EthereumUInt32, idCommitmentsToErase: seq[UInt256])
# Initializes the implementation contract (only used in unit tests)
proc initialize(maxMessageLimit: UInt256)
# this event is raised when a new member is registered
proc MemberRegistered(rateCommitment: UInt256, index: EthereumUInt32) {.event.}
proc MembershipRegistered(idCommitment: UInt256, membershipRateLimit: UInt256, index: EthereumUInt32) {.event.}
# this function denotes existence of a given user
proc memberExists(idCommitment: Uint256): UInt256 {.view.}
proc isInMembershipSet(idCommitment: Uint256): bool {.view.}
# this constant describes the next index of a new member
proc commitmentIndex(): UInt256 {.view.}
proc nextFreeIndex(): UInt256 {.view.}
# this constant describes the block number this contract was deployed on
proc deployedBlockNumber(): UInt256 {.view.}
# this constant describes max message limit of rln contract
proc MAX_MESSAGE_LIMIT(): UInt256 {.view.}
proc maxMembershipRateLimit(): UInt256 {.view.}
# this function returns the merkleProof for a given index
proc merkleProofElements(index: Uint256): seq[Uint256] {.view.}
proc getMerkleProof(index: Uint256): seq[Uint256] {.view.}
# this function returns the Merkle root
proc root(): Uint256 {.view.}
@ -94,8 +94,10 @@ proc fetchMerkleProofElements*(
): Future[Result[seq[Uint256], string]] {.async.} =
let index = stuint(g.membershipIndex.get(), 256)
try:
let merkleProofInvocation = g.wakuRlnContract.get().merkleProofElements(index)
let merkleProofInvocation = g.wakuRlnContract.get().getMerkleProof(index)
let merkleProof = await merkleProofInvocation.call()
debug "Fetched Merkle proof",
index = index, merkleProof = merkleProof
return ok(merkleProof)
except CatchableError as e:
error "Failed to fetch merkle proof", errMsg = e.msg
@ -217,12 +219,12 @@ method register*(
g.retryWrapper(gasPrice, "Failed to get gas price"):
int(await ethRpc.provider.eth_gasPrice()) * 2
let idCommitment = identityCredential.idCommitment.toUInt256()
let idCommitmentsToErase: seq[UInt256] = @[]
debug "registering the member",
idCommitment = idCommitment, userMessageLimit = userMessageLimit
idCommitment = idCommitment, userMessageLimit = userMessageLimit, idCommitmentsToErase = idCommitmentsToErase
var txHash: TxHash
g.retryWrapper(txHash, "Failed to register the member"):
await wakuRlnContract.register(idCommitment, userMessageLimit.stuint(32)).send(
await wakuRlnContract.register(idCommitment, userMessageLimit.stuint(32), idCommitmentsToErase).send(
gasPrice = gasPrice
)
@ -239,15 +241,15 @@ method register*(
if tsReceipt.status.isNone() or tsReceipt.status.get() != 1.Quantity:
raise newException(ValueError, "register: transaction failed")
let firstTopic = tsReceipt.logs[0].topics[0]
# the hash of the signature of MemberRegistered(uint256,uint32) event is equal to the following hex value
let firstTopic = tsReceipt.logs[2].topics[0]
# the hash of the signature of MembershipRegistered(uint256,uint256,uint32) event is equal to the following hex value
if firstTopic !=
cast[FixedBytes[32]](keccak.keccak256.digest("MemberRegistered(uint256,uint32)").data):
cast[FixedBytes[32]](keccak.keccak256.digest("MembershipRegistered(uint256,uint256,uint32)").data):
raise newException(ValueError, "register: unexpected event signature")
# the arguments of the raised event i.e., MemberRegistered are encoded inside the data field
# the arguments of the raised event i.e., MembershipRegistered are encoded inside the data field
# data = rateCommitment encoded as 256 bits || index encoded as 32 bits
let arguments = tsReceipt.logs[0].data
let arguments = tsReceipt.logs[2].data
debug "tx log data", arguments = arguments
let
# In TX log data, uints are encoded in big endian
@ -501,9 +503,9 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
# now we check on the contract if the commitment actually has a membership
try:
let membershipExists = await wakuRlnContract
.memberExists(keystoreCred.identityCredential.idCommitment.toUInt256())
.isInMembershipSet(keystoreCred.identityCredential.idCommitment.toUInt256())
.call()
if membershipExists == 0:
if membershipExists == false:
return err("the commitment does not have a membership")
except CatchableError:
return err("failed to check if the commitment has a membership")
@ -521,7 +523,7 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
return err("persisted data: contract address mismatch")
g.rlnRelayMaxMessageLimit =
cast[uint64](await wakuRlnContract.MAX_MESSAGE_LIMIT().call())
cast[uint64](await wakuRlnContract.maxMembershipRateLimit().call())
proc onDisconnect() {.async.} =
error "Ethereum client disconnected"