Jody7 / Lua-Bitcoin-Miner

35 stars 11 forks source link

Make it work again! #7

Open AndrexYT opened 1 year ago

AndrexYT commented 1 year ago

Hi, can you @Jody7 Make the code work again and tell instructions to add it to rolbox game? I saw you in DuinoCoin chat, and you was making the miner, i want to you helped me with my mining game, and at leaset fixed code, please, i need it for my game!

TBMbvioo3 commented 1 year ago

Yea it would be awesome!

aldotoci commented 7 months ago

If you guys are still interested I can post the working code on my github and explain the implementation, but I do not think it is worth it. After modifing the code a little bit to make the hash go faster without crashing the server. The best I could get is an avarage of 300Hash per second, which is basically not even a dollar per weak. I do not know why it is not going any faster. It propably has a limitation on the server side.

This is the modified code which basically does the brute force. ` local hcount = 0 local fcount = 0

while nonce<4294967296 do
    if tick() - pastTime > 10 then
        wait()
        print('hcount', hcount)
        hcount = 0
        pastTime = tick()   
    end

    local header = little_endian_bytestr(Version)
        ..tobinReverse(PreviousBlock)
        ..tobinReverse(MerkleRoot)
        ..little_endian_bytestr(Time,Bits,nonce)
    local hash=SHA(SHA(header)):reverse()
    if toDEC(hash)<MineTarget then
        print("FOUND HASH:", hash, "HEADER:", header)
        return hash
    else
        --print("Failed Hash: ", hash, "Nonce: ", nonce)
    end
    hcount = hcount + 1
    fcount = fcount + 1
    nonce= Random(1,4294967296)
end`

If you guys come up with some algorithm that would significantly improve the speed let me know. if tick() - pastTime > 10 then wait() print('hcount', hcount) hcount = 0 pastTime = tick() end I added this code because the loop would crash after approx 3000 iterations, since it was exceeding the iteration allowed. This is a measure by roblox to stop infinite loops.

AndrexYT commented 7 months ago

Hi thank you soooo much, finally someone helped me, ty! @aldotoci

aldotoci commented 7 months ago

No problem, do you have any idea on how to imporve the performance, also where can I dm you @AndrexYT ?

Legendary1401 commented 7 months ago

No problem, do you have any idea on how to imporve the performance, also where can I dm you @AndrexYT ?

How can I set this up ? Can you give any instructions ?

aldotoci commented 7 months ago

This is the structure structure of the implementation

Screenshot 2024-03-27 204347

Replace the GetLastBlock file code with the one above `local hs = game:GetService("HttpService") -- Update the URL to Blockchain.com's API for the latest block local url = "https://blockchain.info/latestblock"

return function() local data = hs:GetAsync(url, true) return hs:JSONDecode(data) end`

It should work now. To start hashing, type on the roblox chat: "start".

Legendary1401 commented 7 months ago

This is the structure structure of the implementation

Screenshot 2024-03-27 204347

Replace the GetLastBlock file code with the one above `local hs = game:GetService("HttpService") -- Update the URL to Blockchain.com's API for the latest block local url = "https://blockchain.info/latestblock"

return function() local data = hs:GetAsync(url, true) return hs:JSONDecode(data) end`

It should work now. To start hashing, type on the roblox chat: "start".

Wow thank you also where does the mined coin go ?

aldotoci commented 7 months ago

If the hash exists it will just print on the terminal, but you can change it and store it into a script file or sth like that, but again this is not fast at all and you will propably need an eternity to mine a coin.

AndrexYT commented 7 months ago

@aldotoci Hi, i tried your code, i am getting: 19:56:02.629 Merkle Root: 141f09e42fca6e4116d467baf91fbc0025d9de1cd426feff62793e7978300972 - Server - Main:29 19:56:02.763 ServerScriptService.Main:100: attempt to index nil with 'hash' - Server - Main:100 19:56:02.763 Stack Begin - Studio 19:56:02.763 Script 'ServerScriptService.Main', Line 100 - Studio - Main:100 19:56:02.763 Stack End - Studio