@@ -207,20 +207,13 @@ contract Decryption is
207207 verifiedPublicDecryptSignatures;
208208 /// @notice Handles of the ciphertexts requested for a public decryption
209209 mapping (uint256 decryptionId = > bytes32 [] ctHandles ) publicCtHandles;
210+ /// @notice The number of public decryption requests, used to generate request IDs (`decryptionId`).
211+ uint256 publicDecryptionCounter;
210212 // ----------------------------------------------------------------------------------------------
211213 // User decryption state variables:
212214 // ----------------------------------------------------------------------------------------------
213- /// @notice Verified signatures for a user decryption.
214- mapping (uint256 decryptionId = > bytes [] verifiedSignatures ) verifiedUserDecryptSignatures;
215215 /// @notice The decryption payloads stored during user decryption requests.
216216 mapping (uint256 decryptionId = > UserDecryptionPayload payload ) userDecryptionPayloads;
217- /// @notice The user decrypted shares received from user decryption responses.
218- mapping (uint256 decryptionId = > bytes [] shares ) userDecryptedShares;
219- // ----------------------------------------------------------------------------------------------
220- // Decryption counters:
221- // ----------------------------------------------------------------------------------------------
222- /// @notice The number of public decryption requests, used to generate request IDs (`decryptionId`).
223- uint256 publicDecryptionCounter;
224217 /// @notice The number of user decryption requests, used to generate request IDs (`decryptionId`)
225218 /// @notice (including delegated user decryption requests).
226219 uint256 userDecryptionCounter;
@@ -572,37 +565,34 @@ contract Decryption is
572565 /// @dev KMS node that has not already signed.
573566 _validateDecryptionResponseEIP712Signature (decryptionId, digest, signature);
574567
575- /// @dev Store the signature for the user decryption response.
576- /// @dev This list is then used to check the consensus. Important: the mapping should not
577- /// @dev consider the digest (contrary to the public decryption case) as shares are expected
578- /// @dev to be different for each KMS node.
579- bytes [] storage verifiedSignatures = $.verifiedUserDecryptSignatures[decryptionId];
580- verifiedSignatures.push (signature);
581-
582- /// @dev Store the user decrypted share for the user decryption response.
583- $.userDecryptedShares[decryptionId].push (userDecryptedShare);
584-
585568 // Store the KMS transaction sender address for the public decryption response
586569 // It is important to consider the same mapping fields used for the consensus
587570 // A "late" valid KMS transaction sender address will still be added in the list.
588571 // We thus use a zero digest (default value for `bytes32`) to still be able to retrieve the
589572 // list later independently of the decryption response type (public or user).
590- $.consensusTxSenderAddresses[decryptionId][0 ].push (msg .sender );
573+ address [] storage txSenderAddresses = $.consensusTxSenderAddresses[decryptionId][0 ];
574+ txSenderAddresses.push (msg .sender );
575+
576+ // Store the user decrypted share for the user decryption response.
577+ // The index of the share is the length of the txSenderAddresses - 1 so that the first response
578+ // associated to this decryptionId has an index of 0.
579+ emit UserDecryptionResponse (
580+ decryptionId,
581+ txSenderAddresses.length - 1 ,
582+ userDecryptedShare,
583+ signature,
584+ extraData
585+ );
591586
592587 // Send the event if and only if the consensus is reached in the current response call.
593588 // This means a "late" response will not be reverted, just ignored and no event will be emitted
594- if (! $.decryptionDone[decryptionId] && _isConsensusReachedUser (verifiedSignatures .length )) {
589+ if (! $.decryptionDone[decryptionId] && _isThresholdReachedUser (txSenderAddresses .length )) {
595590 $.decryptionDone[decryptionId] = true ;
596591
597592 // Since we use the default value for `bytes32`, this means we do not need to store the
598593 // digest in `decryptionConsensusDigest` here like we do for the public decryption case.
599594
600- emit UserDecryptionResponse (
601- decryptionId,
602- $.userDecryptedShares[decryptionId],
603- verifiedSignatures,
604- extraData
605- );
595+ emit UserDecryptionResponseThresholdReached (decryptionId);
606596 }
607597 }
608598
@@ -867,20 +857,20 @@ contract Decryption is
867857 );
868858 }
869859
870- /// @notice Checks if the consensus is reached among the KMS nodes .
871- /// @param kmsCounter The number of KMS nodes that agreed
872- /// @return Whether the consensus is reached
873- function _isConsensusReachedPublic (uint256 kmsCounter ) internal view virtual returns (bool ) {
874- uint256 consensusThreshold = GATEWAY_CONFIG.getPublicDecryptionThreshold ();
875- return kmsCounter >= consensusThreshold ;
860+ /// @notice Indicates if the consensus is reached for public decryption .
861+ /// @param numVerifiedResponses The number of public decryption responses that have been verified.
862+ /// @return Whether the consensus has been reached
863+ function _isConsensusReachedPublic (uint256 numVerifiedResponses ) internal view virtual returns (bool ) {
864+ uint256 publicDecryptionThreshold = GATEWAY_CONFIG.getPublicDecryptionThreshold ();
865+ return numVerifiedResponses >= publicDecryptionThreshold ;
876866 }
877867
878- /// @notice Checks if the consensus for user decryption is reached among the KMS signers .
879- /// @param verifiedSignaturesCount The number of signatures that have been verified for a user decryption .
880- /// @return Whether the consensus is reached.
881- function _isConsensusReachedUser (uint256 verifiedSignaturesCount ) internal view virtual returns (bool ) {
882- uint256 consensusThreshold = GATEWAY_CONFIG.getUserDecryptionThreshold ();
883- return verifiedSignaturesCount >= consensusThreshold ;
868+ /// @notice Indicates if the number of verified user decryption responses has reached the threshold .
869+ /// @param numVerifiedResponses The number of user decryption responses that have been verified.
870+ /// @return Whether the threshold has been reached.
871+ function _isThresholdReachedUser (uint256 numVerifiedResponses ) internal view virtual returns (bool ) {
872+ uint256 userDecryptionThreshold = GATEWAY_CONFIG.getUserDecryptionThreshold ();
873+ return numVerifiedResponses >= userDecryptionThreshold ;
884874 }
885875
886876 /// @notice Check the handles' conformance for public decryption requests.
0 commit comments