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

Limit size of linear memory in VM #462

Closed
webmaster128 opened this issue Jul 8, 2020 · 2 comments · Fixed by #504
Closed

Limit size of linear memory in VM #462

webmaster128 opened this issue Jul 8, 2020 · 2 comments · Fixed by #504
Assignees
Milestone

Comments

@webmaster128
Copy link
Member

The heap data of a smart contract execution is stored in a Wasm linear memory. Only zero or one linear memories can exist in the current Wasm standard. The maximum size of a linear memory is 4GB because it is addressed by uint32 offsets in 1 byte steps.

Right now, we ensure the upper memory limit is unset by the contract:

fn check_wasm_memories(module: &Module) -> VmResult<()> {
    // ...

    if limits.maximum() != None {
        return Err(VmError::static_validation_err(
            "Wasm contract memory's maximum must be unset. The host will set it for you.",
        ));
    }
    Ok(())
}

If we wanted we could implement the limit the following way at any time: take a Wasm blob, deserialize, set the maximum of the first linear memory, re-serialize, compile. This is not very elegant and has the disadvantage that the memory limit is stored as part of the compiled modules. So it cannot be adjusted without invalidating cached modules.

A proper solution is discussed here, which is what we wait for right now: wasmerio/wasmer#1360

@webmaster128 webmaster128 added Blocked Blocked on some external dependency vm cosmwasm-vm crate labels Jul 8, 2020
@webmaster128 webmaster128 added this to the 1.0.0 milestone Jul 8, 2020
@webmaster128 webmaster128 changed the title Limit size of linear memory on VM Limit size of linear memory in VM Jul 8, 2020
@webmaster128 webmaster128 modified the milestones: 1.0.0, 0.11.0 Aug 5, 2020
@webmaster128
Copy link
Member Author

Depends on #503

@webmaster128
Copy link
Member Author

This probably becomes very easy with Wasmer 1.0 (follow wasmerio/wasmer#1730 for updates)

@webmaster128 webmaster128 modified the milestones: 0.12.0, 0.13.0 Nov 3, 2020
@webmaster128 webmaster128 removed the Blocked Blocked on some external dependency label Dec 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant