moneroexamples / onion-monero-blockchain-explorer

Onion Monero Blockchain Explorer
https://xmrchain.net
BSD 3-Clause "New" or "Revised" License
362 stars 269 forks source link

Unable to decrypt transaction inputs with the API #261

Closed ACK-J closed 2 years ago

ACK-J commented 2 years ago

Through the GUI I can decode the outputs of a transaction and then there is a drop down that shows the decoded inputs. How can I accomplish this through the API? The closest thing I have found in the documentation is:

# we use here official Monero project's donation address as an example
curl  -w "\n" -X GET "http://127.0.0.1:8081/api/outputs?txhash=17049bc5f2d9fbca1ce8dae443bbbbed2fc02f1ee003ffdd0571996905faa831&address=44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A&viewkey=f359631075708155cc3d92a32b75a7d02a5dcf27756707b47a2b31b21c389501&txprove=0"

I want to be able to point to the correct ring in the ring signature.

ACK-J commented 2 years ago

I found where in the code base that the ring signature is referenced within the API

https://github.com/moneroexamples/onion-monero-blockchain-explorer/blob/9a37839f37abef0b8b94ceeba41ab51a41f3fbd8/src/page.h#L1826-L1831

moneroexamples commented 2 years ago

Thanks, I will look into it. Also can you confirm which branch of monero and explorer do you use?

ACK-J commented 2 years ago

Thank you so much for all your work! @moneroexamples

master-2021-11-20-efb7f97 (1.2)

monero version: 0.17.3.0-72e778a04

Running the command: ./xmrblocks --testnet --enable-json-api --enable-autorefresh-option --enable-emission-monitor --enable-pusher

moneroexamples commented 2 years ago

Can you please double check? I just tested it and it seems to be working:

curl  -w "\n" -X GET "http://127.0.0.1:8081/api/outputs?txhash=17049bc5f2d9fbca1ce8dae443bbbbed2fc02f1ee003ffdd0571996905faa831&address=44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A&viewkey=f359631075708155cc3d92a32b75a7d02a5dcf27756707b47a2b31b21c389501&txprove=0"

{
  "data": {
    "address": "42f18fc61586554095b0799b5c4b6f00cdeb26a93b20540d366932c6001617b75db35109fbba7d5f275fef4b9c49e0cc1c84b219ec6ff652fda54f89f7f63c88",
    "outputs": [
      {
        "amount": 34980000000000,
        "match": true,
        "output_idx": 0,
        "output_pubkey": "35d7200229e725c2bce0da3a2f20ef0720d242ecf88bfcb71eff2025c2501fdb"
      },
      {
        "amount": 0,
        "match": false,
        "output_idx": 1,
        "output_pubkey": "44efccab9f9b42e83c12da7988785d6c4eb3ec6e7aa2ae1234e2f0f7cb9ed6dd"
      }
    ],
    "tx_confirmations": 1242159,
    "tx_hash": "17049bc5f2d9fbca1ce8dae443bbbbed2fc02f1ee003ffdd0571996905faa831",
    "tx_prove": false,
    "tx_timestamp": 1492286660,
    "viewkey": "f359631075708155cc3d92a32b75a7d02a5dcf27756707b47a2b31b21c389501"
  },
  "status": "success"
}

It returns 34980000000000 just like using web version. Or maybe you would expect other result?

ACK-J commented 2 years ago

image This tells me which input was the true public key spent, which I can then go and see what position it is in the ring signature

moneroexamples commented 2 years ago

Without spend key its not possible to reliably decode key images to find "true" outputs used in an outgoing transaction. Thus its not available in the API as to not cause confusion of "strange" result that can be obtained.

ACK-J commented 2 years ago

Okay that logically makes sense, but then how does the UI show decoded inputs of a transaction? Also is there another way that I could determine the true spend in my own ring signature programmatically?

moneroexamples commented 2 years ago

When this functionality was added to GUI, it was much easier to guess the true outputs, way before RingCT. API was added later, and there was little benefit of adding API for that as well at that point.

Without spend key, its not possible to determine true outputs. But I developed other program (https://github.com/moneroexamples/transactions-export) which allows to check how your outputs were used in RingCT. For example, to check which outputs of yours are most "popular".

ACK-J commented 2 years ago

Yea I've been using your xmr2csv and its a great tool, my issue is that it only exports other transactions including my output as a decoy. In my specific scenario I'm looking to export the same information as xmr2csv but for my own transactions. It would be cool if xmr2csv could export the following info for a users transactions, not decoys. Timestamp,Block_no,Tx_hash,Output_pub_key,Key_image,ring_no/ring_size Most importantly is the last field that details the position of the true spend in the ring signature.

In regards to your last comment, should I not be considering the GUI's decoded inputs to be accurate? I'm just confused if it not accurate how is it decoding which input in the ring signature was the true spend?

moneroexamples commented 2 years ago

You are making good point about GUI. Maybe its time to remove it or have it disabled by default, as it will be even less useful with the new HF when ring size will be increased to 16.

I will have a look at xmr2csv and check if adding ring_no/ring_size would be reasonably "easy" to add.

moneroexamples commented 2 years ago

@ACK-J

Guessing outputs is now disabled by default in a devel branch of the explorer.

ACK-J commented 2 years ago

Sounds good, nice work!

ACK-J commented 2 years ago

Actually, I should probably keep everything open until it's merged.

moneroexamples commented 2 years ago

devel branch usually gets merged to master when monero HFs happen, as devel branch of the explorer is kept to work with current master branch of monero. The master branch of monero sis basically its development branch for future releases.