Bitcoin Forum
June 22, 2024, 06:53:19 PM *
News: Voting for pizza day contest
 
  Home Help Search Login Register More  
  Show Posts
Pages: « 1 2 [3] 4 »
41  Bitcoin / Development & Technical Discussion / Re: Pollard's kangaroo ECDLP solver on: March 01, 2021, 03:47:37 PM
Hello there
Generally, I use sagemath, but in this project I am trying to do what I do there in C.

Point * ScalarNumber
I could not see a method for processing

I added it here. I'm not a complete programmer so I'm writing it here.

It works for CPU but I want to run this method with GPU.
Can you help me ?

File Name Secp256K1.cpp

Code:
Point Secp256K1::ECMultiply(Point& p, Int* scalar)
{
    if(scalar->IsZero() || scalar->IsEqual(&order))
        exit(NULL);

    string scalarBin = scalar->GetBaseN(2, "01");
    const char* sclarBinChar = scalarBin.c_str();
    Point tempP = p;

    //tempP = DoubleDirect(tempP);
    //cout << "tempP: " << tempP.x.GetBase10() << "\n";

    for (int i = 1; i < strlen(sclarBinChar); i++)
    {
        tempP = DoubleDirect(tempP);

        if (sclarBinChar[i] == sclarBinChar[0])
        {
            //cout << "Add" << "\n";
            tempP = AddDirect(tempP, p);
        }
    }
    return tempP;
}
42  Bitcoin / Development & Technical Discussion / Re: Pollard's kangaroo ECDLP solver on: February 22, 2021, 10:01:09 PM
Hi, Everyone

Test function in this main.cpp file
The file is running with CPU.
How can I run it with the GPU?

Code:

