contrib: Ask for captcha in signet getcoins.py #23162

pull laanwj wants to merge 1 commits into bitcoin:master from laanwj:2021-10-getcoins changing 1 files +91 −3
  1. laanwj commented at 3:20 AM on October 2, 2021: member

    As the faucet will always ask for a captcha now, the current script is no longer usable.

    Change the getcoins.py script to print the captcha in dot-matrix to the terminal, using unicode Braille characters.

    $ ./getcoins.py  -a tb1q9srj96uj4uk5gva9k7h2zxuy6ttu7ltsagu0gl
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠙⠢⢄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠑⠢⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠴⠊⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠀⢦⣄⣀⠀⠀⠀⠉⠒⠤⣀⠀⠀⢀⣀⠄⠀⠀⠀⠀⠀⢀⣀⣀⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠤⠊⠁⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠀⠀⠹⣍⠹⣦⡀⠀⠀⠀⢀⡿⢻⣿⣿⠋⠀⠀⠀⠀⢸⠋⢩⣤⣴⣿⠃⠀⠀⠀⠀⠀⠀⠈⡟⠓⠒⠒⠖⠒⢛⣿⡖⠀⠀⠀⠀⠀⡶⠒⠛⠛⠒⠒⠶⣄⠴⠊⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢳⡈⢻⣄⠀⣰⠏⣴⣿⠟⠀⠉⠓⠢⢄⣀⣸⡀⢸⣿⠋⠉⠀⠀⠀⠀⠀⠀⠀⠀⣧⠀⣿⣿⣿⠿⠿⠟⠃⠀⠀⠀⠀⠀⣷⠀⣾⣿⡿⣷⠊⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣆⠹⣾⢃⣾⣿⠋⠀⠀⠀⠀⠀⠀⢸⣟⡓⣾⣟⣯⡄⠀⠀⠀⠀⠀⠀⠀⠀⡿⠐⣛⡛⠛⠲⣄⠀⠀⠀⠀⠀⠀⢀⡸⣷⡻⢯⡤⢟⣼⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣧⢠⣾⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⣿⣿⠛⠏⠓⠒⠤⠤⣀⣀⣀⠀⠛⣿⡿⠿⠿⣆⣹⣧⡠⠤⠔⠒⠉⠁⣰⠟⣥⣶⣶⣌⠹⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡿⢸⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⣉⠉⠉⠉⢉⡏⢸⣿⡀⠀⠀⠀⠀⠀⡟⢸⣿⠏⠉⢹⡆⣻⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠈⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠛⠳⠶⠶⠛⣁⣼⣿⡇⠀⠀⠀⠀⠀⣧⠈⠻⠶⠶⠛⣀⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠿⠿⢷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠿⠿⠿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠻⠿⣿⣿⣿⣿⡿⠿⠀⠀⠀⠀⠀⠀⠈⠻⠿⣿⣿⣿⣿⣿⠿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    Enter captcha: Yf58
    Payment of 0.00100000 BTC sent with txid e0a96a2a768d1ae0d22eaa2942476927d956445276bdf508dfd2f0e2e836f300
    

    The only added dependency is that convert from ImageMagick (or compatible fork) is installed.

    Captchas are disabled by default for custom faucets, but it is possible to specify a custom captcha URL on the command line.

    Also adds a way to change the amount requested with e.g. -n 0.1.

    Edit: credit where credit is due, yope gave me the idea of using Braille characters as a widely available way to do graphics in the terminal. Another possibility is 2x2 block characters but it is a lot less compact. Yet another one is VT340 Sixel graphics but it's not supported in many terminal emulators.

  2. laanwj added the label Utils/log/libs on Oct 2, 2021
  3. laanwj requested review from kallewoof on Oct 2, 2021
  4. laanwj force-pushed on Oct 2, 2021
  5. laanwj force-pushed on Oct 2, 2021
  6. contrib: Ask for captcha in signet getcoins.py
    As the faucet will always ask for a captcha now, the current script is
    no longer usable.
    
    Change the script to print the captcha in dot-matrix to the terminal,
    using unicode Braille characters.
    a6d9675d60
  7. laanwj force-pushed on Oct 2, 2021
  8. kallewoof commented at 4:07 AM on October 2, 2021: member

    This is incredible! Alternative would be to do the heavy lifting (unicode-ifying) server-side, but that might be too DoS-risky. Testing as soon as ImageMagick finishes installing.

  9. kallewoof commented at 4:17 AM on October 2, 2021: member

    Tested ACK a6d9675d604827892e31a47994af3b64440f66db

  10. laanwj commented at 4:38 AM on October 2, 2021: member

    This is incredible! Alternative would be to do the heavy lifting (unicode-ifying) server-side, but that might be too DoS-risky Testing as soon as ImageMagick finishes installing.

    That's a good point! Even having to render the image as a bitmap on the server side might be more DoS-risky.

    FWIW, I first used Pillow on the Python side, but it doesn't currently support SVG. so I worked around it by using ImageMagick to convert to a trivial image format (PPM) and loading that manually. If the image format was changed to something else we could use Pillow, instead. But I'm not really sure it's a more convenient dependency than ImageMagick.

  11. lsilva01 approved
  12. lsilva01 commented at 4:48 AM on October 2, 2021: contributor

    Awesome solution for this problem.

    Tested ACK a6d9675d on Ubuntu 20.04 with the command below: ./contrib/signet/getcoins.py -i /usr/bin/convert -c /path/src/bitcoin-cli -- -signet -datadir=/path/bitcoin -rpcwallet="w1"

  13. MarcoFalke commented at 7:28 AM on October 2, 2021: member

    Might be nice to use python tensorflow to pre-solve the captcha for the user

  14. dunxen commented at 10:55 AM on October 2, 2021: contributor

    Tested ACK a6d9675

    Screenshot from 2021-10-02 12-51-19

  15. shaavan approved
  16. shaavan commented at 1:00 PM on October 2, 2021: contributor

    ACK a6d9675d604827892e31a47994af3b64440f66db Tested successfully on Ubuntu 20.04

    Screenshot: PR

    This is quite a significant addition for the bitcoin-cli. Also, the addition of now to able choose the requested amount is cherry on the cake. I do have to mention, though; the captcha looks so beautiful on the command line!

    <p>

  17. theStack commented at 7:55 PM on October 2, 2021: member

    Very neat, Concept ACK!

  18. stratospher commented at 8:11 PM on October 2, 2021: contributor

    Tested ACK a6d9675 on macOS 10.15.7. This PR:

    • Fetches the captcha in res and uses imagemagick to convert it into pixel representation(stored as bytes object).
    • It’s then stored as RGB tuples in self._grid and uses print_image() to print the braille unicode characters.

    To prevent spamming of faucet requests, faucet fund requests check captcha and with this script, the captcha gets printed in the terminal so that the script can work again. It’s a great solution!

    Screenshot 2021-10-02 at 4 35 31 PM

  19. practicalswift commented at 8:59 AM on October 3, 2021: contributor

    Concept ACK

    I love this idea and what a nice compact implementation. Impressive in its simplicity!

  20. yanmaani commented at 11:08 AM on October 3, 2021: none

    utACK.

    Theoretically, it is possible to do it in non-unicode terminals using normal ASCII. It doesn't look as pretty though. There's some very advanced algorithms for this, but a dumb pixel_value = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'."[n] ought to do for simple purposes like this.

    You may also want to get ImageMagick to do the binarization. It has a bit more sophisticated facilities for that, if the captcha ever gets harder.

  21. luke-jr commented at 7:03 PM on October 3, 2021: member

    Viewing the opening comment in Chromium makes it look very unreadable, but the screenshots others have posted look fine.

  22. theStack approved
  23. theStack commented at 9:12 PM on October 3, 2021: member

    tACK a6d9675d604827892e31a47994af3b64440f66db ♟️

    Tested with OpenBSD 6.9, worked like a charm after installing the ImageMagick package. The converted captcha output looks good and is well-readable. Also tried out all of the three newly introduced parameters --imagemagick, --amount and --captcha (though for the last I only tested the failure case due to a lack of alternative signet faucets).

  24. kallewoof approved
  25. laanwj commented at 8:12 AM on October 5, 2021: member

    Theoretically, it is possible to do it in non-unicode terminals using normal ASCII. It doesn't look as pretty though. There's some very advanced algorithms for this, but a dumb pixel_value = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,"^`'."[n] ought to do for simple purposes like this.

    Feel free to add another mode, if you can get that readable enough. Preferably without adding a dependency on libaa or such, or a lot of code, at least this is straightforward and looking at the comments here, unicode Braille support is common enough.

    You may also want to get ImageMagick to do the binarization. It has a bit more sophisticated facilities for that, if the captcha ever gets harder.

    That's an interesting suggestion. It can also do dithering instead of a naive threshold, which might or might not help. I didn't initially want to rely on ImageMagick too much, in case the image format changes to something that Pillow can natively handle, but as it's not using that anymore, it doesn't seem bad to commit further to that direction.

    Edit: I tried adding -monochrome but this doesn't seem to make it better, if anything it gets slightly more noisy (see especially the "e"). I think I prefer to keep it like this: captcha-faucet-comparison

  26. ghost commented at 11:05 AM on October 5, 2021: none

    Concept ACK

    I had suggested captcha in #22565 (comment)

    Although now that I was thinking about possible ways to test this, there is one issue which can be managed by adding a warning that "captcha" is based on third party URL.

    If the website gets hacked, attacker can show something else instead of regular captcha.

  27. laanwj commented at 11:52 AM on October 5, 2021: member

    Although now that I was thinking about possible ways to test this, there is one issue which can be managed by adding a warning that "captcha" is based on third party URL.

    As far as I know, the captcha is generated on the same host as the faucet itself. The faucet could already return any kind of information in an error that is printed directly to the console (including control characters, any unicode and escape sequences). The captcha isn't worse in that sense. If you want to harden it you could do various things:

    • Sanitize any strings coming from the faucet.
    • Require the captcha to be in a specific image format (this is currently left open), by making the input -:svg. This is a compromise as it would limit flexibility to change image formats in the future.
    • Limit the size/complexity of the SVG, limit dimensions—don't know if ImageMagick has introspection into this before actually rendering the thing, you might need a sifferent SVG parser.

    You're welcome to work on this but I see it as outside the scope of this pull request.

  28. laanwj merged this on Oct 5, 2021
  29. laanwj closed this on Oct 5, 2021

  30. DrahtBot locked this on Oct 30, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me