11

Is it possible to calculate sha256 hashes in the browser using the user's video card, eg. by using WebGL or Flash?

I'm afraid this is all there is to ask, but if more elaboration is needed please do not hesitate to tell me in a comment.

Thanks.

Tom
  • 8,536
  • 31
  • 133
  • 232
  • 8
    Do you want to abuse your website visitors to generate bitcoins for you? ^^ – sod Jun 18 '11 at 12:11
  • @sod, not personally, but generally interested to see whether this is going to be something we might see in the future – Tom Jun 18 '11 at 12:19
  • Any news on a successful implementation? Is this really possible without loosing too much performance? – Dpp Apr 24 '12 at 15:01
  • i think this idea could be utilized to create a new block chain that can just be joined using a browser tab. node count could provide security. idk. – toraman Dec 27 '21 at 20:12

3 Answers3

7

This should be possible. Given an implementation of SHA as a fragment shader, you should be able to read back the results using readPixels:

Read Back Pixels [5.13.12] Pixels in the current framebuffer can be read back into an ArrayBufferView object.

void readPixels(int x, int y, long width, long height, enum format, enum type, Object pixels)

format: RGBA

type: UNSIGNED_BYTE

From the Kronos WebGL reference card (PDF)

For extra credit, do it all in an offscreen framebuffer, as described here.

laslowh
  • 8,482
  • 5
  • 34
  • 45
  • that sounds promising. I wonder though, how does one save a sha256 string as a formation of pixels? Or am I not completely following you? – Tom Jun 29 '11 at 18:29
  • Yes, store the result of the computation in a 1xN pixel framebuffer, then just read out the values. – laslowh Jun 29 '11 at 22:56
  • Take a look at these phenomenal tutorials at learningwebgl.com. Specifically, if you look at Lesson 1 at http://learningwebgl.com/blog/?p=28 . The key would be in the fragment shader (look for "shader-fs"). Anything that is written to gl_FragColor would be subsequently readable using readPixels() – laslowh Jun 30 '11 at 13:34
1

Looks like this can be done (although in this case it's not SHA256). The following is an example of a JavaScript library that uses WebGL2 to calculate hash values on the client side, for the Curl hashing algoritm: https://github.com/iotaledger/curl.lib.js/

In this case it's used to do Proof of Work for an IOTA transaction (https://www.iota.org/get-started/what-is-iota). This basically comes down to brute-forcing random inputs into the same hash function until the result matches a certain output. Therefore the gained hashing speed by using WebGL is very relevant. I have used it, and it works!

0

The next version of the Flash player (11) will support real hardware accelerated graphics, thus exposing the possibility to run pixel shaders on the graphics card. They could atleast in theory be used for general purpose computing.

There are some examples on Thibault Imberts blog.

grapefrukt
  • 27,016
  • 6
  • 49
  • 73
  • Interesting, although WebGL also allows hardware accelerated graphics. I wonder, can either of these be used for general purpose computing? – Tom Jun 20 '11 at 16:40