Bitcoin Forum
April 18, 2024, 03:12:03 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to build Libsecp256k1 when running Electrum from a cloned repository.  (Read 119 times)
Accardo (OP)
Hero Member
*****
Offline Offline

Activity: 1050
Merit: 509


Leading Crypto Sports Betting & Casino Platform


View Profile
November 30, 2021, 10:54:42 AM
Merited by CryptopreneurBrainboss (16), Welsh (12), ABCbits (10), hugeblack (10), HCP (10), The Sceptical Chymist (5), NotATether (5)
 #1

Lib; is a library for cryptography on the secp256k1 made available for the public.

Electrum we know is a python program. They are different methods of running an electrum like TAR.gz which the installation code for electrum is made available on github to be.

Code:
sudo apt-get install python3-setuptools python3-pip
python3 -m pip install --user .

This thread shows the implementation details of Libsecp256K1 when running Electrum alternatively.

Below is a script provided to build Libsecp256k1

Code:
sudo apt-get install automake libtool
./contrib/make_libsecp256k1.sh


How to Build Libsecp256k1

It's highly necessary to write your own code (optimized assembly) to improve the performance of your program. Using Gcc-03

Requirement = Autotool

Code:
$ ./autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install  # optional

Checking for Bugs

Code:
$ ./exhaustive_tests

Memory debugging using Valgrind

Code:
$ valgrind --max-stackframe=2500000 ./exhaustive_tests

CREATE A TEST COVERAGE USING GCC WITH
Quote
--enable-coverage

Code:
$ ./configure --enable-coverage

Execute the test

Code:
$ make check

Open a report using gcovr

Code:
$ gcovr --exclude 'src/bench*' --print-summary

Open a HTML report with colored and annotated source code

Code:
$ mkdir -p coverage
$ gcovr --exclude 'src/bench*' --html --html-details -o coverage/coverage.html

These codes were shared on github. I decided to share on this forum to reduce the hassle of looking for them on github.

My source: https://github.com/spesmilo/electrum .

The link above consists of the code required to run Electrum.

Would appreciate if you contribute to this thread, I seek knowledge on this aswell. cheers.

..Stake.com..   ▄████████████████████████████████████▄
   ██ ▄▄▄▄▄▄▄▄▄▄            ▄▄▄▄▄▄▄▄▄▄ ██  ▄████▄
   ██ ▀▀▀▀▀▀▀▀▀▀ ██████████ ▀▀▀▀▀▀▀▀▀▀ ██  ██████
   ██ ██████████ ██      ██ ██████████ ██   ▀██▀
   ██ ██      ██ ██████  ██ ██      ██ ██    ██
   ██ ██████  ██ █████  ███ ██████  ██ ████▄ ██
   ██ █████  ███ ████  ████ █████  ███ ████████
   ██ ████  ████ ██████████ ████  ████ ████▀
   ██ ██████████ ▄▄▄▄▄▄▄▄▄▄ ██████████ ██
   ██            ▀▀▀▀▀▀▀▀▀▀            ██ 
   ▀█████████▀ ▄████████████▄ ▀█████████▀
  ▄▄▄▄▄▄▄▄▄▄▄▄███  ██  ██  ███▄▄▄▄▄▄▄▄▄▄▄▄
 ██████████████████████████████████████████
▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄
█  ▄▀▄             █▀▀█▀▄▄
█  █▀█             █  ▐  ▐▌
█       ▄██▄       █  ▌  █
█     ▄██████▄     █  ▌ ▐▌
█    ██████████    █ ▐  █
█   ▐██████████▌   █ ▐ ▐▌
█    ▀▀██████▀▀    █ ▌ █
█     ▄▄▄██▄▄▄     █ ▌▐▌
█                  █▐ █
█                  █▐▐▌
█                  █▐█
▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀█
▄▄█████████▄▄
▄██▀▀▀▀█████▀▀▀▀██▄
▄█▀       ▐█▌       ▀█▄
██         ▐█▌         ██
████▄     ▄█████▄     ▄████
████████▄███████████▄████████
███▀    █████████████    ▀███
██       ███████████       ██
▀█▄       █████████       ▄█▀
▀█▄    ▄██▀▀▀▀▀▀▀██▄  ▄▄▄█▀
▀███████         ███████▀
▀█████▄       ▄█████▀
▀▀▀███▄▄▄███▀▀▀
..PLAY NOW..
1713409923
Hero Member
*
Offline Offline

Posts: 1713409923

View Profile Personal Message (Offline)

Ignore
1713409923
Reply with quote  #2

1713409923
Report to moderator
1713409923
Hero Member
*
Offline Offline

Posts: 1713409923

View Profile Personal Message (Offline)

Ignore
1713409923
Reply with quote  #2

1713409923
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
NotATether
Legendary
*
Offline Offline

Activity: 1582
Merit: 6669


bitcoincleanup.com / bitmixlist.org


View Profile WWW
November 30, 2021, 04:08:40 PM
 #2

It's highly necessary to write your own code (optimized assembly) to improve the performance of your program. Using Gcc-03

Actually, this is something you do not want to do with any cryptography library or any other encryption library, because sometimes, -O3 introduces side-channel attacks that are difficult to find because they are not in the code.

A classic example is removing no-op codes that don't appear to do anything, but stall execution so that someone can't hook up an oscilloscope to your computer to make a graph of the heat coming out of your processor (indicates when an operation is doing a slow operation instead of a fast one e.g. multiply instead of add).

Since the encryption algorithms go through a lot of loops, the same procedure can be used to discover the computational operations done in each loop.

It is better to not build with any optimization at all, and pass these flags to the build process:

