Help with m5stack project (willing to pay)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
superquest
Posts: 6
Joined: Mon Sep 03, 2018 1:22 am

Help with m5stack project (willing to pay)

Post by superquest » Thu Nov 01, 2018 2:18 am

I'm trying to make a toy Bitcoin wallet using an m5stack ESP32 microcontroller.

I have this fork of loboris' firmware: https://github.com/justinmoon/MicroPyth ... psRAM_LoBo. I added one commit which attempts to hook up 2 libraries containing cryptographic primitives and their MicroPython bindings: https://github.com/justinmoon/MicroPyth ... eb07124f65

This demo code attempts to generate an ECDSA private key, sign an arbitrary message using that key, and verify the signature using the corresponding public key: https://github.com/justinmoon/buidl-wal ... st/main.py

When I run it I encounter this error:
```
>>> from main import main
>>> main()
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x4012defc PS : 0x00060930 A0 : 0x8012dfdc A1 : 0x3ffc4a60
A2 : 0x3ffb31cc A3 : 0x3ffc4ab0 A4 : 0x00000001 A5 : 0x00000004
A6 : 0x00000000 A7 : 0x3ff96458 A8 : 0x00000004 A9 : 0x3ffc4a50
A10 : 0x3ffb314c A11 : 0x3f44084c A12 : 0x00000000 A13 : 0x000001b6
A14 : 0x00000072 A15 : 0x0000002b SAR : 0x00000010 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000064 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffffc

Backtrace: 0x4012defc:0x3ffc4a60 0x4012dfd9:0x3ffc4a90 0x40109700:0x3ffc4ab0 0x401083b4:0x3ffc4ae0 0x4010875c:0x3ffc4b00 0x40108e31:0x3ffc4b20 0x4010918e:0x3ffc4bd0 0x40109ea4:0x3ffc4c60 0x40107e55:0x3ffc4c80 0x400f13d1:0x3ffc4ca0 0x400ecb75:0x3ffc4cc0 0x400ecbe5:0x3ffc4ce0 0x400fa151:0x3ffc4d00 0x400f152e:0x3ffc4da0 0x400ecb75:0x3ffc4dd0 0x400fa0c5:0x3ffc4df0 0x400f152e:0x3ffc4e90 0x400ecb75:0x3ffc4ef0 0x400ecba2:0x3ffc4f10 0x400dfb8f:0x3ffc4f30 0x400dfe0d:0x3ffc4fe0 0x400d4f7c:0x3ffc5020

CPU halted
```

As a sanity check I also made a fork of the base MicroPython firmware. The exact demo code in the Unix port works fine: https://github.com/justinmoon/micropyth ... rc/main.py

There's so much going on here I'm struggling to debug. Is the problem with loboris' library? With the cryptographic libraries I'm using? With my hacks to include those libraries in my project?

How can I resolve this? I'm willing to pay a reasonable hourly rate for someone who can help me get this project off the ground.

Thanks.

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: Help with m5stack project (willing to pay)

Post by loboris » Fri Nov 02, 2018 9:00 am

I've cloned the repository, but could not build.
Some errors were reported - conflicting names in esp-idf mbedtls component and trezor-crypto library.
I'll try again next week.

Have you done something special to compile it?

superquest
Posts: 6
Joined: Mon Sep 03, 2018 1:22 am

Re: Help with m5stack project (willing to pay)

Post by superquest » Fri Nov 02, 2018 5:38 pm

That's right.

I added leading underscore to "aes_encrypt" and "aes_decrypt" definitions in

MicroPython_ESP32_psRAM_LoBo/Tools/esp-idf/components/wpa_supplicant/src/crypto/aes-internal-enc.c

and

MicroPython_ESP32_psRAM_LoBo/Tools/esp-idf/components/wpa_supplicant/src/crypto/aes-internal-dec.c

respectively. This prevents the name collision and should allow project to compile. Sorry I didn't mention that.

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: Help with m5stack project (willing to pay)

Post by loboris » Fri Nov 02, 2018 8:01 pm

A quick fix for the issue:

The problem was with the implementation of random32(void) in components/micropython/lib/trezor-crypto/rand.c.
Change the definition to:

Code: Select all

#include "esp_system.h"

uint32_t random32(void)
{
    return esp_random();
}
Your main example now works:

Code: Select all

MicroPython ESP32_LoBo_v3.2.24 - 2018-09-06 on ESP32 board with ESP32
Type "help()" for more information.
>>> 
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import tcc
=== 
=== 
=== def main():
===     node = tcc.bip32.from_seed(b"foo", "secp256k1")
===     message = "hi"
===     private_key = node.private_key()
===     public_key = node.public_key()
===     message_digest = tcc.sha256(message).digest()
===     sig = tcc.secp256k1.sign(private_key, message_digest)
===     verifies = tcc.secp256k1.verify(public_key, sig, message_digest)
===     print("Verifies?", verifies)
=== 
>>> main()
Verifies? True
>>> 
No payment is necessary, but a donation is always welcomed and appreciated.

superquest
Posts: 6
Joined: Mon Sep 03, 2018 1:22 am

Re: Help with m5stack project (willing to pay)

Post by superquest » Fri Nov 02, 2018 8:45 pm

That worked!

Thanks a ton. I sent a donation. Keep up the great work :)

Post Reply