fix(rln-relay): on chain registration (#1627)

* fix(rln-relay): on chain registration

* fix(rln-relay): bump gas lim
This commit is contained in:
Aaryamann Challani 2023-03-29 14:22:57 +05:30 committed by GitHub
parent 85f33a8efd
commit b1bafda2ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -111,15 +111,16 @@ method register*(g: OnchainGroupManager, identityCredentials: IdentityCredential
var txHash: TxHash var txHash: TxHash
try: # send the registration transaction and check if any error occurs try: # send the registration transaction and check if any error occurs
txHash = await rlnContract.register(idCommitment).send(value = membershipFee, txHash = await rlnContract.register(idCommitment).send(value = membershipFee,
gasPrice = gasPrice) gasPrice = gasPrice,
gas = 100000'u64)
except ValueError as e: except ValueError as e:
error "error while registering the member", msg = e.msg
raise newException(ValueError, "could not register the member: " & e.msg) raise newException(ValueError, "could not register the member: " & e.msg)
# wait for the transaction to be mined # wait for the transaction to be mined
let tsReceipt = await ethRpc.getMinedTransactionReceipt(txHash) let tsReceipt = await ethRpc.getMinedTransactionReceipt(txHash)
g.registrationTxHash = some(txHash) g.registrationTxHash = some(txHash)
# the receipt topic holds the hash of signature of the raised events # the receipt topic holds the hash of signature of the raised events
# TODO: make this robust. search within the event list for the event # TODO: make this robust. search within the event list for the event
let firstTopic = tsReceipt.logs[0].topics[0] let firstTopic = tsReceipt.logs[0].topics[0]
@ -223,7 +224,7 @@ proc seedBlockTableIntoTree*(g: OnchainGroupManager, blockTable: BlockTable): Fu
except: except:
error "failed to insert members into the tree" error "failed to insert members into the tree"
raise newException(ValueError, "failed to insert members into the tree") raise newException(ValueError, "failed to insert members into the tree")
debug "new members added to the Merkle tree", commitments=members.mapIt(it.idCommitment.inHex()) , startingIndex=startingIndex trace "new members added to the Merkle tree", commitments=members.mapIt(it.idCommitment.inHex()) , startingIndex=startingIndex
let lastIndex = startingIndex + members.len.uint - 1 let lastIndex = startingIndex + members.len.uint - 1
let indexGap = startingIndex - latestIndex let indexGap = startingIndex - latestIndex
if not (toSeq(startingIndex..lastIndex) == members.mapIt(it.index)): if not (toSeq(startingIndex..lastIndex) == members.mapIt(it.index)):
@ -364,6 +365,15 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} =
let chainId = await ethRpc.provider.eth_chainId() let chainId = await ethRpc.provider.eth_chainId()
g.chainId = some(chainId) g.chainId = some(chainId)
if g.ethPrivateKey.isSome():
let pk = g.ethPrivateKey.get()
let pkParseRes = keys.PrivateKey.fromHex(pk)
if pkParseRes.isErr():
raise newException(ValueError, "could not parse the private key")
ethRpc.privateKey = some(pkParseRes.get())
ethRpc.defaultAccount = ethRpc.privateKey.get().toPublicKey().toCanonicalAddress().Address
let contractAddress = web3.fromHex(web3.Address, g.ethContractAddress) let contractAddress = web3.fromHex(web3.Address, g.ethContractAddress)
contract = ethRpc.contractSender(RlnContract, contractAddress) contract = ethRpc.contractSender(RlnContract, contractAddress)
@ -374,12 +384,6 @@ method init*(g: OnchainGroupManager): Future[void] {.async.} =
except: except:
raise newException(ValueError, "could not get the membership deposit") raise newException(ValueError, "could not get the membership deposit")
if g.ethPrivateKey.isSome():
let pk = g.ethPrivateKey.get()
let pkParseRes = keys.PrivateKey.fromHex(pk)
if pkParseRes.isErr():
raise newException(ValueError, "could not parse the private key")
ethRpc.privateKey = some(pkParseRes.get())
g.ethRpc = some(ethRpc) g.ethRpc = some(ethRpc)
g.rlnContract = some(contract) g.rlnContract = some(contract)

View File

@ -104,7 +104,6 @@ proc poseidon*(data: seq[seq[byte]]): RlnRelayResult[array[32, byte]] =
var var
hashInputBuffer = inputBytes.toBuffer() hashInputBuffer = inputBytes.toBuffer()
outputBuffer: Buffer # will holds the hash output outputBuffer: Buffer # will holds the hash output
trace "poseidon hash input", hashInputBuffer = hashInputBuffer, inputBytes = inputBytes, bufflen = hashInputBuffer.len
let let
hashSuccess = poseidon(addr hashInputBuffer, addr outputBuffer) hashSuccess = poseidon(addr hashInputBuffer, addr outputBuffer)