Code:
CFLAGS="-fPIE -fstack-protector-all -D_FORTIFY_SOURCE=2"
LDFLAGS="-Wl,-z,now -Wl,-z,relro"

Turns on ASLR (Address Space Layout Randomization), and protects you from buffer overflows and stacks belonging to random functions from being overwritten by bad code.

If you do want faster performance for these kind of programs then you must buy a faster processor, there's no way around it.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Accardo (OP)
Hero Member
*****
Offline Offline

Activity: 1050
Merit: 509


Leading Crypto Sports Betting & Casino Platform


View Profile
November 30, 2021, 05:31:53 PM
Merited by The Sceptical Chymist (3)
 #3

It's highly necessary to write your own code (optimized assembly) to improve the performance of your program. Using Gcc-03

Actually, this is something you do not want to do with any cryptography library or any other encryption library, because sometimes, -O3 introduces side-channel attacks that are difficult to find because they are not in the code.

A classic example is removing no-op codes that don't appear to do anything, but stall execution so that someone can't hook up an oscilloscope to your computer to make a graph of the heat coming out of your processor (indicates when an operation is doing a slow operation instead of a fast one e.g. multiply instead of add).

Since the encryption algorithms go through a lot of loops, the same procedure can be used to discover the computational operations done in each loop.

It is better to not build with any optimization at all, and pass these flags to the build process:

Code:
CFLAGS="-fPIE -fstack-protector-all -D_FORTIFY_SOURCE=2"
LDFLAGS="-Wl,-z,now -Wl,-z,relro"

Turns on ASLR (Address Space Layout Randomization), and protects you from buffer overflows and stacks belonging to random functions from being overwritten by bad code.

If you do want faster performance for these kind of programs then you must buy a faster processor, there's no way around it.


Thank you for schooling me about the implementation attack attached to using Gcc-03.

Quote
If you do want faster performance for these kind of programs then you must buy a faster processor, there's no way around it.

Focusing on speed, the march option -march=cpu-type helps so much. For instance, -malign-double is compatible to *86-64. When a double variable is arranged with a two word boundaries the speed of the code sets to run faster on a Pentium and takes much memory.

At the level of my understanding, Image affects the speed of a program using gcc. So, my question is, are you condemning gcc entirely on this kind of program or just for the side channel attack disadvantage that it comes with?

..Stake.com..   ▄████████████████████████████████████▄
   ██ ▄▄▄▄▄▄▄▄▄▄            ▄▄▄▄▄▄▄▄▄▄ ██  ▄████▄
   ██ ▀▀▀▀▀▀▀▀▀▀ ██████████ ▀▀▀▀▀▀▀▀▀▀ ██  ██████
   ██ ██████████ ██      ██ ██████████ ██   ▀██▀
   ██ ██      ██ ██████  ██ ██      ██ ██    ██
   ██ ██████  ██ █████  ███ ██████  ██ ████▄ ██
   ██ █████  ███ ████  ████ █████  ███ ████████
   ██ ████  ████ ██████████ ████  ████ ████▀
   ██ ██████████ ▄▄▄▄▄▄▄▄▄▄ ██████████ ██
   ██            ▀▀▀▀▀▀▀▀▀▀            ██ 
   ▀█████████▀ ▄████████████▄ ▀█████████▀
  ▄▄▄▄▄▄▄▄▄▄▄▄███  ██  ██  ███▄▄▄▄▄▄▄▄▄▄▄▄
 ██████████████████████████████████████████
▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄
█  ▄▀▄             █▀▀█▀▄▄
█  █▀█             █  ▐  ▐▌
█       ▄██▄       █  ▌  █
█     ▄██████▄     █  ▌ ▐▌
█    ██████████    █ ▐  █
█   ▐██████████▌   █ ▐ ▐▌
█    ▀▀██████▀▀    █ ▌ █
█     ▄▄▄██▄▄▄     █ ▌▐▌
█                  █▐ █
█                  █▐▐▌
█                  █▐█
▀▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▀█
▄▄█████████▄▄
▄██▀▀▀▀█████▀▀▀▀██▄
▄█▀       ▐█▌       ▀█▄
██         ▐█▌         ██
████▄     ▄█████▄     ▄████
████████▄███████████▄████████
███▀    █████████████    ▀███
██       ███████████       ██
▀█▄       █████████       ▄█▀
▀█▄    ▄██▀▀▀▀▀▀▀██▄  ▄▄▄█▀
▀███████         ███████▀
▀█████▄       ▄█████▀
▀▀▀███▄▄▄███▀▀▀
..PLAY NOW..
NotATether
Legendary
*
Offline Offline

Activity: 1582
Merit: 6669


bitcoincleanup.com / bitmixlist.org


View Profile WWW
December 01, 2021, 02:08:26 PM
Merited by Welsh (6), hugeblack (4), Accardo (2)
 #4

Focusing on speed, the march option -march=cpu-type helps so much. For instance, -malign-double is compatible to *86-64. When a double variable is arranged with a two word boundaries the speed of the code sets to run faster on a Pentium and takes much memory.

When I'm just building software just for a local machine, passing -march=native and -mtune=native is an easy way to turn on maximum CPU arch optimization without having to research the specifics of the CPU model I'm compiling on.

At the level of my understanding, Image affects the speed of a program using gcc. So, my question is, are you condemning gcc entirely on this kind of program or just for the side channel attack disadvantage that it comes with?

GCC without any optimization options is suitable for cryptographic and programs with sensitive consensus rules such as Bitcoin Core because then the binary output corresponds to the code (which can easily be audited by security professionals) and it is the way that libsecp256k1 is compiled for distributions as far as I know.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!