@@ -208,12 +208,8 @@ contract Decryption is
208208 // ----------------------------------------------------------------------------------------------
209209 // User decryption state variables:
210210 // ----------------------------------------------------------------------------------------------
211- /// @notice Verified signatures for a user decryption.
212- mapping (uint256 decryptionId = > bytes [] verifiedSignatures ) verifiedUserDecryptSignatures;
213211 /// @notice The decryption payloads stored during user decryption requests.
214212 mapping (uint256 decryptionId = > UserDecryptionPayload payload ) userDecryptionPayloads;
215- /// @notice The user decrypted shares received from user decryption responses.
216- mapping (uint256 decryptionId = > bytes [] shares ) userDecryptedShares;
217213 }
218214
219215 /// @dev Storage location has been computed using the following command:
@@ -546,37 +542,34 @@ contract Decryption is
546542 /// @dev KMS node that has not already signed.
547543 _validateDecryptionResponseEIP712Signature (decryptionId, digest, signature);
548544
549- /// @dev Store the signature for the user decryption response.
550- /// @dev This list is then used to check the consensus. Important: the mapping should not
551- /// @dev consider the digest (contrary to the public decryption case) as shares are expected
552- /// @dev to be different for each KMS node.
553- bytes [] storage verifiedSignatures = $.verifiedUserDecryptSignatures[decryptionId];
554- verifiedSignatures.push (signature);
555-
556- /// @dev Store the user decrypted share for the user decryption response.
557- $.userDecryptedShares[decryptionId].push (userDecryptedShare);
558-
559545 // Store the KMS transaction sender address for the public decryption response
560546 // It is important to consider the same mapping fields used for the consensus
561547 // A "late" valid KMS transaction sender address will still be added in the list.
562548 // We thus use a zero digest (default value for `bytes32`) to still be able to retrieve the
563549 // list later independently of the decryption response type (public or user).
564- $.consensusTxSenderAddresses[decryptionId][0 ].push (msg .sender );
550+ address [] storage txSenderAddresses = $.consensusTxSenderAddresses[decryptionId][0 ];
551+ txSenderAddresses.push (msg .sender );
552+
553+ // Store the user decrypted share for the user decryption response.
554+ // The index of the share is the length of the txSenderAddresses - 1 so that the first response
555+ // associated to this decryptionId has an index of 0.
556+ emit UserDecryptionResponse (
557+ decryptionId,
558+ txSenderAddresses.length - 1 ,
559+ userDecryptedShare,
560+ signature,
561+ extraData
562+ );
565563
566564 // Send the event if and only if the consensus is reached in the current response call.
567565 // This means a "late" response will not be reverted, just ignored and no event will be emitted
568- if (! $.decryptionDone[decryptionId] && _isConsensusReachedUser (verifiedSignatures .length )) {
566+ if (! $.decryptionDone[decryptionId] && _isThresholdReachedUser (txSenderAddresses .length )) {
569567 $.decryptionDone[decryptionId] = true ;
570568
571569 // Since we use the default value for `bytes32`, this means we do not need to store the
572570 // digest in `decryptionConsensusDigest` here like we do for the public decryption case.
573571
574- emit UserDecryptionResponse (
575- decryptionId,
576- $.userDecryptedShares[decryptionId],
577- verifiedSignatures,
578- extraData
579- );
572+ emit UserDecryptionResponseThresholdReached (decryptionId);
580573 }
581574 }
582575
@@ -840,20 +833,20 @@ contract Decryption is
840833 );
841834 }
842835
843- /// @notice Checks if the consensus is reached among the KMS nodes .
844- /// @param kmsCounter The number of KMS nodes that agreed
845- /// @return Whether the consensus is reached
846- function _isConsensusReachedPublic (uint256 kmsCounter ) internal view virtual returns (bool ) {
847- uint256 consensusThreshold = GATEWAY_CONFIG.getPublicDecryptionThreshold ();
848- return kmsCounter >= consensusThreshold ;
836+ /// @notice Indicates if the consensus is reached for public decryption .
837+ /// @param numVerifiedResponses The number of public decryption responses that have been verified.
838+ /// @return Whether the consensus has been reached
839+ function _isConsensusReachedPublic (uint256 numVerifiedResponses ) internal view virtual returns (bool ) {
840+ uint256 publicDecryptionThreshold = GATEWAY_CONFIG.getPublicDecryptionThreshold ();
841+ return numVerifiedResponses >= publicDecryptionThreshold ;
849842 }
850843
851- /// @notice Checks if the consensus for user decryption is reached among the KMS signers .
852- /// @param verifiedSignaturesCount The number of signatures that have been verified for a user decryption .
853- /// @return Whether the consensus is reached.
854- function _isConsensusReachedUser (uint256 verifiedSignaturesCount ) internal view virtual returns (bool ) {
855- uint256 consensusThreshold = GATEWAY_CONFIG.getUserDecryptionThreshold ();
856- return verifiedSignaturesCount >= consensusThreshold ;
844+ /// @notice Indicates if the number of verified user decryption responses has reached the threshold .
845+ /// @param numVerifiedResponses The number of user decryption responses that have been verified.
846+ /// @return Whether the threshold has been reached.
847+ function _isThresholdReachedUser (uint256 numVerifiedResponses ) internal view virtual returns (bool ) {
848+ uint256 userDecryptionThreshold = GATEWAY_CONFIG.getUserDecryptionThreshold ();
849+ return numVerifiedResponses >= userDecryptionThreshold ;
857850 }
858851
859852 /// @notice Check the handles' conformance for public decryption requests.
0 commit comments