mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 14:03:06 +00:00
Testing zerokit PR
This commit is contained in:
parent
7123c5532c
commit
6f32375894
2
Makefile
2
Makefile
@ -177,7 +177,7 @@ nimbus-build-system-nimble-dir:
|
||||
.PHONY: librln
|
||||
|
||||
LIBRLN_BUILDDIR := $(CURDIR)/vendor/zerokit
|
||||
LIBRLN_VERSION := v0.7.0
|
||||
LIBRLN_VERSION := v0.8.0
|
||||
|
||||
ifeq ($(detected_OS),Windows)
|
||||
LIBRLN_FILE := rln.lib
|
||||
|
||||
@ -205,20 +205,20 @@ suite "Onchain group manager":
|
||||
(waitFor manager.init()).isOkOr:
|
||||
raiseAssert $error
|
||||
|
||||
let idCommitment = generateCredentials(manager.rlnInstance).idCommitment
|
||||
let merkleRootBefore = manager.fetchMerkleRoot()
|
||||
let idCredentials = generateCredentials(manager.rlnInstance)
|
||||
let merkleRootBefore = (waitFor manager.fetchMerkleRoot()).valueOr:
|
||||
raiseAssert "Failed to fetch merkle root: " & $error
|
||||
|
||||
try:
|
||||
waitFor manager.register(
|
||||
RateCommitment(
|
||||
idCommitment: idCommitment, userMessageLimit: UserMessageLimit(20)
|
||||
)
|
||||
)
|
||||
debug "Registering commitment", idCommitment = idCredentials.idCommitment
|
||||
waitFor manager.register(idCredentials, UserMessageLimit(20))
|
||||
except Exception, CatchableError:
|
||||
assert false,
|
||||
"exception raised when calling register: " & getCurrentExceptionMsg()
|
||||
|
||||
let merkleRootAfter = manager.fetchMerkleRoot()
|
||||
|
||||
debug "Fetching Merkle root after registration"
|
||||
let merkleRootAfter = (waitFor manager.fetchMerkleRoot()).valueOr:
|
||||
raiseAssert "Failed to fetch merkle root: " & $error
|
||||
|
||||
check:
|
||||
merkleRootAfter != merkleRootBefore
|
||||
|
||||
2
vendor/zerokit
vendored
2
vendor/zerokit
vendored
@ -1 +1 @@
|
||||
Subproject commit ba467d370c56b7432522227de22fbd664d44ef3e
|
||||
Subproject commit 2749be14c60a129ffb1757be22d706c07629d7c0
|
||||
@ -30,7 +30,7 @@ proc toUInt256*(idCommitment: IDCommitment): UInt256 =
|
||||
return pk
|
||||
|
||||
proc toIDCommitment*(idCommitmentUint: UInt256): IDCommitment =
|
||||
let pk = IDCommitment(@(idCommitmentUint.toBytesLE()))
|
||||
let pk = IDCommitment(@(idCommitmentUint.toBytesBE()))
|
||||
return pk
|
||||
|
||||
type MembershipIndex* = uint
|
||||
@ -53,16 +53,16 @@ proc toIdentityCredentials*(
|
||||
try:
|
||||
let
|
||||
idTrapdoor = IdentityTrapdoor(
|
||||
@(hexToUint[CredentialByteSize](groupKeys[i][0]).toBytesLE())
|
||||
@(hexToUint[CredentialByteSize](groupKeys[i][0]).toBytesBE())
|
||||
)
|
||||
idNullifier = IdentityNullifier(
|
||||
@(hexToUint[CredentialByteSize](groupKeys[i][1]).toBytesLE())
|
||||
@(hexToUint[CredentialByteSize](groupKeys[i][1]).toBytesBE())
|
||||
)
|
||||
idSecretHash = IdentitySecretHash(
|
||||
@(hexToUint[CredentialByteSize](groupKeys[i][2]).toBytesLE())
|
||||
@(hexToUint[CredentialByteSize](groupKeys[i][2]).toBytesBE())
|
||||
)
|
||||
idCommitment =
|
||||
IDCommitment(@(hexToUint[CredentialByteSize](groupKeys[i][3]).toBytesLE()))
|
||||
IDCommitment(@(hexToUint[CredentialByteSize](groupKeys[i][3]).toBytesBE()))
|
||||
groupIdCredentials.add(
|
||||
IdentityCredential(
|
||||
idTrapdoor: idTrapdoor,
|
||||
|
||||
@ -304,7 +304,9 @@ method register*(
|
||||
var gasPrice: int
|
||||
g.retryWrapper(gasPrice, "Failed to get gas price"):
|
||||
int(await ethRpc.provider.eth_gasPrice()) * 2
|
||||
let idCommitmentBytes = identityCredential.idCommitment
|
||||
let idCommitmentHex = identityCredential.idCommitment.inHex()
|
||||
debug "identityCredential idCommitmentBytes", idCommitmentBytes = idCommitmentBytes
|
||||
debug "identityCredential idCommitmentHex", idCommitment = idCommitmentHex
|
||||
let idCommitment = identityCredential.idCommitment.toUInt256()
|
||||
let idCommitmentsToErase: seq[UInt256] = @[]
|
||||
@ -577,11 +579,11 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
|
||||
# check if the Ethereum client is reachable
|
||||
let ethRpc: Web3 = (await establishConnection(g)).valueOr:
|
||||
return err("failed to connect to Ethereum clients: " & $error)
|
||||
|
||||
debug "initializing OnchainGroupManager"
|
||||
var fetchedChainId: UInt256
|
||||
g.retryWrapper(fetchedChainId, "Failed to get the chain id"):
|
||||
await ethRpc.provider.eth_chainId()
|
||||
|
||||
debug "fetched chain id", fetchedChainId = fetchedChainId
|
||||
# Set the chain id
|
||||
if g.chainId == 0:
|
||||
warn "Chain ID not set in config, using RPC Provider's Chain ID",
|
||||
@ -610,6 +612,8 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
|
||||
g.wakuRlnContract = some(wakuRlnContract)
|
||||
|
||||
if g.keystorePath.isSome() and g.keystorePassword.isSome():
|
||||
debug "Using existing keystore credentials",
|
||||
keystorePath = g.keystorePath.get()
|
||||
if not fileExists(g.keystorePath.get()):
|
||||
error "File provided as keystore path does not exist", path = g.keystorePath.get()
|
||||
return err("File provided as keystore path does not exist")
|
||||
@ -642,6 +646,8 @@ method init*(g: OnchainGroupManager): Future[GroupManagerResult[void]] {.async.}
|
||||
try:
|
||||
let commitmentBytes = keystoreCred.identityCredential.idCommitment
|
||||
let params = commitmentBytes.reversed()
|
||||
debug "Reversing idCommitment bytes when sending as param to verify if membership exists",
|
||||
commitment = idCommitmentHex, params = params
|
||||
let resultBytes = await sendEthCallWithParams(
|
||||
ethRpc = g.ethRpc.get(),
|
||||
functionSignature = "isInMembershipSet(uint256)",
|
||||
|
||||
@ -27,7 +27,7 @@ type
|
||||
RawRateCommitment* = seq[byte]
|
||||
|
||||
proc toRateCommitment*(rateCommitmentUint: UInt256): RawRateCommitment =
|
||||
return RawRateCommitment(@(rateCommitmentUint.toBytesLE()))
|
||||
return RawRateCommitment(@(rateCommitmentUint.toBytesBE()))
|
||||
|
||||
# Custom data types defined for waku rln relay -------------------------
|
||||
type RateLimitProof* = object
|
||||
|
||||
@ -101,6 +101,10 @@ proc key_gen*(
|
||||
ctx: ptr RLN, output_buffer: ptr Buffer
|
||||
): bool {.importc: "extended_key_gen".}
|
||||
|
||||
proc key_gen_be*(
|
||||
ctx: ptr RLN, output_buffer: ptr Buffer
|
||||
): bool {.importc: "extended_key_gen_be".}
|
||||
|
||||
## generates identity trapdoor, identity nullifier, identity secret hash and id commitment tuple serialized inside output_buffer as | identity_trapdoor<32> | identity_nullifier<32> | identity_secret_hash<32> | id_commitment<32> |
|
||||
## identity secret hash is the poseidon hash of [identity_trapdoor, identity_nullifier]
|
||||
## id commitment is the poseidon hash of the identity secret hash
|
||||
@ -158,8 +162,7 @@ proc verify*(
|
||||
|
||||
proc verify_with_roots*(
|
||||
ctx: ptr RLN,
|
||||
proof_buffer: ptr Buffer,
|
||||
roots_buffer: ptr Buffer,
|
||||
proof_buffer: ptr Buffer, roots_buffer: ptr Buffer,
|
||||
proof_is_valid_ptr: ptr bool,
|
||||
): bool {.importc: "verify_with_roots".}
|
||||
|
||||
|
||||
@ -22,13 +22,14 @@ proc membershipKeyGen*(ctxPtr: ptr RLN): RlnRelayResult[IdentityCredential] =
|
||||
var
|
||||
keysBuffer: Buffer
|
||||
keysBufferPtr = addr(keysBuffer)
|
||||
done = key_gen(ctxPtr, keysBufferPtr)
|
||||
done = key_gen_be(ctxPtr, keysBufferPtr)
|
||||
|
||||
# check whether the keys are generated successfully
|
||||
if (done == false):
|
||||
return err("error in key generation")
|
||||
|
||||
if (keysBuffer.len != 4 * 32):
|
||||
debug "keysBuffer is of invalid length", keysBufferLen = keysBuffer.len
|
||||
return err("keysBuffer is of invalid length")
|
||||
|
||||
var generatedKeys = cast[ptr array[4 * 32, byte]](keysBufferPtr.`ptr`)[]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user