-
Notifications
You must be signed in to change notification settings - Fork 12
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
Upgradable
parameter and result serialization of code
#77
Comments
Also the borsh serialization of Since it’s related to |
Upgradable::up_stage_code
parameter serializationUpgradable
parameter and result serialization of code
Good catch @mooori . I think it makes sense to change the serialization to use JSON (bytes encoded as base64) to be consistent with everything else. If the efficiency is really important to some use-case they can always override the default implementation correct? |
It surfaced in integration tests and surprised me there. If someone implements the Another simple way to use borsh instead of json would be adding a wrapper like this to the contract: pub fn borsh_up_stage_code(&mut self, #[serializer(borsh)] code: Vec<u8>) {
self.up_stage_code(code);
} Given these options I think for now it’s fine to switch to json. If efficiency of these methods becomes a frequent issue, we could let users configure the serialization protocol via a macro attribute: #[derive(Upgradable)]
#[upgradable(code_serialization(borsh))
pub struct Contract { /* ... */ } |
@birchmd @mooori Some background:
The problem here is that the hash is not of the binary wasm file, but it should be the hash of the serialized borsh bytes. So The DAO signers will need to use some extra tool to validate that the hash of the binary is the same as the one that stored in the repo or release links. But there is another solution, we can completely avoid the dao upgrade logic, to be able to do that, we need to add an additional |
@karim-en thanks for reporting the issue and proposing solutions!
When
Just to double check that I understood correctly, the proposal is to modify fn up_deploy_code(&mut self, function_call_args: Option<FunctionCallArgs>, hash: Option<String>) {
//...
if let Some(hash) = hash {
// Panic if `hash` does not correspond to the hash of the staged code
}
//...
} That would sound like a reasonable approach to me. |
@mooori Yes, exactly. |
My understanding of The The attached call can be to a migration function which uses @karim-en I noticed you mentioned the function signature |
@mooori Yes, that is true that the Yeah, I am aware of the deploy & migrate functionally, Astro dao also has a similar approach, but this doesn't protect us from deploying a problematic contract by mistake, if the full access keys were removed and there is no correct migration function then there is no way to recover the contract. |
Here is the expand of this function:
As you can see the generated code doesn't contain Btw, if it is problematic to do that in the plugins themselves, then we could add this requirement just to the attach_full_access_key. |
A failure of the migration function causes the upgrade to roll back if the migration function is called via the
Such an approach in
Currently we expect plugins to be used within implementation blocks with
With raw functions like that, using |
Upgradable::up_stage_code
uses borsh parameter serialization:https://github.com/aurora-is-near/near-plugins/blob/c043add4c2a0810872c4326a55c5162bccd3f4ee/near-plugins-derive/src/upgradable.rs#L33
However, this isn’t documented:
https://github.com/aurora-is-near/near-plugins/blob/1cf0aa61e38d3b02803642983795c927598375ba/near-plugins/src/upgradable.rs#L56-L58
So most likely users will assume default json parameter serialization and then wonder why deserialization fails when calling
up_stage_code
in a transaction.Either we should document this or change
up_stage_code
to use json serialization. If I remember correctly, this is the only method provided by near-plugins which does not use json parameter serialization. Even if less efficient, perhaps we should switch to json here for a consistent and intuitive API?Edit: Another advantage of json is that it allows using
near-cli
to stage code, which is problematic with borsh as described here (sectionup_stage_code
).cc @birchmd
The text was updated successfully, but these errors were encountered: