Skip to content

Commit

Permalink
Merge pull request #432 from EYBlockchain/hari/transaction-type-chall…
Browse files Browse the repository at this point in the history
…enge

fix: remove length check in invalid txn typecheck
  • Loading branch information
ChaitanyaKonda authored Feb 8, 2022
2 parents aede5aa + 2aa6331 commit f4811a6
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions nightfall-deployer/contracts/ChallengesUtil.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,19 @@ library ChallengesUtil {
for (uint256 i = 0; i < transaction.proof.length; i++) {
if (transaction.proof[i] == 0) nZeroProof++;
}
uint256 nZeroCompressedSecrets;
for (uint256 i = 0; i < transaction.compressedSecrets.length; i++) {
if (transaction.compressedSecrets[i] == 0) nZeroCompressedSecrets++;
}
require(
(transaction.tokenId == ZERO && transaction.value == 0) ||
transaction.ercAddress == ZERO ||
transaction.recipientAddress != ZERO ||
transaction.commitments[0] == ZERO ||
transaction.commitments[1] != ZERO ||
transaction.commitments.length != 1 ||
transaction.nullifiers.length != 0 ||
transaction.compressedSecrets.length != 0 ||
transaction.nullifiers[0] != ZERO ||
transaction.nullifiers[1] != ZERO ||
nZeroCompressedSecrets != 8 ||
nZeroProof == 4 || // We assume that 3 out of the 4 proof elements can be a valid ZERO. Deals with exception cases
transaction.historicRootBlockNumberL2[0] != 0 ||
transaction.historicRootBlockNumberL2[1] != 0,
Expand Down Expand Up @@ -106,10 +110,8 @@ library ChallengesUtil {
transaction.recipientAddress != ZERO ||
transaction.commitments[0] == ZERO ||
transaction.commitments[1] != ZERO ||
transaction.commitments.length != 1 ||
transaction.nullifiers[0] == ZERO ||
transaction.nullifiers[1] != ZERO ||
transaction.nullifiers.length != 1 ||
nZeroCompressedSecrets == 8 || // We assume that 7 out of the 8 compressed secrets elements can be a valid ZERO. Deals with exception cases
nZeroProof == 4 || // We assume that 3 out of the 4 proof elements can be a valid ZERO. Deals with exception cases
transaction.historicRootBlockNumberL2[1] != 0, // If this is a single, the second historicBlockNumber needs to be zero
Expand Down Expand Up @@ -137,10 +139,8 @@ library ChallengesUtil {
transaction.recipientAddress != ZERO ||
transaction.commitments[0] == ZERO ||
transaction.commitments[1] == ZERO ||
transaction.commitments.length != 2 ||
transaction.nullifiers[0] == ZERO ||
transaction.nullifiers[1] == ZERO ||
transaction.nullifiers.length != 2 ||
nZeroCompressedSecrets == 8 || // We assume that 7 out of the 8 compressed secrets elements can be a valid ZERO. Deals with exception cases
nZeroProof == 4, // We assume that 3 out of the 4 proof elements can be a valid ZERO. Deals with exception cases
'This double transfer transaction type is valid'
Expand All @@ -156,15 +156,19 @@ library ChallengesUtil {
for (uint256 i = 0; i < transaction.proof.length; i++) {
if (transaction.proof[i] == 0) nZeroProof++;
}
uint256 nZeroCompressedSecrets;
for (uint256 i = 0; i < transaction.compressedSecrets.length; i++) {
if (transaction.compressedSecrets[i] == 0) nZeroCompressedSecrets++;
}
require(
(transaction.tokenId == ZERO && transaction.value == 0) ||
transaction.ercAddress == ZERO ||
transaction.recipientAddress == ZERO ||
transaction.commitments.length != 0 ||
transaction.commitments[0] != ZERO ||
transaction.commitments[1] != ZERO ||
transaction.nullifiers[0] == ZERO ||
transaction.nullifiers[1] != ZERO ||
transaction.nullifiers.length != 1 ||
transaction.compressedSecrets.length != 0 ||
nZeroCompressedSecrets != 8 ||
nZeroProof == 4 || // We assume that 3 out of the 4 proof elements can be a valid ZERO. Deals with exception cases
transaction.historicRootBlockNumberL2[1] != 0, // A withdraw has a similar constraint as a single transfer
'This withdraw transaction type is valid'
Expand Down

0 comments on commit f4811a6

Please sign in to comment.