shift-reality / php-crypto

A Pure PHP (without any external PHP-extension) Implementation of BLAKE-256, GROESTL-256, JH-256, SKEIN-256 cryptography algorithms.
Apache License 2.0
12 stars 6 forks source link

cool project #1

Closed wyattzheng closed 6 years ago

wyattzheng commented 6 years ago

are you going to build a php-miner of Monero coin? they are all algos that CryptoNote mentioned

thanks to your contributions!

wyattzheng commented 6 years ago

i can't understand why the implements of algos need extensions.it should be pure php like this project

shift-reality commented 6 years ago

Yes, i tried to implement cryptonight algo... But without direct access to machine instructions (like intel 128 bit integers) is very slow.. Extensions is written on C language and muuuuch faster than pure PHP. And CN also require fast random memory r/w...-I can't found work-around of this problem....

shift-reality commented 6 years ago

Final variant of php-miner produce 1 hash per 15-30 seconds)) Incredible speed

wyattzheng commented 6 years ago

that is too slow,and that is why CN algo can prevent ASIC,fast memory speed is needed.have you try running phpminer at local machine

shift-reality commented 6 years ago

Yes, i running performance tests using php-cli (machine is 8-core AMD processor, 8GB RAM, debian 9) so slow...

Maybe need look to /dev/shm or some other fast memory, but this to invoke syscall to read/write and probably increase mem access time... No solution

wyattzheng commented 6 years ago

that is a bad news.php 7.0 is 2 times faster than php5.6. hope php can provide cpu cache mem interface,or really no solution.i will use your algo implements to build a phpminer to start my tests

wyattzheng commented 6 years ago

i noticed that CryptoNight for NodeJs works well.have you read coinhive source codes? 3H/s it can reach in my PC.Theoretically,php should work as well as nodejs

shift-reality commented 6 years ago

i test on php 7.2 with opcache. You can use code as you want and anywhere...) Please tell me you result stat when all is done

Theoretically,php should work as well as nodejs :)

wyattzheng commented 6 years ago

all right,thanks

wyattzheng commented 6 years ago

i start perf test of these codes,i found that oaes_mix_cols cause too much times,when i disable this,the efficiency increase to 3 times higher than before

wyattzheng commented 6 years ago

also, 'global' is toooooooooooooooo slow

wyattzheng commented 6 years ago

those array with many default value spend much time,i think they can combine into a string,then substring them

shift-reality commented 6 years ago

I think about this... And PHP can apply bitwise operations to string like XOR so, faster XOR 2 strings fully than 2 arrays of N elements because ^ is operator, and perform 1 operation to any-length string "hello"^"12345" equals to five ops: h^1 e^2 l^3 ...

shift-reality commented 6 years ago

also need to unroll all loop, if's... etc

shift-reality commented 6 years ago

oaes is totally copied from C lang and adopted to PHP lang.. without any changes

About coinhive: -In browser used WebAssembly -nodejs load external dll/so with miner (i believe)

wyattzheng commented 6 years ago

30seconds a hash is too slow,i think there are still spaces to optimize the codes.although it can not achieve the speed like WebAssembly.

shift-reality commented 6 years ago

There is another problem, cryptonight use AESENC x86 instruction: https://www.felixcloutier.com/x86/AESENC.html But PHP don't obtain this feature never

shift-reality commented 6 years ago

I thing general problem is in AESENC.. because extra hashes is supplimental and take less of 0.01% of all time, non-critical

wyattzheng commented 6 years ago

right,One Round Aes spends almost full of time

shift-reality commented 6 years ago

Any working solution? maybe need check built-in extensions? Like bcmath?

wyattzheng commented 6 years ago

using extensions rathan than writing whole the CN algo into a extension.I'm trying as much as possible to optimize the codes without a extension so i can upload this to freehost to earn XMR-coin

wyattzheng commented 6 years ago

hey man,look this https://github.com/ZhyMC/phpminer

wyattzheng commented 6 years ago

i code mine.php and found a solution of SubAndShiftAndMixAddRoundInPlace,this is very fast and i have verified it's correct.but i haven't finish mine.php, hope tonight i can finish it

shift-reality commented 6 years ago

Good But where you found cryptonight file ? I missed and not uploaded to github maybe)

wyattzheng commented 6 years ago

i code it by myself spend over 20 hours.your blake256.php work in 64bit system caught some problems,so i have to fix it

shift-reality commented 6 years ago

how much hashes now?

wyattzheng commented 6 years ago

20~30secs a hash just like yours,but i prepare to optimize codes when i finish the phpminer

wyattzheng commented 6 years ago

i gonna use microtimes to check Timings.See which part is most slow and try to do a change

shift-reality commented 6 years ago

i uploaded cn.php may it's help you, don't know

wyattzheng commented 6 years ago

i almost finish the cn.php myself, hahaha

shift-reality commented 6 years ago

what is problem with blake256?

shift-reality commented 6 years ago

maybe don't upload updates to project until it's ready and final stats available?)

wyattzheng commented 6 years ago

it's about PHP_INT_MAX, php allow a number > 2147483647 when environment is 64bit,but somethings we need integer overflow

wyattzheng commented 6 years ago

try to make it 0.1H/s,i think it's possible,and over this speed the project start to be a kind of useful,

shift-reality commented 6 years ago

ok

You debug hash func's, and after i finalize it - write usefull library,make code good write unit-tests for hash fn-s... etc and you add this as composer dep :)

shift-reality commented 6 years ago

so i write crypto-library, you write phpminer Good

wyattzheng commented 6 years ago

that's nice

wyattzheng commented 6 years ago

i fixed blake256 and work well in 64bit system.and CN is done! watch my codes at https://github.com/ZhyMc/phpminer

wyattzheng commented 6 years ago

finally!!

shift-reality commented 6 years ago

it's worked now? how much h/s?

wyattzheng commented 6 years ago

i just finished it.and the next step is to optimize it. (1/20 )h/s

shift-reality commented 6 years ago

CN hash is correct?

shift-reality commented 6 years ago

what is function trans($nb) actually doing? I have no idea what can broke b256 on 64 bit windows platform (i tested on PHP 7.2 for AMD x86_64) and blake hashes is fine calculated

wyattzheng commented 6 years ago

but in my computer it calculated wrong results.trans() make 64int overflow like 32int

shift-reality commented 6 years ago

ok, later i create test cases for blake with more data&hash pairs and we can check this behavior

Please, after it's ready, create inplace(remove function call) code for SubAndShiftAndMixAddRoundInPlace, xor_blocks .... etc This increase calc speed in 3-5 times, i tested

wyattzheng commented 6 years ago

wow 3-5times ,that makes me feel there are lots of spaces to optimze

wyattzheng commented 6 years ago

i'm working on stratum protocol,it is exciting to me

shift-reality commented 6 years ago

i suggest to not use stratum.. Use long poll instead. Because it's easiest way and not require extra threads for IO.

Miner arch should be like this: 1 master process-communicate with minepoll and receiver tasks N slave processes compute hashes +This allow to stop process if hash is already mined by somebody other +Not required thread model

IPC can be implemented used named pipe

wyattzheng commented 6 years ago

just like what you said,i learn the theory of pool .You can see that my phpminerBridge.js and phpminer.php

shift-reality commented 6 years ago

yes, i seen latest u'r activity