monero-integrations / monerowp

Monero WooCommerce Plugin for Wordpress
MIT License
105 stars 74 forks source link

Decrypting payment id in Monero_Cryptonote results in infinite loop #81

Open Olsm opened 5 years ago

Olsm commented 5 years ago

On xmrchain.net it says “payment_id8” instead of the previous “payment_id”. The “payment_id8” is the short payment id and in encrypted form. We need to decrypt the encrypted payment id to compare it with the real payment id (which was used when generating the integrated address. I think I found a function for this in monerowp called stealth_payment_id with comment this is a one way function used for both encrypting and decrypting 8 byte payment IDs

I called said function like so:

monero_cryptonote()->stealth_payment_id( $tx['payment_id8'], monero_cryptonote()->txpub_from_extra( $tx['extra'] ), $options[ 'xmr_view_key' ] )

However it ends up in an infinite loop in function scalarmult at line 181 in monerowp/include/crypto/ed25519.php

The code below works and this is actually what monero_payments in monerowp is doing with function verify_non_rpc but this is a horrible way to do it for performance. Every single tx in a block is making an api call to xmrchain in the $tools->check_tx function. and that took almost 1 second per tx in the last test I did. For this reason previously I made it so it would check if the tx has a matching payment id before it calls check_tx, rather than calling it for every single tx block by block. As soon as we manage to decrypt the payment_id so we can match it, we can continue having this performance benefit.

    $tools    = new NodeTools();
    $tx_found = false;

    foreach ( $txs as $tx ) {
        // TODO: Only call check_tx if payment id is found
        //$decrypted_payment_id = $tx['payment_id8'] ? monero_cryptonote()->stealth_payment_id( $tx['payment_id8'], $tx['tx_hash'], $options[ 'xmr_view_key' ] ) : '';
        //if ( $decrypted_payment_id == $payment_id ) {
            $tx_hash = $tx[ 'tx_hash' ];
            $result  = $tools->check_tx( $tx_hash, $order->address, $options[ 'xmr_view_key' ] );
            if ( $result ) {
                $tx_found             = $tx;
                $tx_found[ 'output' ] = $result;
                break;
            }
        //}
    }