/*
 * This file is part of the BSGS distribution (https://github.com/JeanLucPons/Kangaroo).
 * Copyright (c) 2020 Jean Luc PONS.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "Kangaroo.h"
#include "Timer.h"
#include "SECPK1/SECP256k1.h"
#include "GPU/GPUEngine.h"
#include <fstream>
#include <string>
#include <string.h>
#include <stdexcept>
#include <sstream>

#include <thread>
using namespace std;

#define CHECKARG(opt,n) if(a>=argc-1) {::printf(opt " missing argument #%d\n",n);exit(0);} else {a++;}


int getInt(string name, char* v) {

    int r;

    try {

        r = std::stoi(string(v));

    }
    catch (std::invalid_argument&) {

        printf("Invalid %s argument, number expected\n", name.c_str());
        exit(-1);

    }

    return r;

}

double getDouble(string name, char* v) {

    double r;

    try {

        r = std::stod(string(v));

    }
    catch (std::invalid_argument&) {

        printf("Invalid %s argument, number expected\n", name.c_str());
        exit(-1);

    }

    return r;

}

// ------------------------------------------------------------------------------------------

void getInts(string name, vector<int>& tokens, const string& text, char sep) {

    size_t start = 0, end = 0;
    tokens.clear();
    int item;

    try {

        while ((end = text.find(sep, start)) != string::npos) {
            item = std::stoi(text.substr(start, end - start));
            tokens.push_back(item);
            start = end + 1;
        }

        item = std::stoi(text.substr(start));
        tokens.push_back(item);

    }
    catch (std::invalid_argument&) {

        printf("Invalid %s argument, number expected\n", name.c_str());
        exit(-1);

    }

}
// ------------------------------------------------------------------------------------------

// Default params
static int dp = -1;
static int nbCPUThread;
static string configFile = "";
static bool checkFlag = false;
static bool gpuEnable = false;
static vector<int> gpuId = { 0 };
static vector<int> gridSize;
static string workFile = "";
static string checkWorkFile = "";
static string iWorkFile = "";
static uint32_t savePeriod = 60;
static bool saveKangaroo = false;
static bool saveKangarooByServer = false;
static string merge1 = "";
static string merge2 = "";
static string mergeDest = "";
static string mergeDir = "";
static string infoFile = "";
static double maxStep = 0.0;
static int wtimeout = 3000;
static int ntimeout = 3000;
static int port = 17403;
static bool serverMode = false;
static string serverIP = "";
static string outputFile = "";
static bool splitWorkFile = false;

//Mamu
Secp256K1 secp256k1;
int nbGPUThread;
uint64_t totalRW;
uint64_t counters[256];
int CPU_GRP_SIZE = 1024;

void TestFunc(string ScalarInput)
{

    Int i;
    char* c = const_cast<char*>(ScalarInput.c_str()); //*****************************************************************************************************
    i.SetBase10(c);

    while (true)
    {
        i.AddOne();
        Point aa = secp256k1.ComputePublicKey(&i);

        string PointaX = aa.x.GetBase10();
        string PointaY = aa.y.GetBase10();

        Int s(secp256k1.order);
        s.Sub(&i);
        Point bb = secp256k1.ComputePublicKey(&s);

        string PointbX = bb.x.GetBase10();
        string PointbY = bb.y.GetBase10();

        string num1 = i.GetBase10();
        string num2 = s.GetBase10();

        string Result1 = num1 + " = " + PointaX + " : " + PointaY + "\n";
        string Result2 = num2 + " = " + PointbX + " : " + PointbY + "\n";

        cout << Result1 << "\n";
        cout << Result2 << "\n";




    }
}

void main()
{
    secp256k1.Init();
    cout << "Working..." << "\n";

    string ScalarInput;
    printf("\n\tStart Number : ");

    cin >> ScalarInput;
    TestFunc(ScalarInput);




}
43  Bitcoin / Development & Technical Discussion / Re: Nonce k and k +1 (ECDSA SIGNATURE) on: February 19, 2021, 09:12:59 AM
I would like to remember

The denominator value in mod N with the numbers you gave is 0
Code:
sage: s1*r2-s2*r1
-5870565115156863143967205950922086098709780287420322365789905571260282461016136233055572663350029552122182409141177952688017925412898993949944021339758863

sage: (s1*r2-s2*r1)%N
0


44  Bitcoin / Development & Technical Discussion / Re: Nonce k and k +1 (ECDSA SIGNATURE) on: February 16, 2021, 08:38:35 PM
r1/s1 mod order = r2/s2 mod order

it's same signature, no diffrent signature


Code:
k1 == 109263722787838616791900575947640359553086907200677310074463510255775504782173*x + 33373073398809441106621025265904429856170478887328914010434069704980389675914
k2 == 109263722787838616791900575947640359553086907200677310074463510255775504782173*x + 33373073398809441106621025265904429856170478887328914010434069704980389675915

sage: r1/s1%N
109263722787838616791900575947640359553086907200677310074463510255775504782173

sage: r2/s2%N
109263722787838616791900575947640359553086907200677310074463510255775504782173
45  Bitcoin / Development & Technical Discussion / Re: R value parse from signature on Blockchain input transactions on: January 27, 2021, 08:42:02 AM
If you're looking for double r-values, forget about it!
You are definitely not the first to search the blockchain for it.

I wrote a blockchain explorer that you can use to search for anything in the blockchain. But it's not finished yet and needs a lot of memory and RAM.

Thank you

I will not be looking at repeating R values. I will use it in some tests and at the same time I am trying to learn and develop the parse operation in the blockchain.



Can I export all signatures from blockchain and parse R values of signatures?
There are billions of signatures on the bitcoin blockchain, why do you need to export "all" of them?

Quote
I did it with Python but it's very slow
Do you know a code with C?
Things aren't "very slow" because of the programming language, they are usually slow because of bad code or simply slow process.
As for other code, there are general blockchain parsers but there is no point in extracting signatures alone so there isn't any "good" code for it.

Thank you for the explanation pooya87.

I had such an idea after reviewing the video here.
https://www.youtube.com/watch?v=C6zrPMnyWSw



46  Bitcoin / Development & Technical Discussion / R value parse from signature on Blockchain input transactions on: January 26, 2021, 07:59:41 PM
Hi!

Can I export all signatures from blockchain and parse R values of signatures? Can you suggest a method?

https://gz.blockchair.com/bitcoin/inputs/
from the files at this address
I did it with Python but it's very slow
Do you know a code with C?

Thank you.
47  Local / Türkçe (Turkish) / Re: GPU ile Eliptik Eğri Aritmetiği ve Programlama Hakkında on: December 23, 2020, 07:32:53 AM
RSA için Şadi hocanın videosunu izlemeni öneririm. http://bilgisayarkavramlari.com/2008/03/19/rsa/

Yıllar oldu izledim. Hatta 24-32 bitlik RSA kriptosu için kodlar yazıp public key den private key üreten kodlar da yazıp konunun temel mantığının anlaşılması için yayınladım.

Aslında sormak istediğim çok  detay var. Büyük harflerin noktayı küçük harflerin genelde çarpan olan sayıları ifade ettiğini anladım fakat örneğin xx ifadesi x * x ile aynı anlamamı geliyor yoksa xx ayrı bir değişken mi?

Ayrıca en baştaki soruna dönecek olursak ECdouble, ECadd ve ECmultiply methodlarını sormuştun. Hemen yazayım fakat burada Curve fonksiyonun secp256k1 olması ne anlama geliyor? Buradaki kodlara bakarak aradaki farkı anlatabilir misin?

Sana hemen ECdouble, ECadd ve ECmultiply işlevleri için bir C# kodu yazayım.

Programın çıktısı şöyle ana programa bakarsan bir curve fonksiyonu nasıl tanımlanır? Sonra bir point ile diğer bir point nasıl toplanır ve bir point ile bir skaler nasıl çarpılır aynı matematikte olduğu gibi bir hal aldı ve senin işini çok kolaylaştıracak.

Şimdi bana secp256k1 farkını anlatabilir misin? TODO yazığım yere yalnızca Main fonksiyonunu kullanarak prviate ve public key üretip gönderebilir misin?

O kısım nasıl oluyor?

Programın çıktısı şöyle;

Code:
Hello World!
Sample Add: (0,-4)
Sample Multiple: (-1,3)

Code:
using System;
using System.Text;
using System.Numerics;

namespace TestEllipticCurve
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // TODO: generate private key and public key

            // Örnek CurveFp ve Point nasıl kullanılır?

            var curve = new CurveFp(5, 2, 3);

            var point = new Point(curve, 19, 23);

            var point2 = new Point(curve, 17, 11);

            var sampleAdd = point + point2;

            var skaler = 31;

            var sampleMultiple = point * skaler;

            Console.WriteLine("Sample Add: {0}", sampleAdd);
            Console.WriteLine("Sample Multiple: {0}", sampleMultiple);

            Console.ReadLine();
        }

        class Point
        {
            public static readonly Point INFINITY = new Point(null, default(BigInteger), default(BigInteger));
            public CurveFp Curve { get; private set; }
            public BigInteger X { get; private set; }
            public BigInteger Y { get; private set; }

            public Point(CurveFp curve, BigInteger x, BigInteger y)
            {
                this.Curve = curve;
                this.X = x;
                this.Y = y;
            }
            public Point Double()
            {
                if (this == INFINITY)
                    return INFINITY;

                BigInteger p = this.Curve.p;
                BigInteger a = this.Curve.a;
                BigInteger l = ((3 * this.X * this.X + a) * InverseMod(2 * this.Y, p)) % p;
                BigInteger x3 = (l * l - 2 * this.X) % p;
                BigInteger y3 = (l * (this.X - x3) - this.Y) % p;
                return new Point(this.Curve, x3, y3);
            }
            public override string ToString()
            {
                if (this == INFINITY)
                    return "infinity";
                return string.Format("({0},{1})", this.X, this.Y);
            }
            public static Point operator +(Point left, Point right)
            {
                if (right == INFINITY)
                    return left;
                if (left == INFINITY)
                    return right;
                if (left.X == right.X)
                {
                    if ((left.Y + right.Y) % left.Curve.p == 0)
                        return INFINITY;
                    else
                        return left.Double();
                }

                var p = left.Curve.p;
                var l = ((right.Y - left.Y) * InverseMod(right.X - left.X, p)) % p;
                var x3 = (l * l - left.X - right.X) % p;
                var y3 = (l * (left.X - x3) - left.Y) % p;
                return new Point(left.Curve, x3, y3);
            }
            public static Point operator *(Point left, BigInteger right)
            {
                var e = right;
                if (e == 0 || left == INFINITY)
                    return INFINITY;
                var e3 = 3 * e;
                var negativeLeft = new Point(left.Curve, left.X, -left.Y);
                var i = LeftmostBit(e3) / 2;
                var result = left;
                while (i > 1)
                {
                    result = result.Double();
                    if ((e3 & i) != 0 && (e & i) == 0)
                        result += left;
                    if ((e3 & i) == 0 && (e & i) != 0)
                        result += negativeLeft;
                    i /= 2;
                }
                return result;
            }

            private static BigInteger LeftmostBit(BigInteger x)
            {
                BigInteger result = 1;
                while (result <= x)
                    result = 2 * result;
                return result / 2;
            }
            private static BigInteger InverseMod(BigInteger a, BigInteger m)
            {
                while (a < 0) a += m;
                if (a < 0 || m <= a)
                    a = a % m;
                BigInteger c = a;
                BigInteger d = m;

                BigInteger uc = 1;
                BigInteger vc = 0;
                BigInteger ud = 0;
                BigInteger vd = 1;

                while (c != 0)
                {
                    BigInteger r;
                    //q, c, d = divmod( d, c ) + ( c, );
                    var q = BigInteger.DivRem(d, c, out r);
                    d = c;
                    c = r;

                    //uc, vc, ud, vd = ud - q*uc, vd - q*vc, uc, vc;
                    var uct = uc;
                    var vct = vc;
                    var udt = ud;
                    var vdt = vd;
                    uc = udt - q * uct;
                    vc = vdt - q * vct;
                    ud = uct;
                    vd = vct;
                }
                if (ud > 0) return ud;
                else return ud + m;
            }
        }

        class CurveFp
        {
            public BigInteger p { get; private set; }
            public BigInteger a { get; private set; }
            public BigInteger b { get; private set; }
            public CurveFp(BigInteger p, BigInteger a, BigInteger b)
            {
                this.p = p;
                this.a = a;
                this.b = b;
            }
        }
    }
}


merhaba C# ta da olsa baska bir yerde de

Point1 + Point1  sonucu  "return PointNew"  için dönmesi EliptikEğriAritmetiğinde -> ECdobuble  kullanman gerekir

Point1 + Point2  sonucunu return etmen için EliptikEğriAritmetiğinde -> ECadd kullanman gerekir

Peki Point Nasıl olusacak ?

Onuda GeneratorPoint olarak Gx ve Gy ile üstteki python kodunda yazdım.

48  Local / Türkçe (Turkish) / Re: GPU ile Eliptik Eğri Aritmetiği ve Programlama Hakkında on: December 22, 2020, 08:27:08 PM
Şifreleme yöntemlerini tanımlamak gerekiyor.

Simetrik şifreleme -> Veriyi şifrelediğin anahtarı kullanarak şifreli veriyi çözme için yine aynı anahtarı kullandığın şireleme metodudur. >- AES, DES ..gibi
Asimterik şifreleme -> Veriyi iki anahtar ile şifreleyen şifreleyen ve çözebilen şifreleme method  u olarak düşünebilirsin.-- >> ECDSA , RSA ... gibi


Devamında bunu okumanı öneririm.
https://medium.com/@muhammedkaralar/simetrik-ve-asimetrik-şifreleme-d57673284646#:~:text=Asimetrik%20şifreleme%20%2C%20simetrik%20şifrelemenin%20tersine,günümüzde%20oldukça%20yaygın%20olarak%20kullanılmaktadır.


ancak ECDSA da point işlemleri yapman için EllipticCurve Aritmetiğini kullanırsın.
EllipticCurve Aritmetiğide , Double ve Add üzerine kurulu bir point toplama aritmetiğidir. Nasıl çalıştığını önceki mesajımda bahsettim.


Ne yapmak istediğime gelince aslında girdiğim integer ile  nokta üretmek ve kontrol etmek istiyorum.Ör : 300 olsun

örneğin
Code:

inputInt = 300

i = inputInt % N

while True :
    i=i+1
    A = ((i + 1) % N)*G
    B = ((i * 2) % N)*G
    C = ((i + pow(2,i)) % N )*G
    
    
    if C.x % 35 == 5 :
        print (C,i)
    
    if B.x % 31 == 4 :
        print (B,i)
        
    if A.x % 27 == 17 :
        print (A,i)
49  Local / Türkçe (Turkish) / Re: Bitcoin Algoritmasi 256-SHA Hacklenebilir mi ? on: December 22, 2020, 01:38:05 AM
Merhaba

Kullanıcı tanımlı girişler tavsiye edilmediğinden sık sık kullanılmıyor . İlgili sitedeki adresler sanırım 6 yıl önceki haberdekiler link burada -> https://www.reddit.com/r/Bitcoin/comments/1zti1p/17956_hacked_brainwallet_passwords/


Sha256 bip39 gibi metodlardaki anahtar kelimeler için kullanılıyor bildiğim kadarıyla -> https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki






50  Local / Türkçe (Turkish) / Re: GPU ile Eliptik Eğri Aritmetiği ve Programlama Hakkında on: December 22, 2020, 01:08:34 AM
John_Ahmet değerli bilgiler için teşekkürler.



O kadar çok C kullanamıyorum daha çok matematik ve kriptografi ile ilgiliyim.

VanitySearch un kodunu inceledim. Pubkey i bitcoin adreslerine çeviren bana göre kodu okumamı zorlaştıran bir sürü karşılaştırma var ve kontrol var benim yapmak istediğim işlemler sadece Elliptic Curve de ve Matematiksel

 
Açıkçası Secp256k1 için C de GPU(Nvidia) ile çalışan 3 tane fonksiyon lazım EcAdd, Ecdouble, EcMultipy , İlgilenirsen VanitySearch i modifiye edecek C bilgin varsa yapar mısın ?

Selamlar..
51  Local / Türkçe (Turkish) / Re: Bitcoin Algoritmasi 256-SHA Hacklenebilir mi ? on: December 21, 2020, 09:54:33 PM
Sonuçta bu algoritmayıda üreten bir insan değil mi ? Hemde Amerika'da bir şirket.Peki kendi ürettikleri algoritma ile çalışan bitcoini nasıl ve neden hackleyemiyorlar ?
Demek istediğim private keyleri kendi icat ettikleri algoritma ile tahmin edemiyorlarmı ?

pek mümkün değil çünkü stringleri tuttursanız dahi string üzerinden key üretilmiyor.

OpenSSL deki random_bit fonksiyonu kullanılıyor. Bu bitlerin tahmin edilemesi üzerine toplarca akademik makale var. kısaca sha256 icindeki string data cok uzun bir bir karmaşasıdır.

2013 teki Brainwallet faciasından sonra bu sekilde cüzdan üretimi durdu. Bulan buldu (:
52  Bitcoin / Development & Technical Discussion / Re: Finding base point in elliptical curve = Bitcoin done on: December 16, 2020, 09:33:41 AM
If we search for a curve y2 = x3 + d passing through (1000,2000) then d = -996,000,000. Such big d would give enormous coordinates very fast. Well, small d would grow almost as fast too. Elliptic curve security is based on this effect to a large extent.

A "smaller" curve would be y2 = x3 + 12 with G=(-2,2). The curve is of rank 1, isomorphic to secp256k1 curve mod p, G being the point with smallest height.
2*G = (13, -47)
3*G = (-74/225, 11674/3375)
4*G = (27313/8836, -5352937/830584)
5*G = (14932678/8994001, 109819305542/26973008999)
...


The numbers grow very fast, n*G needs at least 2n bits to represent just the numerator of x coordinate. y grows even faster.

To some extent this could be mitigated by using curves of rank > 1. This means a curve with more than one rational generator. One could relatively easy find a curve of rank 8, the smallest one (in absolute value) is d=−2520963512. The average x would need at least 273 bits to just represent its numerator (when multiplying by <2256).

The highest rank of publicly known curve, isomorphic to secp256k1, is 16. The x coordinate numerator (~245 bits) would fit the RAM of modern supercomputer.

There's no known (easy) way to lift a point mod p to a rational numbers one. It is at least as hard as ECDLP.





Hello j2002ba2

If we have a G index of 2 ** 38 or let's call it a group, its name is BASE38.

example BASE10 key = 8167645757840975234255102487877016845485722317550747028405241086210041306983 * G


29713722170858000878998072904785719749218414354075310360368316055 * BASE38 == 8167645757840975234255102487877016845485722317550747028405241086210041306983 * G

Is it right to think like that?
53  Bitcoin / Development & Technical Discussion / Re: Extracting data from a blk file. on: December 16, 2020, 09:20:08 AM
A block file (blk.dat) is not in human readable form. I wanted to know if there is a way to extract the data of it. For example converting it into text with readable block header, version number, last block, merkle root, time, target and all of the transactions that are included in that block. The same way bitcoin core translates it to JSON.

Hi, you can use this for python -> https://github.com/ragestack/blockchain-parser

54  Local / Türkçe (Turkish) / GPU ile Eliptik Eğri Aritmetiği ve Programlama Hakkında on: December 12, 2020, 12:45:24 AM
Merhaba

Uzun zamandır eliptik eğri kriptolojisi ile ilgileniyorum. Eğri Matematiğinde(sadece nokta toplama) ilgili kütüphaneler mevcut. Windows 10, Sage ve Python kullanabiliyorum.

C bilen bir arkadaşım benim için bu aşağıdaki aritmetik kodunu C de yazdı ve CPU ile gayet hızlı çalışıyor fakat GPU  kadar değil. C konudu GPU üzerinden çalıştırmak için yeterli bilgimiz yok bu yüzden çalıştracak bir yöntem arıyorum.

benzer şekilde pythonda fastecdsa(https://github.com/AntonKueltz/fastecdsa) gibi kütüphanelerde kullandım. Fastecdsa tıpkı Sage gibi pythonda kullanmaya imkan tanıyor. Biginteger problemini C üzerinde kendilerine has bir kütüphane ile çözebiliyorlar. Python u Tensorflow sayesinde GPU ile çalıştırabiliyorum. Fakat  tf-big (https://github.com/tf-encrypted/tf-big) gibi kütüphanelerin windows ta bir karşılığı yok. Tf-Big yeterli olacak mı emin değilim.


Özetle şöyle çıkmaza girdim.
GPU ile çalışmak istiyorum C bilmiyorum.
GPU ile python da çalışabiliyorum ama int64 ten yukarı çıkamıyorum. Biginteger Bitwise ile yapılabilir mi diye araştırdım ama kullanımını anlamadım.Amatör Matematik meraklısı olduğumda algoritma mantığı geliştirsemde bilgisayar limitlerini ve terimlerini anlamakta güçlük çekiyorum. (https://github.com/YulitaGap/BigInteger)


Bitwise bit üzerinden matematik işlemi yapılabilen bir 2 lik tabanda bir sistem midir ? 2 lik tabanda modüler aritmetik nasıl çalışır ?

Kısaca bitwise işlemi kafamı kurcaladı. Pratik olarak işlemi bitler halinde GPU çiplerine işletmek daha hızlı olacaktır diye düşünüyorum.

C üzerinde çalışan OpenCL destekli bir kütüphane de mevcut (https://github.com/ilaychen/ECDSA-OpenCL)

Eğri aritmetiğinde GPU nun  kullanıldığını test ettim. (Bitcrack,Kangaroo,Vanitysearch vs.)

Sorularımı genelde yabancılara soruyorum ilgili Türkler vardır Türkçe konuşalım diye buraya yazdım. Tekrar selamlar teşekkürler.




Bitcoinin kullandığı Eliptik Eğri Aritmetiğinin en basit Python Kodu :

Code:
Pcurve = 2**256 - 2**32 - 2**9 - 2**8 - 2**7 - 2**6 - 2**4 -1 # The proven prime
N=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 # Number of points in the field
Acurve = 0; Bcurve = 7 # This defines the curve. y^2 = x^3 + Acurve * x + Bcurve
Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240
Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424
GPoint = (Gx,Gy) # This is our generator point. Tillions of dif ones possible


def modinv(a,n=Pcurve): #Extended Euclidean Algorithm/'division' in elliptic curves
    lm, hm = 1,0
    low, high = a%n,n
    while low > 1:
        ratio = high/low
        nm, new = hm-lm*ratio, high-low*ratio
        lm, low, hm, high = nm, new, lm, low
    return lm % n

def ECadd(xp,yp,xq,yq): # Not true addition, invented for EC. It adds Point-P with Point-Q.
    m = ((yq-yp) * modinv(xq-xp,Pcurve)) % Pcurve
    xr = (m*m-xp-xq) % Pcurve
    yr = (m*(xp-xr)-yp) % Pcurve
    return (xr,yr)

def ECdouble(xp,yp): # EC point doubling,  invented for EC. It doubles Point-P.
    LamNumer = 3*xp*xp+Acurve
    LamDenom = 2*yp
    Lam = (LamNumer * modinv(LamDenom,Pcurve)) % Pcurve
    xr = (Lam*Lam-2*xp) % Pcurve
    yr = (Lam*(xp-xr)-yp) % Pcurve
    return (xr,yr)

def EccMultiply(xs,ys,Scalar): # Double & add. EC Multiplication, Not true multiplication
    if Scalar == 0 or Scalar >= N: raise Exception("Invalid Scalar/Private Key")
    ScalarBin = str(bin(Scalar))[2:]
    Qx,Qy=xs,ys
    for i in range (1, len(ScalarBin)): # This is invented EC multiplication.
        Qx,Qy=ECdouble(Qx,Qy); # print "DUB", Qx; print
        if ScalarBin[i] == "1":
            Qx,Qy=ECadd(Qx,Qy,xs,ys); # print "ADD", Qx; print
    return (Qx,Qy)

55  Bitcoin / Development & Technical Discussion / Re: Pollard's kangaroo ECDLP solver on: December 01, 2020, 07:33:55 PM
-snip-
I have some functions in Python and it runs very slow compared to C.

The sage I want to do with the GPU is as follows
Code:
Pr = 115792089237316195423570985008687907853269984665640564039457584007908834671663

E = EllipticCurve (GF (P), [0,7])
N = E.order ()

G = E(55066263022277343669578718895168534326250603453777594175500187360389116729240,32670510020758816978083085130507043184471273380659243275938904335757337482424) # on E

T = E(26864879445837655118481716049217967286489564259939711339119540571911158650839,29571359081268663540055655726653840143920402820693420787986280659961264797165) # on E

numInt = 5646546546563131314723897429834729834798237429837498237498237489273948728934798237489723489723984729837489237498237498237498237498273493729847

numMod = numInt %N

numInv = pow(numMod ,N-2,N) # detail -> https://stackoverflow.com/questions/59234775/how-to-calculate-2-to-the-power-of-a-large-number-modulo-another-large-number


numMod * G
numMod * T

(T-G) * numInv



print (5*T)
print (2*G)

print (numMod * G)
print (numMod * (-G))

print (numMod * T)
print ((numMod-3) * (T-G))


Do you have any suggestions? What should I do ?
I wrote my question here because it is indirectly related to this project. Please forgive.

Hi! The slowest part in your python is inverse function. Try to implement gmpy2 inverse function (included in gmpy2) - it is C-based and very fast:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#gmpy

You can find the details here: https://bitcointalk.org/index.php?topic=5245379.msg55214449#msg55214449

Hello MrFreeDragon
Is it possible to write the python code you show with Cython?
Thanks again, my work was faster than before.

Code:
import gmpy2

modulo = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
order  = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
Gy = 0X483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8

class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

PG = Point(Gx,Gy)
Z = Point(0,0) # zero-point, infinite in real x,y - plane

# return (g, x, y) a*x + b*y = gcd(x, y)
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)

def modinv(m, n = modulo):
    while m < 0:
        m += n
    g, x, _ = egcd(m, n)
    if g == 1:
        return x % n

    else: print (' no inverse exist')

def mul2(Pmul2, p = modulo):
    R = Point(0,0)
    #c = 3*Pmul2.x*Pmul2.x*modinv(2*Pmul2.y, p) % p
    c = 3*Pmul2.x*Pmul2.x*gmpy2.invert(2*Pmul2.y, p) % p
    R.x = (c*c-2*Pmul2.x) % p
    R.y = (c*(Pmul2.x - R.x)-Pmul2.y) % p
    return R

def add(Padd, Q, p = modulo):
    if Padd.x == Padd.y == 0: return Q
    if Q.x == Q.y == 0: return Padd
    if Padd == Q: return mul2(Q)
    R = Point()
    dx = (Q.x - Padd.x) % p
    dy = (Q.y - Padd.y) % p
    c = dy * gmpy2.invert(dx, p) % p     
    #c = dy * modinv(dx, p) % p
    R.x = (c*c - Padd.x - Q.x) % p
    R.y = (c*(Padd.x - R.x) - Padd.y) % p
    return R # 6 sub, 3 mul, 1 inv

def mulk(k, Pmulk, p = modulo):
    if k == 0: return Z
    if k == 1: return Pmulk
    if (k % 2 == 0): return mulk(k//2, mul2(Pmulk, p), p)
    return add(Pmulk, mulk((k-1)//2, mul2(Pmulk, p), p), p)



56  Bitcoin / Development & Technical Discussion / Re: Bitcoin Elliptic curve point multiplication results in key ZERO on: November 21, 2020, 08:14:37 PM
what I don't understand is why would multiplying the key I mentioned by 12345 (or 3039 in hex) gives zero?
that is not mathematically possible. the point you posted in OP (04065f5...) is on secp256k1 curve and when it is multiplied by a number smaller than the curve order the resulting point is also already on curve. the correct result is what you posted in this comment (049663999....). the only reason why you get zero is possibly a bug in the tool you are using.

I agree, a bug on gobittest seems more likely as an explanation since if I do the same operation on python I get a different key but the same public address.

Maybe Bug but,  no on EllipticCurve your pubkey( in same time addresses )

May be its same ? -> https://www.blockchain.com/btc/address/1RBanRBanRBanRBanRBanRBan223RWPFp

this address recive bitcoin but can't spent. because it has no pubkey(EC point), just hash160
57  Bitcoin / Development & Technical Discussion / Re: How to do MuSig verify ? on: November 09, 2020, 05:33:05 AM
Do you mean multisig? MuSig is a particular scheme that uses Schnorr signatures and is not available in Bitcoin. The transaction that you refer to is a standard Bitcoin multisig, not MuSig.



Multisigs are verified as normal ecdsa signatures. There are multiple signatures and each one verifies with one of the pubkeys in the multisig. Verification is just normal ECDSA.

I can see pubkey (EllipticCurve Point) belonging to the bitcoin address in standard signatures. but I could not see it in the signature.

actually i was wondering, this is 3LpvrH24YmEAmJ1MUfawDu6pPsm14r2FtV address pubkey

thanks achow101
58  Bitcoin / Development & Technical Discussion / How to do MuSig verify ? on: November 09, 2020, 03:31:18 AM
I was very curious about your mathematics. How MuSig works. How to works hash () funciton M in signatures. Could you share it over a sample signature? I looked at the examples but did not understand. I think I'm learning by applying. Thank you


example transaction

https://www.blockchain.com/btc/tx/0b6b75af54df2311ab718779e06968e3b5d2f53224ffc64282e81116e17094e6


we have

G = EC Generator Point

r1 = 0x17beb671b4a2e7688fc357b7ade7f72bf24eff073bb42950d0fc23c6a7f2af63
s1 = 0x31741ae73667b21ea0229cb8950b9d950d248c26cef0f4871506ff1c47b6e0b9
r2 = 0x71f1950fc6dfa95d4466164e6a8ed7bded41f723733a9799e4e371a868fd3c78
s2 = 0x010820bfbaf0591116076799ba7d30c7e6cd5fa02090de0deb6926a4f7f49e47


P1 = 0325937706eb4d50c16fc2f0ab3ee0b53e1513ebf14e0509bc5b4b09abd395c90a
P2 = 022a1f8e2169dfc64655fa0657537e70d32c584013dd2b8da9a53ab2d260c79ad3
P3 = 02cfc77d383647a00703250f53339bfc2885668daeee3f6c0d34d9f1b2f7a740ab



59  Bitcoin / Development & Technical Discussion / Re: Pollard's kangaroo ECDLP solver on: October 23, 2020, 08:42:16 PM
Thanks brainless

The reason I chose Jean_Luc's project
it can run its own uint_64 (own integer class) with GPU, I'm trying to understand this issue.

Source code includes AddDircet, DoubleDirect and ComputePublicKey (G * int). But EccMultipy (Point x int) does not exist.

I was just in the beginning, I guess this is not the right place to discuss. But even if I only use CPU it is much faster than python. I don't know if it is with a GPU.

I'm not sure what I'm learning, I am not aware of C or C ++ right now, for now (:

" ComputePublicKey (G * int) (G * int). But EccMultipy (Point x int) does not exist. "

G = point
G * int = its eccmultiply (Point x int)

only developer need to design as per above command for easy input/output at gpu work, let see who design it for community

JLuc code  

Pubkey = ComputePublicKey (int); (G in this funciton, and G has some hash algroithm)

brainless

Is it possible to control -2**35 to 2**35  point operation in 3 seconds on CPU?


few sec on gpu

so I want to test a GPU-powered ECC operation with the GPU running at full performance. I have a few studies that I have tested with Sage,
I'm looking for a library that works with GPU where I can create functions and loops it in C or C ++.

Thanks for your interest brainless
60  Bitcoin / Development & Technical Discussion / Re: Pollard's kangaroo ECDLP solver on: October 23, 2020, 08:12:46 PM
Thanks brainless

The reason I chose Jean_Luc's project
it can run its own uint_64 (own integer class) with GPU, I'm trying to understand this issue.

Source code includes AddDircet, DoubleDirect and ComputePublicKey (G * int). But EccMultipy (Point x int) does not exist.

I was just in the beginning, I guess this is not the right place to discuss. But even if I only use CPU it is much faster than python. I don't know if it is with a GPU.

I'm not sure what I'm learning, I am not aware of C or C ++ right now, for now (:

" ComputePublicKey (G * int) (G * int). But EccMultipy (Point x int) does not exist. "

G = point
G * int = its eccmultiply (Point x int)

only developer need to design as per above command for easy input/output at gpu work, let see who design it for community

JLuc code  

Pubkey = ComputePublicKey (int); (G in this funciton, and G has some hash algroithm)

brainless

Is it possible to control -2**35 to 2**35  point operation in 3 seconds on CPU?
Pages: « 1 2 [3] 4 »
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!