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

Any easy way to validate a function signature? #1101

Closed
slavik0329 opened this issue Oct 13, 2020 · 9 comments
Closed

Any easy way to validate a function signature? #1101

slavik0329 opened this issue Oct 13, 2020 · 9 comments
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@slavik0329
Copy link

For example:

uint32 num1,address from,bool isTrue
should validate to true while

uAint8 num1,addressed to
should be false.

The only thing Ive found that does validation is the Abicoder encode function, however I have to provide values for it to work.

Thanks!

@ricmoo
Copy link
Member

ricmoo commented Oct 13, 2020

You need a bit more for a signature, but you could glue boiler plate around it, but you could use something like ethers.utils.FunctionFragment.from("transfer(address from, uint)" to use the human-readable parser. Or the ethers.utils.ParamTypr.from("uint blah") on each individual parameter. The former is more useful though, as it will determine individual components; do not simply spilt on the comma as nested structures can bite you and the FunctionFragment will figure that out for you...

@ricmoo ricmoo added the discussion Questions, feedback and general information. label Oct 13, 2020
@ricmoo
Copy link
Member

ricmoo commented Oct 13, 2020

@slavik0329
Copy link
Author

slavik0329 commented Oct 13, 2020 via email

@slavik0329
Copy link
Author

slavik0329 commented Oct 14, 2020

@ricmoo Heres an example:

Screen Shot 2020-10-14 at 12 31 46 PM

It does not seem to do any type checking on the parameters.

@ricmoo
Copy link
Member

ricmoo commented Oct 14, 2020

Hmmm. It shouldn’t have done that, but now I realize I can’t change that in a backwards compatible way. It will be corrected in v6.

In the meantime, I should be able to get something together to help you verify signatures. I’m almost done EIP-712 and have 2 other things to get to, but there is something I wanted to get around to adjacent to what you are trying to solve. :)

@ricmoo ricmoo added enhancement New feature or improvement. on-deck This Enhancement or Bug is currently being worked on. and removed discussion Questions, feedback and general information. labels Oct 14, 2020
@slavik0329
Copy link
Author

@ricmoo Hey, have you had a chance to work on this? No big deal if not, just wondering.

@ricmoo
Copy link
Member

ricmoo commented Nov 23, 2020

Yes! I have something locally that I think will do exactly what you want. And be generally useful for now and the future... Just running a bit more testing on it first.

Basically, it will allow you to compute the default values for a given set of parameters. So, you can use it like this:

// Works:
const fragment = ethers.utils.FunctionFragment.from("transfer(uint32 num1,address from,bool isTrue)");
console.log(ethers.utils.defaultAbiCoder.getDefaultValue(fragment.inputs));
/*
[ 0,
  '0x0000000000000000000000000000000000000000',
  false,
  num1: 0,
  from: '0x0000000000000000000000000000000000000000',
  isTrue: false ]
*/

// Throws an Error:
const fragment = ethers.utils.FunctionFragment.from("transfer(uAint8 num1,addressed to)");
console.log(ethers.utils.defaultAbiCoder.getDefaultValue(fragment.inputs));

The CI system seems down right now, but let me know what you think and I'll try to get this out as soon as possible. :)

@ricmoo
Copy link
Member

ricmoo commented Nov 24, 2020

The above functionality has been added in 5.0.22.

Try it out and let me know if you have any problems.

Thanks! :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Nov 24, 2020
@slavik0329
Copy link
Author

slavik0329 commented Dec 2, 2020

@ricmoo Amazing! This is exactly what I was hoping for. Works great. Thank you so much for releasing this patch, it will be very useful to me and most likely many others!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

2 participants