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

Verify numeric instructions #37

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

zixuanzh
Copy link

@zixuanzh zixuanzh commented Dec 6, 2018

As per issue #18

parity-wasm checks types for const operators but not for binary as specified in the spec.

We simulated the stack to check for types and hence we added a new validator interface that takes in a mutable self reference. We also use a self defined enum instead of String for error handling and propagation as advised by the documentation.

@jakelang
Copy link
Collaborator

jakelang commented Dec 6, 2018

@zixuanzh CI is failing because you need to run cargo fmt. just FYI

type Pop = Vec<ValueType>;
type Push = Vec<ValueType>;

struct Signature {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document these structs with triple-slash comments? That way rustdoc can automatically generate a docs site for this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zixuanzh @Steampunkery please document the code.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed to the staging repo a moment ago, should show up in here soon. @zixuanzh @jakelang

push: Push
}

pub enum Filter {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be useful to have per-instruction granularity here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per instruction granularity would be a tricky/impossible thing to implement because you need to simulate an entire stack to know if the right data types will be on that stack at the right time. If you mean just simulating a stack and filtering out certain instructions, then yes, I could do that.

for signature_value in &signature.pop {
let value = self.stack.pop();
match value {
Some(stack_value) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a matter of preference but I find it cleaner, in the case of destructuring two-valued enums like Option, to use the if let Some(stack_value) pattern here.

@jakelang
Copy link
Collaborator

jakelang commented Dec 6, 2018

@zixuanzh CI seems to be a version behind on rustfmt. will fix that.

edit: actually that doesn't seem to be the problem. trying to find out why fmt is still freaking out.

edit 2: Are you sure you are using the correct version?

@zixuanzh zixuanzh force-pushed the verify-instructions branch from c451588 to ad30d14 Compare December 6, 2018 15:47
@zixuanzh
Copy link
Author

zixuanzh commented Dec 6, 2018

I am running on 1.32.0-nightly, fmt fails at deployer.rs etc in CI, it passes CI when I only commit verify-instructions related files.

@jakelang
Copy link
Collaborator

@zixuanzh is this ready or WIP? Please add the respective label.

Also please rebase.

@zixuanzh zixuanzh force-pushed the verify-instructions branch from ad30d14 to 93e2c7f Compare December 21, 2018 05:03
@zixuanzh
Copy link
Author

@jakelang it should be ready as it is unless @Steampunkery has something to add, we don't have access to add labels.

@@ -35,6 +40,10 @@ pub trait ModuleValidator {
fn validate(&self, module: &Module) -> Result<bool, ModuleError>;
}

pub trait InstructionValidator {
fn validate(&mut self, module: &Module) -> Result<bool, InstructionError>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since we have ModuleError, it should be possible to merge the InstructionError enum into it and thus removing the need for a new trait.

@axic
Copy link
Member

axic commented Dec 21, 2018

I think this looks good in general, great work @Steampunkery and @zixuanzh!

InvalidOperation(Instruction),
}

impl fmt::Display for InstructionError {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we merge ModuleError and InstructionError, could you create a new PR which just adds the Display and Error traits on ModuleError? Then this PR can just extend that with the new enum values.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, instead of adding new variants, it may make sense to just encode these errors as a string in the Custom variant of ModuleError.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or make Custom(T) type generic and throw InstructionError in there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Text in general is fine, but for programmatic detection the enums are better.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to stick to enum variants if possible, and I can certainly look into merging InstructionError into ModuleError.

@jakelang jakelang added the ready Ready for review and merge label Dec 21, 2018
}

#[cfg(test)]
mod tests {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs moar unit tests

@axic
Copy link
Member

axic commented Jan 26, 2019

@Steampunkery @zixuanzh can we take over this PR or do you think you'll have some resources to work on this in the next while?

@zixuanzh
Copy link
Author

@axic please proceed, we are unlikely to work on this in the immediate future. thanks

@jakelang jakelang added deferred Maybe later. and removed ready Ready for review and merge labels Jun 13, 2019
@axic axic force-pushed the verify-instructions branch from 93e2c7f to df99108 Compare September 24, 2019 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deferred Maybe later.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants