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

Reduce the size of precomputed signing table for lowmemory #323

Merged
merged 1 commit into from
Sep 8, 2021

Conversation

RCasatta
Copy link
Contributor

@RCasatta RCasatta commented Jul 21, 2021

Reduce the size of precomputed signing table (ECMULT_GEN_PREC_BITS) for lowmemory feature

in rust-bitcoin embedded test secp preallocate_size become 33472 from 66240

@RCasatta RCasatta changed the title really low memory test Reduce the size of precomputed signing table for lowmemory Jul 21, 2021
@elichai
Copy link
Member

elichai commented Jul 21, 2021

Can I ask what's the motivation behind this? a specific setup where this was too much memory?
I'm for reducing ECMULT_GEN_PREC_BITS because it saves 2048 bytes, which can be important for lowmemory
But reducing ECMULT_WINDOW_SIZE from 4 to 2 only save 24 bytes in the context and costs ~16% decrease in performance on my laptop

(i9-9980HK, turbo off, window size 4, gen prec bits 2)

ecdsa_verify: min 80.9us / avg 81.2us / max 81.4us
ecdsa_verify: min 81.1us / avg 81.9us / max 83.4us
ecdsa_verify: min 81.3us / avg 82.0us / max 83.6us

(window size 2, gen prec bits 2)

ecdsa_verify: min 95.7us / avg 96.0us / max 97.0us
ecdsa_verify: min 95.6us / avg 97.1us / max 100us
ecdsa_verify: min 95.6us / avg 96.1us / max 98.1us

@RCasatta
Copy link
Contributor Author

RCasatta commented Jul 21, 2021

But reducing ECMULT_WINDOW_SIZE from 4 to 2 only save 24 bytes in the context and costs ~16% decrease in performance on my laptop

sorry, I did a test changing ECMULT_WINDOW_SIZE but it was not intended to be changed in the commit (as you can see from the commit message there is no reference to it)

I'm for reducing ECMULT_GEN_PREC_BITS because it saves 2048 bytes,

Why do you say 2048 bytes, is this line wrong? https://github.com/rust-bitcoin/rust-bitcoin/blob/df4d70a37e96e6f82c5231063635e877cb6b4f77/embedded/src/main.rs#L37

Can I ask what's the motivation behind this? a specific setup where this was too much memory?

In general lower required memory enlarges the possible usable MCUs, and personally, I would like to run it on the stm32f4xx Blackpill (64k ram)

@elichai
Copy link
Member

elichai commented Jul 21, 2021

Why do you say 2048 bytes, is this line wrong? https://github.com/rust-bitcoin/rust-bitcoin/blob/master/embedded/src/main.rs#L37

I completely forgot that our precompute size is in blocks of 16 bytes and not in bytes(funny considering I changed that lol)
so you're right, changing the window size from 4 to 2 decreases by 384 bytes, and the precision bits from 4 to 2 decreases by 32,768 bytes.

Copy link
Member

@elichai elichai left a comment

Choose a reason for hiding this comment

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

tACK

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 505b04d

Not sure why CI is not running. Passes locally for me.

@apoelstra apoelstra merged commit acba77c into rust-bitcoin:master Sep 8, 2021
@elichai
Copy link
Member

elichai commented Sep 10, 2021

So apparently when you try to use this library inside Fortanix SGX enclave you get a SIGBUG, but with this PR + lowmemory you don't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants