From f2520c73394ba64cce9fdbe91b75883a0ae21089 Mon Sep 17 00:00:00 2001 From: ilko-iliev-lime Date: Mon, 13 Nov 2023 11:05:00 +0200 Subject: [PATCH 1/3] Removed static call check (#9672) Signed-off-by: ilko-iliev-lime --- .../impl/exec/systemcontracts/hts/istoken/IsTokenCall.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java index c86794a51e26..c4326e00b55a 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java @@ -62,9 +62,6 @@ public IsTokenCall( private @NonNull FullResult fullResultsFor( @NonNull final ResponseCodeEnum status, final long gasRequirement, final boolean isToken) { // @Future remove to revert #9065 after modularization is completed - if (isStaticCall && status != SUCCESS) { - return revertResult(status, gasRequirement); - } return successResult(IS_TOKEN.getOutputs().encodeElements(status.protoOrdinal(), isToken), gasRequirement); } } From 9afa2049773b4f9df7374e37a0b99c48ee607bac Mon Sep 17 00:00:00 2001 From: ilko-iliev-lime Date: Mon, 13 Nov 2023 11:09:01 +0200 Subject: [PATCH 2/3] Fied TokenAndTypeCheckSuite (#9672) Signed-off-by: ilko-iliev-lime --- .../hts/istoken/IsTokenCall.java | 2 +- .../hts/tokentype/TokenTypeCall.java | 43 +++++++++++++++++++ .../hts/istoken/IsTokenCallTest.java | 12 +----- .../precompile/TokenAndTypeCheckSuite.java | 1 + 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java index c4326e00b55a..ac1581a619c7 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java @@ -56,7 +56,7 @@ public IsTokenCall( @Override protected @NonNull FullResult viewCallResultWith( @NonNull final ResponseCodeEnum status, final long gasRequirement) { - return fullResultsFor(status, gasRequirement, false); + return fullResultsFor(SUCCESS, gasRequirement, false); } private @NonNull FullResult fullResultsFor( diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeCall.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeCall.java index d1e6e7a754d5..87d443fe6792 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeCall.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeCall.java @@ -16,12 +16,19 @@ package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.tokentype; +import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TOKEN_ID; import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS; import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.HederaSystemContract.FullResult.revertResult; import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.HederaSystemContract.FullResult.successResult; +import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.HtsSystemContract.HTS_PRECOMPILE_ADDRESS; +import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCall.PricedResult.gasOnly; import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.tokentype.TokenTypeTranslator.TOKEN_TYPE; +import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.asEvmContractId; +import static com.hedera.node.app.service.contract.impl.utils.SystemContractUtils.contractFunctionResultFailedFor; +import static com.hedera.node.app.service.contract.impl.utils.SystemContractUtils.contractFunctionResultSuccessFor; import static java.util.Objects.requireNonNull; +import com.hedera.hapi.node.base.ContractID; import com.hedera.hapi.node.base.ResponseCodeEnum; import com.hedera.hapi.node.state.token.Token; import com.hedera.node.app.service.contract.impl.exec.gas.SystemContractGasCalculator; @@ -29,8 +36,11 @@ import com.hedera.node.app.service.contract.impl.exec.systemcontracts.HederaSystemContract.FullResult; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.AbstractNonRevertibleTokenViewCall; import com.hedera.node.app.service.contract.impl.hevm.HederaWorldUpdater; +import com.hedera.node.app.service.contract.impl.utils.SystemContractUtils; import edu.umd.cs.findbugs.annotations.NonNull; import edu.umd.cs.findbugs.annotations.Nullable; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Address; public class TokenTypeCall extends AbstractNonRevertibleTokenViewCall { private final boolean isStaticCall; @@ -68,4 +78,37 @@ public TokenTypeCall( } return successResult(TOKEN_TYPE.getOutputs().encodeElements(status.protoOrdinal(), tokenType), gasRequirement); } + + + @Override + public @NonNull PricedResult execute() { + PricedResult result; + long gasRequirement; + Bytes output; + + ContractID contractID = asEvmContractId(Address.fromHexString(HTS_PRECOMPILE_ADDRESS)); + if (token == null) { + result = gasOnly(viewCallResultWith(INVALID_TOKEN_ID, gasCalculator.viewGasRequirement())); + + gasRequirement = result.fullResult().gasRequirement(); + enhancement + .systemOperations() + .externalizeResult( + contractFunctionResultFailedFor(gasRequirement, INVALID_TOKEN_ID.toString(), contractID), + SystemContractUtils.ResultStatus.IS_ERROR, + INVALID_TOKEN_ID); + } else { + result = gasOnly(resultOfViewingToken(token)); + + gasRequirement = result.fullResult().gasRequirement(); + output = result.fullResult().result().getOutput(); + enhancement + .systemOperations() + .externalizeResult( + contractFunctionResultSuccessFor(gasRequirement, output, contractID), + SystemContractUtils.ResultStatus.IS_SUCCESS, + SUCCESS); + } + return result; + } } diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenCallTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenCallTest.java index 6335878d7c34..35e7da763b3a 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenCallTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenCallTest.java @@ -58,18 +58,8 @@ void returnsIsTokenForMissingToken() { assertEquals( Bytes.wrap(IsKycTranslator.IS_KYC .getOutputs() - .encodeElements(INVALID_TOKEN_ID.protoOrdinal(), false) + .encodeElements(SUCCESS.protoOrdinal(), false) .array()), result.getOutput()); } - - @Test - void returnsIsTokenForMissingTokenStaticCall() { - final var subject = new IsTokenCall(gasCalculator, mockEnhancement(), true, null); - - final var result = subject.execute().fullResult().result(); - - assertEquals(MessageFrame.State.REVERT, result.getState()); - assertEquals(revertOutputFor(INVALID_TOKEN_ID), result.getOutput()); - } } diff --git a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenAndTypeCheckSuite.java b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenAndTypeCheckSuite.java index 39c071d08198..28661d0636f7 100644 --- a/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenAndTypeCheckSuite.java +++ b/hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/contract/precompile/TokenAndTypeCheckSuite.java @@ -122,6 +122,7 @@ private HapiSpec checkTokenAndTypeStandardCases() { .then(); } + @HapiTest private HapiSpec checkTokenAndTypeNegativeCases() { final AtomicReference vanillaTokenID = new AtomicReference<>(); final var notAnAddress = new byte[20]; From c2cf0f539432ca663938e259859ba57c95175734 Mon Sep 17 00:00:00 2001 From: ilko-iliev-lime Date: Mon, 13 Nov 2023 11:13:52 +0200 Subject: [PATCH 3/3] Applied spotless (#9672) Signed-off-by: ilko-iliev-lime --- .../impl/exec/systemcontracts/hts/istoken/IsTokenCall.java | 1 - .../impl/exec/systemcontracts/hts/tokentype/TokenTypeCall.java | 1 - .../test/exec/systemcontracts/hts/istoken/IsTokenCallTest.java | 2 -- 3 files changed, 4 deletions(-) diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java index ac1581a619c7..29dfa62fa15f 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/istoken/IsTokenCall.java @@ -17,7 +17,6 @@ package com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.istoken; import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS; -import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.HederaSystemContract.FullResult.revertResult; import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.HederaSystemContract.FullResult.successResult; import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.istoken.IsTokenTranslator.IS_TOKEN; import static java.util.Objects.requireNonNull; diff --git a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeCall.java b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeCall.java index 87d443fe6792..0e9fba5fe92e 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeCall.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/hts/tokentype/TokenTypeCall.java @@ -79,7 +79,6 @@ public TokenTypeCall( return successResult(TOKEN_TYPE.getOutputs().encodeElements(status.protoOrdinal(), tokenType), gasRequirement); } - @Override public @NonNull PricedResult execute() { PricedResult result; diff --git a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenCallTest.java b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenCallTest.java index 35e7da763b3a..2b520442006f 100644 --- a/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenCallTest.java +++ b/hedera-node/hedera-smart-contract-service-impl/src/test/java/com/hedera/node/app/service/contract/impl/test/exec/systemcontracts/hts/istoken/IsTokenCallTest.java @@ -16,10 +16,8 @@ package com.hedera.node.app.service.contract.impl.test.exec.systemcontracts.hts.istoken; -import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_TOKEN_ID; import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS; import static com.hedera.node.app.service.contract.impl.test.TestHelpers.FUNGIBLE_TOKEN; -import static com.hedera.node.app.service.contract.impl.test.TestHelpers.revertOutputFor; import static org.junit.jupiter.api.Assertions.assertEquals; import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.iskyc.IsKycTranslator;