Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currently useless CodeValidator's method validate_program #4462

Closed
ecol-master opened this issue Jan 22, 2025 · 2 comments · Fixed by #4485
Closed

Currently useless CodeValidator's method validate_program #4462

ecol-master opened this issue Jan 22, 2025 · 2 comments · Fixed by #4485
Assignees
Labels
C2-refactoring Refactoring proposal D5-tooling Helper tools and utilities D7-performance Increase our node/runtime/programs execution work performance

Comments

@ecol-master
Copy link
Contributor

File Location(s)

Source file: utils/wasm-builder/src/code_validator.rs

impl CodeValidator {
    pub fn validate_program(self) -> anyhow::Result<()> {
        match Code::try_new(
            self.code,
            1,
            |_| CustomConstantCostRules::default(),
            None,
            None,
            None,
        ) {
            Err(code_error) => Err(CodeErrorWithContext::from((self.module, code_error)))?,
            _ => Ok(()),
        }
    }
    ...
}

Proposal

Currently, the validate_program method in the CodeValidator class is ineffective. All the parameters which are influnce to validation are set to None, and there is no actual validation of the program’s code being performed.

I propose to add something likeWasmProjectSetting with fields like: code_validation: true.
It will help to increase performance in code postprocessing

Source: utils/wasm-builder/src/wasm_project.rs line 514:

for (wasm_path, _) in &wasm_files {
    let code = fs::read(wasm_path)?;
    let validator = CodeValidator::try_from(code)?;

    if self.project_type.is_metawasm() {
        validator.validate_metawasm()?;
    } else {
        validator.validate_program()?;
    }
}
@ecol-master ecol-master added C2-refactoring Refactoring proposal D5-tooling Helper tools and utilities D7-performance Increase our node/runtime/programs execution work performance labels Jan 22, 2025
@ecol-master ecol-master self-assigned this Jan 22, 2025
@StackOverflowExcept1on
Copy link
Member

You can fix this using gear_core::gas_metering, specifically Schedule. It is necessary to copy pallet-gear.

gear/pallets/gear/src/lib.rs

Lines 1163 to 1170 in 25a331d

let code = Code::try_new(
code,
schedule.instruction_weights.version,
|module| schedule.rules(module),
schedule.limits.stack_height,
schedule.limits.data_segments_amount.into(),
schedule.limits.table_number.into(),
)

@StackOverflowExcept1on
Copy link
Member

Also do not change validate_metawasm as it will be removed soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C2-refactoring Refactoring proposal D5-tooling Helper tools and utilities D7-performance Increase our node/runtime/programs execution work performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants