janus / vanity-petra

MIT License
1 stars 1 forks source link

Not generating the expected address #1

Open janus opened 5 years ago

janus commented 5 years ago

We would like to use vanity-petra to generate a random private key and corresponding public key, but we noticed that we are not getting the right address when importing the keystore file to the Petrachor client. We are using BLS12-381, and we have created a wasm file to interface with JavaScript. Petrachor is C++ and based on ethereum-cpp so this should be familiar for Ethereum developers. We need private keys created by vanity-petra to produce the same Petrachor address that is produced when imported into the Petrachor client.

Live Demo of vanity-petra: https://janus.github.io/vanity-petra/

Install instructions for the Petrachor Client: https://github.com/petrachor/petrachor/wiki/Ubuntu-and-Debian-Build-From-Source

Once you have compiled from source, navigate to ~/petrachor/build/petrachor-key

To import a keystore file generated from vanity-petra $ ./petrachor-key importbare

To inspect the imported key $ ./petrachor-key inspectbare

The result of inspectbare will display the address produced by the Petrachor client, and this should match the address produced by vanity-petra.

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 1.7 ETH (306.65 USD @ $180.38/ETH) attached to it as part of the https://github.com/petrachor/ fund.

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Cancelled


Work has been started.

These users each claimed they can complete the work by 2 weeks, 6 days from now. Please review their action plans below:

1) akersof has been approved to start work.

As i wrote on github you have all the details, and a proof as i already made this kind of job. We will need to talk on the real scope of the code you want to run.

Learn more on the Gitcoin Issue Details page.

janus commented 5 years ago

@akersof, Can you do this in two days? And Have you really worked on BL12_381 algo? This is not as easy as getting a public address from crypto libs when dealing with Ethereum.

janus commented 5 years ago

@gutsal-arsen , You mentioned CSA thing , why? I know that you got speed , but do you have the right skill set for this task?

janus commented 5 years ago

@mul1sh , One week is pretty much for me. And have you really worked with BL12_381?

janus commented 5 years ago

@mul1sh , thanks for the feed back. But one can you G2 for public key, and G1 for verification or the other way round. We chose G2 for public key, and it has nothing to do with what we are experiencing . Petrachor client creates acceptable keys for us, however the one created by vanity-petra tends to differ from Petrachor when the keystore is imported into Petrachor client.
We don't need rust here, we are playing with JavaScript, you can develop wasm file. That is what we have done. Please go through our question

akersof commented 5 years ago

@janus, Well i stopped the job apply on gitcoin because 2 days will be short for me, i would be available only from the wednesday for the coming week. And yes i already worked on address generation from a random number (the private key) to an address on the bitcoin side. All the ecdsa stuff should be the same, on Ethereum, for getting a public key, and from a public key the generation of an address is pretty easy. As a proof i made in javascript check: Elliptic curve and Secp256k1. So yeah i am pretty aware of all the math and crypto stuff behind it, but i am not sure you can wait for me to start working wednesday on it. p.s: this is a POC and everything was done manually without a bitcoin or ethereum lib, ofc i would use a more maintained library for doing calculation like Extended Euclidean algorithm and modular multiplicative inverse if one exists but at the time i wrote the code i didn't find a good javascript lib for doing this well

janus commented 5 years ago

@janus, Well i stopped the job apply on gitcoin because 2 days will be short for me, i would be available only from the wednesday for the coming week. And yes i already worked on address generation from a random number (the private key) to an address on the bitcoin side. All the ecdsa stuff should be the same, on Ethereum, for getting a public key, and from a public key the generation of an address is pretty easy. As a proof i made in javascript check: Elliptic curve and Secp256k1. So yeah i am pretty aware of all the math and crypto stuff behind it, but i am not sure you can wait for me to start working wednesday on it. p.s: this is a POC and everything was done manually without a bitcoin or ethereum lib, ofc i would use a more maintained library for doing calculation like Extended Euclidean algorithm and modular multiplicative inverse if one exists but at the time i wrote the code i didn't find a good javascript lib for doing this well

@akersof Please reply ... I want to give it to you

akersof commented 5 years ago

@janus Well i reapplied again, please confirm work, and let's talk about the scope

janus commented 5 years ago

Approved. Ask any question.

akersof commented 5 years ago

@janus , i checked my maths and algorithms, and so far i am getting the right pubkey for a given private key, as you know it is sensitive part so i would really check and check it again twice. My questions: 1) This address generation process will be run in the browser or on a node.js backend? 2) Do you still need a random private key generation or you provide it ? 3) Are you Ok if i code for you a self-contained function, you can optionally provide a private key as parameter, if none is provided i would generate one then, and the function will return an object like {privKey: 0x0....., pubKey: 0x...., address: 0x0Fe25D70F.....}. 4) Or you are more into bug hunting and you want me to fix what is already coded and faulty running?

janus commented 5 years ago

@akersof ,

  1. Please take a look, https://github.com/petrachor/pairing-ariel. This is the code we are using, it is in Rust. We are using G2 for Public key , and G1 for signing. Please check out these files: https://github.com/petrachor/petrachor/blob/master/libdevcrypto/BLS12_381.cpp https://github.com/petrachor/petrachor/blob/master/libdevcrypto/BLS12_381.h https://github.com/petrachor/petrachor/blob/master/libdevcrypto/Common.h https://github.com/petrachor/petrachor/blob/master/libdevcrypto/Common.cpp

Below tells you more about private key generation.

template <class C> class KeyPair {
    static const unsigned char addressPrefix = 0xF1;
public:
    typedef typename C::Secret Secret;
    typedef typename C::Public Public;
    /// Normal constructor - populates object from the given secret key.
    /// If the secret key is invalid the constructor succeeds, but public key
    /// and address stay "null".
    KeyPair(Secret const& _sec) :
        m_secret(_sec),
        m_public(toPublic<C>(_sec))
    {
        // Assign address only if the secret key is valid.
        if (m_public)
            m_address = toAddress<C>(m_public);
    }

    /// Create a new, randomly generated object.
    static KeyPair create(bool icap = false, unsigned firstByte = addressPrefix) {
        while (true)
        {
            KeyPair kp(Secret::random());
            while (!kp.address()
                   || (icap && (kp.address()[0] ^ firstByte)))
                kp = KeyPair(Secret(sha3(kp.secret().ref())));
            return kp;
        }
    }

Or you are more into bug hunting and you want me to fix what is already coded and faulty running? Great go to vanity-pretra, and figure out why it secret key generates a different address when imported into petrachor client. If you can do this ... I am okay...

Do you still need a random private key generation or you provide it ? Please check vanity-petra file vanity.js and see what we have there. Use any random key generator that is stable and reliable

This address generation process will be run in the browser or on a node.js backend? Browser please

If you have more questions please don't hesitate to ask

akersof commented 5 years ago

@janus Ok i investigate your code base, fyi i already know how to do it from scratch, but curious to know what is wrong in your code. I start working on it in few hours

janus commented 5 years ago

@akersof , I prefer starting from scratch ....

As I have stated it creates public key that is different from petrachor client. I have not pinned it down yet

gitcoinbot commented 5 years ago

@akersof Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


@akersof due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Cancelled


The funding of 1.7 ETH (321.89 USD @ $189.35/ETH) attached to this issue has been cancelled by the bounty submitter