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 ;
@@ -218,6 +220,9 @@ public void execute(Object object) throws ContractExeException {
218220 } else {
219221 result .spendEnergy (saveCodeEnergy );
220222 if (VMConfig .allowTvmConstantinople ()) {
223+ CreateSmartContract createContract =
224+ ContractCapsule .getSmartContractFromTransaction (trx );
225+ checkContractHashFields (createContract .getNewContract ());
221226 rootRepository .saveCode (program .getContractAddress ().getNoLeadZeroesData (), code );
222227 }
223228 }
@@ -331,6 +336,7 @@ private void create()
331336 if (contract == null ) {
332337 throw new ContractValidateException ("Cannot get CreateSmartContract from transaction" );
333338 }
339+
334340 SmartContract newSmartContract ;
335341 if (VMConfig .allowTvmCompatibleEvm ()) {
336342 newSmartContract = contract .getNewContract ().toBuilder ().setVersion (1 ).build ();
@@ -342,11 +348,7 @@ private void create()
342348 throw new ContractValidateException ("OwnerAddress is not equals OriginAddress" );
343349 }
344350
345- byte [] contractName = newSmartContract .getName ().getBytes ();
346-
347- if (contractName .length > VMConstant .CONTRACT_NAME_LENGTH ) {
348- throw new ContractValidateException ("contractName's length cannot be greater than 32" );
349- }
351+ checkContractNameLength (contract .getNewContract ());
350352
351353 long percent = contract .getNewContract ().getConsumeUserResourcePercent ();
352354 if (percent < 0 || percent > VMConstant .ONE_HUNDRED ) {
@@ -456,6 +458,22 @@ private void create()
456458
457459 }
458460
461+ static void checkContractHashFields (SmartContract contract ) {
462+ if (!contract .getCodeHash ().isEmpty () || !contract .getTrxHash ().isEmpty ()) {
463+ MUtil .checkCPUTimeForContractHashFields ();
464+ }
465+ }
466+
467+ static void checkContractNameLength (SmartContract contract ) throws ContractValidateException {
468+ int contractNameLength =
469+ ForkController .instance ().pass (Parameter .ForkBlockVersionEnum .VERSION_4_8_2_2 )
470+ ? contract .getNameBytes ().size ()
471+ : contract .getName ().getBytes ().length ;
472+ if (contractNameLength > VMConstant .CONTRACT_NAME_LENGTH ) {
473+ throw new ContractValidateException ("contractName's length cannot be greater than 32" );
474+ }
475+ }
476+
459477 /**
460478 * **
461479 */
0 commit comments