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

Ungovernable wasm code keys #3061

Open
grarco opened this issue Apr 11, 2024 · 4 comments
Open

Ungovernable wasm code keys #3061

grarco opened this issue Apr 11, 2024 · 4 comments
Assignees

Comments

@grarco
Copy link
Collaborator

grarco commented Apr 11, 2024

Seems like the wasm keys in storage do not fall under any address and therefore have no associated VP.

/// Returns a key of the wasm code of the given hash
pub fn wasm_code(code_hash: &Hash) -> Self {
let mut segments =
Self::from(WASM_KEY_PREFIX.to_owned().to_db_key()).segments;
segments.push(DbKeySeg::StringSeg(WASM_CODE_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(code_hash.to_string()));
Key { segments }
}
/// Returns a key of wasm code's hash of the given name
pub fn wasm_code_name(code_name: String) -> Self {
let mut segments =
Self::from(WASM_KEY_PREFIX.to_owned().to_db_key()).segments;
segments.push(DbKeySeg::StringSeg(WASM_CODE_NAME_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(code_name));
Key { segments }
}
/// Returns a key of the wasm code's length of the given hash
pub fn wasm_code_len(code_hash: &Hash) -> Self {
let mut segments =
Self::from(WASM_KEY_PREFIX.to_owned().to_db_key()).segments;
segments.push(DbKeySeg::StringSeg(WASM_CODE_LEN_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(code_hash.to_string()));
Key { segments }
}
/// Returns a key of the wasm code hash of the given code path
pub fn wasm_hash(code_path: impl AsRef<str>) -> Self {
let mut segments =
Self::from(WASM_KEY_PREFIX.to_owned().to_db_key()).segments;
segments.push(DbKeySeg::StringSeg(WASM_HASH_PREFIX.to_owned()));
segments.push(DbKeySeg::StringSeg(code_path.as_ref().to_string()));
Key { segments }
}

Since we prevent modification to non-protected keys in storage, this means that no governance proposal can effectively modify these keys, which is required if we want to extend the allowlist for example.

We should place these keys under some VP to allow this and also add a check in this vp when a new wasm code is added to storage by running the validate_untrusted_wasm function to make sure that the tx doesn't contain unwanted features (this can be run by the community members before voting on the proposal but I believe a check in protocol would add more safety). On top of that we can also check that all the required keys are updated accordingly, e.g. if we add a new wasm code we should also insert the relative name, length and hash keys, and if we want to remove one from the allowlist we should do it in the way we designed (just remove from the allowlist and keep everything else for execution).

@grarco grarco added bug Something isn't working storage governance pre-mainnet Must happen before mainnet. breaking: protocol labels Apr 11, 2024
@grarco grarco added this to the To evaluate milestone Apr 11, 2024
@Fraccaman Fraccaman self-assigned this Apr 19, 2024
@grarco
Copy link
Collaborator Author

grarco commented Apr 19, 2024

After #3100 we only need to update the parameters vp to check the correctness of the updates coming from a proposal

@cwgoes
Copy link
Collaborator

cwgoes commented May 9, 2024

These checks are important in general, but not critical for phase 1 - we can take extra care for the first proposals.

@cwgoes cwgoes removed the pre-mainnet Must happen before mainnet. label May 9, 2024
@Fraccaman Fraccaman reopened this May 13, 2024
@brentstone
Copy link
Collaborator

why reopened?

@grarco
Copy link
Collaborator Author

grarco commented May 13, 2024

Second part of this issue hasn't been addressed yet. As per Chris's last comment we are leaving it for later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants