2525import org .tron .common .runtime .InternalTransaction .TrxType ;
2626import org .tron .common .runtime .ProgramResult ;
2727import org .tron .common .runtime .vm .DataWord ;
28+ import org .tron .common .utils .ForkController ;
2829import org .tron .common .utils .StorageUtils ;
2930import org .tron .common .utils .StringUtil ;
3031import org .tron .common .utils .WalletUtil ;
3334import org .tron .core .capsule .BlockCapsule ;
3435import org .tron .core .capsule .ContractCapsule ;
3536import org .tron .core .capsule .ReceiptCapsule ;
37+ import org .tron .core .config .Parameter ;
3638import org .tron .core .db .EnergyProcessor ;
3739import org .tron .core .db .TransactionContext ;
3840import org .tron .core .exception .ContractExeException ;
@@ -217,6 +219,9 @@ public void execute(Object object) throws ContractExeException {
217219 } else {
218220 result .spendEnergy (saveCodeEnergy );
219221 if (VMConfig .allowTvmConstantinople ()) {
222+ CreateSmartContract createContract =
223+ ContractCapsule .getSmartContractFromTransaction (trx );
224+ checkContractHashFields (createContract .getNewContract ());
220225 rootRepository .saveCode (program .getContractAddress ().getNoLeadZeroesData (), code );
221226 }
222227 }
@@ -330,6 +335,7 @@ private void create()
330335 if (contract == null ) {
331336 throw new ContractValidateException ("Cannot get CreateSmartContract from transaction" );
332337 }
338+
333339 SmartContract newSmartContract ;
334340 if (VMConfig .allowTvmCompatibleEvm ()) {
335341 newSmartContract = contract .getNewContract ().toBuilder ().setVersion (1 ).build ();
@@ -341,11 +347,7 @@ private void create()
341347 throw new ContractValidateException ("OwnerAddress is not equals OriginAddress" );
342348 }
343349
344- byte [] contractName = newSmartContract .getName ().getBytes ();
345-
346- if (contractName .length > VMConstant .CONTRACT_NAME_LENGTH ) {
347- throw new ContractValidateException ("contractName's length cannot be greater than 32" );
348- }
350+ checkContractNameLength (contract .getNewContract ());
349351
350352 long percent = contract .getNewContract ().getConsumeUserResourcePercent ();
351353 if (percent < 0 || percent > VMConstant .ONE_HUNDRED ) {
@@ -455,6 +457,22 @@ private void create()
455457
456458 }
457459
460+ static void checkContractHashFields (SmartContract contract ) {
461+ if (!contract .getCodeHash ().isEmpty () || !contract .getTrxHash ().isEmpty ()) {
462+ MUtil .checkCPUTimeForContractHashFields ();
463+ }
464+ }
465+
466+ static void checkContractNameLength (SmartContract contract ) throws ContractValidateException {
467+ int contractNameLength =
468+ ForkController .instance ().pass (Parameter .ForkBlockVersionEnum .VERSION_4_8_2_2 )
469+ ? contract .getNameBytes ().size ()
470+ : contract .getName ().getBytes ().length ;
471+ if (contractNameLength > VMConstant .CONTRACT_NAME_LENGTH ) {
472+ throw new ContractValidateException ("contractName's length cannot be greater than 32" );
473+ }
474+ }
475+
458476 /**
459477 * **
460478 */
0 commit comments