From 4318bc7bc297513ba6d10a28867db0d2e18d9a1c Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Fri, 29 Mar 2024 12:27:33 +0000 Subject: [PATCH] Check checksum --- circuits/auth/authV2.circom | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/circuits/auth/authV2.circom b/circuits/auth/authV2.circom index 7fe9efb..d55bb85 100644 --- a/circuits/auth/authV2.circom +++ b/circuits/auth/authV2.circom @@ -136,18 +136,28 @@ template checkAuthV2(IdOwnershipLevels, onChainLevels) { challengeSignatureS ); - /* Check on-chain SMT inclusion existence */ - signal cutId <== cutId()(genesisID); + /* Check if state is genesis and if genesisId is valid */ signal cutState <== cutState()(state); - signal isStateGenesis <== IsEqual()([cutId, cutState]); + component genesisIdParts = SplitID(); + genesisIdParts.id <== genesisID; + + signal calculatedChecksum <== CalculateIdChecksum()(genesisIdParts.typ, genesisIdParts.genesis); + ForceEqualIfEnabled()( + enabled, + [genesisIdParts.checksum, calculatedChecksum] + ); + + signal isStateGenesis <== IsEqual()([genesisIdParts.genesis, cutState]); + + /* Check on-chain SMT inclusion existence */ signal genesisIDHash <== Poseidon(1)([genesisID]); SMTVerifier(onChainLevels)( enabled <== enabled, - fnc <== isStateGenesis, // non-inclusion in case if genesis state, otherwise inclusion + fnc <== isStateGenesis, // non-inclusion in case of genesis state, otherwise inclusion root <== gistRoot, siblings <== gistMtp, oldKey <== gistMtpAuxHi,