Awarded: - Bounty #32 - EVM Transactions - Motoko - $8,000

Not sure if this is helpful(or which library you were referring to), but:(looks like this is just verification…I think you need signing)

In the given Motoko code, the value “v” is not explicitly calculated, but rather it is implicitly derived as a part of the signature verification process using the values “r” and “s” from the signature, and the public key and the message being verified.

Specifically, the code first checks that “r” and “s” are valid and within the curve’s range, and then converts them to Fp elements “r” and “s” using the curve’s modulus “r”. It then calculates the hash “h” of the message using SHA256 and converts it to an Fp element.

Next, the code calculates the inverse of “s” as “sInverse”, and uses it to compute two Fp elements “a” and “b” as:

a = h * sInverse
b = r * sInverse

These values are then used to calculate a point on the curve using the Jacobi function, as:

Jacobi.mulBase(a.value, curve),
Jacobi.mul(Jacobi.fromAffine(#point (x, y, curve)), b.value)

This point is then checked to see if it matches the value of “r”, which is the x-coordinate of the signature point. If it does match, then the signature is considered valid and the function returns “true”. Otherwise, it returns “false”.

So, while the code doesn’t explicitly calculate the value of “v”, it does use “r” and “s” to calculate a point on the curve, and then checks whether the x-coordinate of that point matches “r”. This effectively determines the value of “v” and ensures that the signature is valid.

Sorry. When I said verify the signature, it was actually recover the public key from the signature.

To be able sign a evm transaction (ic-evm-sign/ at master · nikolas-con/ic-evm-sign · GitHub), the ecdsa module from bitcoin-motoko would need a recovery function like libsec256k1’s recover_raw(): libsecp256k1/ at master · paritytech/libsecp256k1 · GitHub

That’s the one I’m trying to get to work, but there’s something wrong with the ecmult() function on the Motoko port (mo-libsecp256k1/ at main · av1ctor/mo-libsecp256k1 · GitHub).

The libsec256k1’s ecdsa.recover() was fixed :smile:

Now back to the EVM transactions.


Alright, I think it’s done:

  1. GitHub - av1ctor/ Motoko EVM transaction creation, encoding, and decoding
  2. GitHub - av1ctor/ Motoko port of libsecp256k1

There’s also a demo backend in Motoko: at main · av1ctor/ · GitHub

All tests ported from GitHub - nikolas-con/ic-evm-sign: A library to sign EVM transactions on the Internet Computer. are passing.

@skilesare: If there’s something missing, please let me know, thanks.

1 Like

Hey @v1ctor, congrats on completing this. Has it been vetted by @skilesare or his colleagues? I’m eager to take it for a spin :racing_car:, and eventually use it in production :rocket:

With version v.0.1.3 fixes it should be OK to use in production.

Awesome, thx @v1ctor ! This unlocks plenty of use-cases for those who prefer Motoko over Rust on IC.

1 Like

do you mind adding your libsecp256k1 library to GitHub - motoko-unofficial/awesome-motoko: A curated list of Motoko code and resources.?

Right, pull request opened :slight_smile:

1 Like