-
Notifications
You must be signed in to change notification settings - Fork 374
Crypto api, Rust-only #770
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
Conversation
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.
Nice stuff
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.
Some more comments. Will get back to the open question after lunch
1c65365
to
29f52fb
Compare
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.
Could we return bool
instead of u32
as the return type of verify_secp256k1
over the FFI interface?
Of course! Guess wasm32 memory model is messing with my brain's workings. |
It seems that's not possible without modifying / extending
|
Okay, seems like there are only those value types in WebAssembly: /// A list of all possible value types in WebAssembly.
#[derive(Copy, Debug, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub enum Type {
/// Signed 32 bit integer.
I32,
/// Signed 64 bit integer.
I64,
/// Floating point 32 bit integer.
F32,
/// Floating point 64 bit integer.
F64,
/// A 128 bit number.
V128,
/// A reference to opaque data in the Wasm instance.
ExternRef, /* = 128 */
/// A reference to a Wasm function.
FuncRef,
} See also https://github.com/WebAssembly/design/blob/master/Semantics.md#types. Alright, let's keep the 0/1 solution then. |
Yeah, I was just thinking that booleans are notoriously inconsistent, both in and across languajes / platforms. |
packages/std/src/imports.rs
Outdated
message_hash: &[u8], | ||
signature: &[u8], | ||
public_key: &[u8], | ||
) -> StdResult<bool> { |
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.
StdResult
wrapper is basically useless now. Do we go ahead and remove it? Or do we keep it, just for API consistency?
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.
Let's remove it. The fewer errors the contract developer needs to handle, the better. We have many API calls that can only:
- Succeed
- Fail in VM and never return to contract
- Panic in contract
All the Storage API works like this.
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.
Hmmm, it seems StdResult
is a good idea here, for Api
compatibility; i.e. that way the MockApi
impl can return errors, in contract testing land.
Not sure if we want that, though. Though it will ease development / debugging, it points to functionality that will never trigger behaves differently in the "real" (vm) environment.
Update: I think it's nevertheless a good idea, for usability / transparency. Will add both versions, and we can decide.
What do you think?
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.
Good point. I tend to favour panics in the MockApi
. Those can easily debug and we optimize for the production use case where there is nothing the contract developer should or can handle.
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.
OK, going for that then.
I'll publish these latest changes in a new PR (cosmwasm-crypto
package) against main
, so that you can take a look at the final version. Besides api / contract testing, and some extra docs / comments, I would say, this is done™️.
Thanks for all the feedback / reviews!
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 code looks fine to me. What is missing to me is a use case in a contract.
That can be a different PR, but we need to show/test usage. Having a contract that verifies a signature, and testing it both with unit tests (MockApi) and integration tests (ExternalApi). That, for me, shows it is all working and wired up properly.
Will do that next, and then work on refactoring stuff (internal Update: Also need to add some test cases for the wasm <-> native interface. And some API documentation. |
Yeah, sorry for that. Needed to see it working first, to be able to define the API and do the plumbing. |
8ea5e4c
to
1eafb65
Compare
Include non low-S signatures normalization
Co-authored-by: Simon Warta <[email protected]>
Co-authored-by: Simon Warta <[email protected]>
Co-authored-by: Simon Warta <[email protected]>
1eafb65
to
0b675a2
Compare
Co-authored-by: Simon Warta <[email protected]>
Co-authored-by: Simon Warta <[email protected]>
Co-authored-by: Simon Warta <[email protected]>
92df8f7
to
f0501ea
Compare
f0501ea
to
25eecd4
Compare
Closing in favour of #779. |
Closes first part of #751: secp256k1 signature verification for Cosmos signatures.
Alernative to #767, using the Rust-only crate
k256
.Still some improvements to do, documentation to add, but ready for review.