-
Notifications
You must be signed in to change notification settings - Fork 354
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
Update check for contract instantiation #5699
Conversation
Can we get this merged? I can't use contracts UI with RISC-V contracts otherwise. |
this PR seems pretty innocent, can we get it merged @jacogr? 🙏🏻 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced this is "innocent enough".
Basically at this point we can throw any data into the mix as expect it to work, i.e. some JSON, a random piece of text, etc. Basically we end up with garbage that cannot be executed in any interpreter.
If there are additional formats that should be supported, the better approach is to check the magic flag for that specific format in addition to the isWasm
check.
EDIT: The is<NewFormat>()
check function can just be added locally to the specific file - it would make sense to also add it to common (and when that is available in a release, the local version inside the file can be removed)
So what? The verification also does only check the first bytes for the "wasm magic". There are still infinite many ways to send "garbage that cannot be executed in any interpreter" after those bytes. I cannot see the value that this very shallow check provides. Users have to do error handling anyways since |
It is what it is :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained in #5699 (review):
- Add a
is<FormatName>()
check function (e.g. assuming the new format isXXX
we addisXXX
- used in the sample for the next points) to check the magic bytes for the specific additional type - Adjust the
isWasm
checks to doisWasm(...) || isXXX(...)
- (Optional, but appreciated) Also add the
isXXX
to the common repo (will eventually replace the local version when that stuff is released)
That should more-or-less cover the same functionality. (Not 100% sure on the source.wasm
usage, implementers would know better on that)
7c78a0f
to
1c42041
Compare
Added a similar check for RISC-V @jacogr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, looks like it fits the bill.
Two small comment added just to be slightly more pedantic/explicit on return types/guards. (It always helps when we come back years from now)
@@ -42,12 +52,12 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> { | |||
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined, decorateMethod: DecorateMethod<ApiType>) { | |||
super(api, abi, decorateMethod); | |||
|
|||
this.code = isWasm(this.abi.info.source.wasm) | |||
this.code = isValidCode(this.abi.info.source.wasm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly weird that a different format may come through in source.wasm
, but either way, all ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the field in the contract metadata will most likely be renamed once the support for RISC-V is released. not something we should address now imo.
Co-authored-by: Jaco <[email protected]>
Co-authored-by: Jaco <[email protected]>
isWasm
check for contract instantiation
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Replaced the
isWasm
check on contract instantiation withisU8a
in order to allow experimentation with other targets.For more info see use-ink/contracts-ui#507