zlsecure3 / review_star

0 stars 0 forks source link

Gas Optimization in `StarNameService` contract `create_name_script` function #48

Open zlsecure3 opened 1 year ago

zlsecure3 commented 1 year ago

subject

Gas Optimization in StarNameService contract create_name_script function

description

Redundant code assert!(table::contains(&name_service_extension.gradient_fee_in_domainname, domain_name), GRADIENT_FEE_NOT_EXIST); let fee_vector = table::borrow(&name_service_extension.gradient_fee_in_domainname, domain_name);

    if (pay_option == 1){
            assert!(table::contains(&name_service_extension.gradient_fee_in_domainname, domain_name), GRADIENT_FEE_NOT_EXIST);
            let fee_vector = table::borrow(&name_service_extension.gradient_fee_in_domainname, domain_name); 
                if ( name_length > vector::length(fee_vector)) {
                    let fee = *vector::borrow(fee_vector, 0);
                    Airdrop::consume(account,fee * duration / 31536000);
                 }else {
                    let fee = *vector::borrow(fee_vector, name_length);
                    Airdrop::consume(account,fee * duration / 31536000);
                }
        } else {
            assert!(table::contains(&name_service_extension.gradient_fee_in_domainname, domain_name), GRADIENT_FEE_NOT_EXIST);
            let fee_vector = table::borrow(&name_service_extension.gradient_fee_in_domainname, domain_name); 
                if ( name_length > vector::length(fee_vector)) {
                    let fee = *vector::borrow(fee_vector, 0);
                    coin::transfer<AptosCoin>(account, @SNS_address, fee * duration / 31536000);
                 } else {
                    let fee = *vector::borrow(fee_vector, name_length);
                    coin::transfer<AptosCoin>(account, @SNS_address, fee * duration / 31536000);
                }
        };

recommendation

Put these two pieces of code before the if judgment

locations

severity

Informational

damage

exploitability

category

Gas Optimization


system_generated: auditor:yekong submission_id:1475606646

zlsecure3 commented 1 year ago

grading (edit)


submission_id:1475606646


review_type:GRADING


result: TBD-yes,no


rating: TBD-123


comment: TBD-Rejected,Accepted by Secure3.


severity: TBD-Critical,Medium,Low,Informational


category:


description:


zlsecure3 commented 1 year ago

client feedback (manual copy)


submission_id:1475606646


review_type:CLIENT_FEEDBACK


result: TBD-yes,no


severity: TBD-Critical,Medium,Low,Informational


comment:


zlsecure3 commented 1 year ago

client feedback decision(edit)


submission_id:1475606646


review_type:CLIENT_FEEDBACK_DECISION


result: TBD-yes,no,yes-honored,no-honored


severity: TBD-Critical,Medium,Low,Informational


comment: