Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for deleted accounts in crypto allowances #8834

Merged
merged 11 commits into from
Oct 3, 2023
Prev Previous commit
Next Next commit
Fix aggregation of nft delete allowances
Signed-off-by: Matt Hess <matt.hess@swirldslabs.com>
  • Loading branch information
mhess-swl committed Sep 22, 2023
commit cf0ace62b6d0f4d554b0b96446066b07956ea750
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public void preHandle(@NonNull final PreHandleContext context) throws PreCheckEx
pureChecks(txn);
final var op = txn.cryptoDeleteAllowanceOrThrow();
// Every owner whose allowances are being removed should sign (or the payer, if there is no owner)
final var payerId = txn.transactionID().accountID();
for (final var allowance : op.nftAllowancesOrElse(emptyList())) {
if (allowance.hasOwner()) {
context.requireKeyOrThrow(allowance.ownerOrThrow(), INVALID_ALLOWANCE_OWNER_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import com.hedera.node.app.spi.workflows.HandleContext;
import com.hedera.node.config.data.HederaConfig;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.HashSet;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
Expand Down Expand Up @@ -148,11 +147,8 @@ private void validateAllowancesCount(
*/
public static int aggregateNftDeleteAllowances(final List<NftRemoveAllowance> nftAllowances) {
var count = 0;
final var serialsSet = new HashSet<Long>();
for (final var allowance : nftAllowances) {
serialsSet.addAll(allowance.serialNumbers());
count += serialsSet.size();
serialsSet.clear();
count += allowance.serialNumbers().size();
}
return count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ALLOWANCE_OWNER_ID;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_TOKEN_NFT_SERIAL_NUMBER;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_ALLOWANCES_EXCEEDED;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SENDER_DOES_NOT_OWN_NFT_SERIAL_NO;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.TOKEN_NOT_ASSOCIATED_TO_ACCOUNT;
import static com.hederahashgraph.api.proto.java.TokenType.NON_FUNGIBLE_UNIQUE;
Expand Down Expand Up @@ -509,30 +508,28 @@ private HapiSpec exceedsTransactionLimit() {
List.of(
ByteString.copyFromUtf8("a"),
ByteString.copyFromUtf8("b"),
ByteString.copyFromUtf8("c"),
ByteString.copyFromUtf8("d"),
ByteString.copyFromUtf8("e")))
ByteString.copyFromUtf8("c")))
.via("nftTokenMint"),
mintToken(token, 500L).via("tokenMint"),
cryptoTransfer(movingUnique(nft, 1L, 2L, 3L, 4L, 5L).between(TOKEN_TREASURY, owner)))
cryptoTransfer(movingUnique(nft, 1L, 2L, 3L).between(TOKEN_TREASURY, owner)))
.when(
cryptoApproveAllowance()
.payingWith(owner)
.addNftAllowance(owner, nft, spender, false, List.of(1L, 2L)),
cryptoDeleteAllowance()
.payingWith(owner)
.addNftDeleteAllowance(owner, nft, List.of(1L, 1L, 1L, 1L, 1L))
.hasPrecheck(OK),
.addNftDeleteAllowance(owner, nft, List.of(1L, 2L, 3L, 3L, 3L))
.hasPrecheck(MAX_ALLOWANCES_EXCEEDED),
cryptoDeleteAllowance()
.payingWith(owner)
.addNftDeleteAllowance(owner, nft, List.of(1L, 2L, 3L, 4L, 5L))
.addNftDeleteAllowance(owner, nft, List.of(1L, 1L, 1L, 1L, 1L))
.hasPrecheck(MAX_ALLOWANCES_EXCEEDED),
cryptoDeleteAllowance()
.payingWith(owner)
.addNftDeleteAllowance(owner, nft, List.of(1L))
.addNftDeleteAllowance(owner, nft, List.of(2L))
.addNftDeleteAllowance(owner, nft, List.of(3L))
.addNftDeleteAllowance(owner, nft, List.of(4L))
.addNftDeleteAllowance(owner, nft, List.of(1L))
.addNftDeleteAllowance(owner, nft, List.of(1L))
.hasPrecheck(MAX_ALLOWANCES_EXCEEDED))
.then(
Expand Down