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

Testing a Deploy transaction with an invalid verify function signature #22

Open
YaronWittenstein opened this issue Oct 21, 2021 · 0 comments
Assignees
Labels
svm test Testing related

Comments

@YaronWittenstein
Copy link
Contributor

YaronWittenstein commented Oct 21, 2021

Each valid Template under SVM needs to have the svm_verifymethod and it should have () -> (i32) function signature

(module
  (export "svm_verify" (func $svm_verify))

  ;; Valid `svm_verify` signature
  (func $svm_verify (result i32)
    (i32.const 0)))

This time we want to feed Deploy with an invalid svm_verify input.
We'd expect ValidateDeploy to fail.

There are two options to generate such an input:

Modify the SDK code-generation

The current SDK's code at the point of writing this issue generates an empty verify.
https://github.com/spacemeshos/svm/blob/22fb1cf627d5c82d20c285744dd9ee708e9c7c08/crates/sdk-macros/src/template.rs#L283

Thus, the current verify code-generation is a stopgap since authors of Template will have to write their own verify.
Probably, the best thing will be to remove this stub and enforce each template to have svm_verify created.

I think that the elegant way will be to add a #[verify] decorator for such a method (similar to the #[ctor] and #[endpoint]) and let the compiler take care of generating svm_verify at the final Wasm.

Note: the compiler needs to enforce only one (and exactly one) method that could be annotated with the #[verify] attribute within a Template.

Write Wasm Manually

That is also a valid option, but it might be a bit harder but still feasible. For example, we can manually compose a Wasm file in its Text representation and convert a binary Wasm.

Then we can manually create a JSON for the Template Metadata (empty Data layout and pick a ctor).
Finally, we could stitch the pieces using the CLI.

Other

Once we have a working test, it should be easy to test an invalid svm_alloc method and other required SVM Template functions (more due to the Nonces Schemes).

@YaronWittenstein YaronWittenstein changed the title Testing a Spawn and Call transactions with an invalid verify function signature Testing a Deploy transaction with an invalid verify function signature Oct 21, 2021
@YaronWittenstein YaronWittenstein added svm test Testing related labels Oct 21, 2021
@neysofu neysofu self-assigned this Nov 8, 2021
@neysofu neysofu mentioned this issue Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
svm test Testing related
Projects
None yet
Development

No branches or pull requests

2 participants