diff --git a/src/main/java/org/tron/core/Wallet.java b/src/main/java/org/tron/core/Wallet.java index b66c8200d81..ab450f9825f 100755 --- a/src/main/java/org/tron/core/Wallet.java +++ b/src/main/java/org/tron/core/Wallet.java @@ -921,6 +921,11 @@ public Protocol.ChainParameters getChainParameters() { .setValue(dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059()) .build()); + builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder() + .setKey("getForbidTransferToContract") + .setValue(dbManager.getDynamicPropertiesStore().getForbidTransferToContract()) + .build()); + builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder() .setKey("getAdaptiveResourceLimitTargetRatio") .setValue( diff --git a/src/main/java/org/tron/core/actuator/TransferActuator.java b/src/main/java/org/tron/core/actuator/TransferActuator.java index 9b216723b9c..1acb2d0afb9 100755 --- a/src/main/java/org/tron/core/actuator/TransferActuator.java +++ b/src/main/java/org/tron/core/actuator/TransferActuator.java @@ -124,8 +124,8 @@ public boolean validate() throws ContractValidateException { if (toAccount == null) { fee = fee + dbManager.getDynamicPropertiesStore().getCreateNewAccountFeeInSystemContract(); } - //after TvmSolidity059 proposal, send trx to smartContract by actuator is not allowed. - if (dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059() == 1 + //after ForbidTransferToContract proposal, send trx to smartContract by actuator is not allowed. + if (dbManager.getDynamicPropertiesStore().getForbidTransferToContract() == 1 && toAccount != null && toAccount.getType() == AccountType.Contract) { throw new ContractValidateException("Cannot transfer trx to smartContract."); diff --git a/src/main/java/org/tron/core/actuator/TransferAssetActuator.java b/src/main/java/org/tron/core/actuator/TransferAssetActuator.java index 64177d6ae1d..e49beffc295 100644 --- a/src/main/java/org/tron/core/actuator/TransferAssetActuator.java +++ b/src/main/java/org/tron/core/actuator/TransferAssetActuator.java @@ -166,8 +166,8 @@ public boolean validate() throws ContractValidateException { AccountCapsule toAccount = this.dbManager.getAccountStore().get(toAddress); if (toAccount != null) { - //after TvmSolidity059 proposal, send trx to smartContract by actuator is not allowed. - if (dbManager.getDynamicPropertiesStore().getAllowTvmSolidity059() == 1 + //after ForbidTransferToContract proposal, send trx to smartContract by actuator is not allowed. + if (dbManager.getDynamicPropertiesStore().getForbidTransferToContract() == 1 && toAccount.getType() == AccountType.Contract) { throw new ContractValidateException("Cannot transfer asset to smartContract."); } diff --git a/src/main/java/org/tron/core/config/Parameter.java b/src/main/java/org/tron/core/config/Parameter.java index 706b42f54cd..bc70098a232 100644 --- a/src/main/java/org/tron/core/config/Parameter.java +++ b/src/main/java/org/tron/core/config/Parameter.java @@ -23,7 +23,7 @@ public class ChainConstant { public static final int BLOCK_FILLED_SLOTS_NUMBER = 128; public static final int MAX_VOTE_NUMBER = 30; public static final int MAX_FROZEN_NUMBER = 1; - public static final int BLOCK_VERSION = 9; + public static final int BLOCK_VERSION = 10; } public class NodeConstant { @@ -84,7 +84,8 @@ public enum ForkBlockVersionEnum { VERSION_3_2_2(6), VERSION_3_5(7), VERSION_3_6(8), - VERSION_3_6_5(9); + VERSION_3_6_5(9), + VERSION_3_6_6(10); @Getter private int value; diff --git a/src/main/java/org/tron/core/config/args/Args.java b/src/main/java/org/tron/core/config/args/Args.java index 45b1f92979d..f24b425eb31 100644 --- a/src/main/java/org/tron/core/config/args/Args.java +++ b/src/main/java/org/tron/core/config/args/Args.java @@ -361,6 +361,10 @@ public class Args { @Setter private long allowTvmSolidity059; //committee parameter + @Getter + @Setter + private long forbidTransferToContract; //committee parameter + @Getter @Setter private int tcpNettyWorkThreadNum; @@ -529,6 +533,7 @@ public static void clearParam() { INSTANCE.allowDelegateResource = 0; INSTANCE.allowSameTokenName = 0; INSTANCE.allowTvmSolidity059 = 0; + INSTANCE.forbidTransferToContract = 0; INSTANCE.tcpNettyWorkThreadNum = 0; INSTANCE.udpNettyWorkThreadNum = 0; INSTANCE.p2pNodeId = ""; @@ -888,6 +893,10 @@ public static void setParam(final String[] args, final String confFileName) { config.hasPath("committee.allowTvmSolidity059") ? config .getInt("committee.allowTvmSolidity059") : 0; + INSTANCE.forbidTransferToContract = + config.hasPath("committee.forbidTransferToContract") ? config + .getInt("committee.forbidTransferToContract") : 0; + INSTANCE.tcpNettyWorkThreadNum = config.hasPath("node.tcpNettyWorkThreadNum") ? config .getInt("node.tcpNettyWorkThreadNum") : 0; diff --git a/src/main/java/org/tron/core/db/DynamicPropertiesStore.java b/src/main/java/org/tron/core/db/DynamicPropertiesStore.java index 2f43495bf5a..29468ec4b74 100755 --- a/src/main/java/org/tron/core/db/DynamicPropertiesStore.java +++ b/src/main/java/org/tron/core/db/DynamicPropertiesStore.java @@ -170,6 +170,8 @@ private static class DynamicResourceProperties { private static final byte[] ALLOW_TVM_SOLIDITY_059 = "ALLOW_TVM_SOLIDITY_059".getBytes(); + private static final byte[] FORBID_TRANSFER_TO_CONTRACT = "FORBID_TRANSFER_TO_CONTRACT".getBytes(); + //Used only for protobuf data filter , once,value is 0,1 private static final byte[] ALLOW_PROTO_FILTER_NUM = "ALLOW_PROTO_FILTER_NUM" .getBytes(); @@ -522,6 +524,12 @@ private DynamicPropertiesStore(@Value("properties") String dbName) { this.saveAllowTvmSolidity059(Args.getInstance().getAllowTvmSolidity059()); } + try { + this.getForbidTransferToContract(); + } catch (IllegalArgumentException e) { + this.saveForbidTransferToContract(Args.getInstance().getForbidTransferToContract()); + } + try { this.getAvailableContractType(); } catch (IllegalArgumentException e) { @@ -1378,6 +1386,17 @@ public long getAllowTvmSolidity059() { .orElseThrow(() -> new IllegalArgumentException("not found ALLOW_TVM_SOLIDITY_059")); } + public void saveForbidTransferToContract(long value) { + this.put(FORBID_TRANSFER_TO_CONTRACT, + new BytesCapsule(ByteArray.fromLong(value))); + } + + public long getForbidTransferToContract() { + return Optional.ofNullable(getUnchecked(FORBID_TRANSFER_TO_CONTRACT)) + .map(BytesCapsule::getData) + .map(ByteArray::toLong) + .orElseThrow(() -> new IllegalArgumentException("not found FORBID_TRANSFER_TO_CONTRACT")); + } public void saveAvailableContractType(byte[] value) { diff --git a/src/main/java/org/tron/core/services/ProposalService.java b/src/main/java/org/tron/core/services/ProposalService.java index 8e926d29336..7282bf22ac4 100644 --- a/src/main/java/org/tron/core/services/ProposalService.java +++ b/src/main/java/org/tron/core/services/ProposalService.java @@ -54,7 +54,8 @@ public enum ProposalType { ALLOW_CHANGE_DELEGATION(30), //1, 30 WITNESS_127_PAY_PER_BLOCK(31), //drop, 31 ALLOW_TVM_SOLIDITY_059(32), // 1, 32 - ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO(33); // 10, 33 + ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO(33), // 10, 33 + FORBID_TRANSFER_TO_CONTRACT(35); // 1, 35 ProposalType(long code) { this.code = code; @@ -330,6 +331,22 @@ public static void validator(Manager manager, long code, long value) } break; } + case FORBID_TRANSFER_TO_CONTRACT: { + if (!manager.getForkController().pass(ForkBlockVersionEnum.VERSION_3_6_6)) { + + throw new ContractValidateException(BAD_PARAM_ID); + } + if (value != 1) { + throw new ContractValidateException( + "This value[FORBID_TRANSFER_TO_CONTRACT] is only allowed to be 1"); + } + if (manager.getDynamicPropertiesStore().getAllowCreationOfContracts() == 0) { + throw new ContractValidateException( + "[ALLOW_CREATION_OF_CONTRACTS] proposal must be approved " + + "before [FORBID_TRANSFER_TO_CONTRACT] can be proposed"); + } + break; + } default: break; } @@ -492,6 +509,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule) manager.getDynamicPropertiesStore().saveWitness127PayPerBlock(entry.getValue()); break; } + case FORBID_TRANSFER_TO_CONTRACT: { + manager.getDynamicPropertiesStore().saveForbidTransferToContract(entry.getValue()); + break; + } default: find = false; break; diff --git a/src/test/java/org/tron/core/actuator/TransferActuatorTest.java b/src/test/java/org/tron/core/actuator/TransferActuatorTest.java index d0ee8a05dae..75a5604cd20 100755 --- a/src/test/java/org/tron/core/actuator/TransferActuatorTest.java +++ b/src/test/java/org/tron/core/actuator/TransferActuatorTest.java @@ -466,7 +466,7 @@ public void insufficientFee() { @Test public void transferToSmartContractAddress() throws ContractExeException, ReceiptCheckErrException, VMIllegalException, ContractValidateException, BalanceInsufficientException { - dbManager.getDynamicPropertiesStore().saveAllowTvmSolidity059(1); + dbManager.getDynamicPropertiesStore().saveForbidTransferToContract(1); String contractName = "testContract"; byte[] address = Hex.decode(OWNER_ADDRESS); String ABI = diff --git a/src/test/java/org/tron/core/actuator/TransferAssetActuatorTest.java b/src/test/java/org/tron/core/actuator/TransferAssetActuatorTest.java index 503ccb2678c..22f5b62f43b 100755 --- a/src/test/java/org/tron/core/actuator/TransferAssetActuatorTest.java +++ b/src/test/java/org/tron/core/actuator/TransferAssetActuatorTest.java @@ -1350,7 +1350,7 @@ public void SameTokenNameCloseAssetNameTest() { @Test public void transferToContractAddress() throws ContractExeException, ReceiptCheckErrException, VMIllegalException, ContractValidateException, BalanceInsufficientException { - dbManager.getDynamicPropertiesStore().saveAllowTvmSolidity059(1); + dbManager.getDynamicPropertiesStore().saveForbidTransferToContract(1); createAssertSameTokenNameActive(); VMConfig.initAllowMultiSign(1); VMConfig.initAllowTvmTransferTrc10(1);