Bitcoin Forum
March 19, 2024, 03:05:19 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Announcing a new True p2p PHP Blockchain (No Apache/no Mysql) - To be mined soon  (Read 118 times)
kladskull (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
March 02, 2022, 03:49:50 PM
 #1

Months ago, I wanted to learn blockchain tech. I decided to fork Bitcoin. Like most I was overwhelmed and ended up getting discouraged. I found a few "light" projects in Python, and some in other languages (including one in PHP called Aronium). I didn't like many of the projects - they didn't seem to be "bitcoin like". I.e: no scripting, the transactions and blockchain didn't seem to be the same (or similar) to bitcoin.

So I decided to just learn as much as I could about blockchains, bitcoin and how they work. The result of all of this is the project Xeros. I should say, I am nearly done the projects alpha release. I just have to complete/test the p2p code, and fix a few bugs I am expecting.

Why release it before I am done? Well.. I figured I could find some contributers and clean the project up, maybe get a proper web presense in place, fix underlying issues that may exist, and do this properly as I think its probably the first PHP Blockchain source code that is super close to Bitcoin. I wanted to call it something related to PHP, but thought that the process would just naturally happen as contributers came on the project.

I'd like to say, I've tried to keep the code consistant, but I've refactored the code probably 3 times as I learned how things actually worked. Please be gentle with the code style, and formatting, perhaps you'd like to contribute and help make this better?

Like bitcoin it has the following attributes:

  • Actual P2P Networking (no HTML/PHP/Apache)
  • Scripting - you can use XerosASM to create scripts that can lock and unlock transactions. One note about this is - I didn't like the bitcoin scripting - as a lot of it was disabled after release - the syntax was kind of ugly too - not to say mine isn't! To get the scripting done in a managable fasion, I used an Assembler-like language. It is slightly comfusing if you don't know assembler, and likely confusing if you do know it as its a more dumbed-down version.
  • There are a ton of commands in the language as well. I plan to create a PHP or Python type scripting language, that I can "compile" <convert> to my language in the future, or just replace it (in a backwards compatable way of course)
  • There are a ton of commands in the language as well. I plan to create a PHP or Python type scripting language, that I can "compile" <convert> to my language in the future, or just replace it (in a backwards compatable way of course)
  • The scripting VM (Or state machine, what I really like to call it) has some registers, a stack, a program counter, and state. The way I wrote it, I can meter how long it runs if I add in looping, by time, or program count.

Here is a sample locking script:

Pay-to-Public Key hash (more anonymous)
Code:
mov <sha256>,ax;    // move the hashed public key into a register
adha ax;            // convert the hash to an address
pop bx;             // pop the first public key
adpk bx;            // convert the public key to an address
vadr ax,bx;         // compare the address to the scriptAddress
pop ax;             // move the second public key into a register
pop bx;             // move the signature into a register
vsig ax,<hash>,bx;  // verify that pubkey<ax> signed <bx> to produce <cx>

Here is the unlocking script
Code:
push [signature];   // push the sig to the stack
push [publicKey];   // push the public key into the stack
dup;                // duplicate the public key to the stack

  • If you know about bitcoin scripting, you'll know the scripts are combined and run (UNLOCKING + LOCKING).
  • The p2p networking is different as well - I am actually working on this now, its the last part before I can watch a couple peers communicate.
  • The block and transactions transferred stored in a very similar way to bitcoin - but using raw JSON.
  • Data is all stored using Sqlite3 - I didn't want to beg people to install Mysql/Postgres
  • No Web server, like all the other PHP blockchains (no apache etc). I wanted a install the requirements and run the coin with little server config as possible - just like bitcoin.
  • The consensus is pretty basic, could use work, also uses double sha256 like Bitcoin, was considering using Bcrypt.

The blocks look like this (and another thing about this - is the scripts are compressed to keep them small) -- please also note, the hash won't match up as I changed a couple things here so it fit.
Code:
{
   "server":"Xero",
   "version":"0.0001",
   "height":2119,
   "response":true,
   "data":{
      "network_id":"xa01",
      "block_id":"F5evzyi6q7uvBVcWYVtsZyConWr6SQBy2oip5wzqspPa",
      "previous_block_id":"7W5WKLvXre24BUgZbU4LRrii7rHUHNgX21MXvqko2YAP",
      "date_created":"1643047029",
      "height":"2119",
      "nonce":"155632845",
      "difficulty":"26",
      "merkle_root":"8ce65a579f356c1e50a97c6360bc79b0571e892b6ae44d36a34cddeb0d39cdb4",
      "transaction_count":"1",
      "previous_hash":"0000000dcc714a00a1bb2550ea2cedc4d5bf7e9ae9eb7d8c2723d6c7128055e2",
      "hash":"000000035ed5608a98d33899bf05a2cb4cb9785612e6392ff5e1084560919d3a",
      "next_id":"0",
      "transactions":[
         {
            "block_id":"F5evzyi6q7uvBVcWYVtsZyConWr6SQBy2oip5wzqspPa",
            "transaction_id":"53PH3EX5SCipZgfxASP9bjamDEFn57onYGaEokV4u5sa",
            "date_created":"1643047029",
            "signature":"67fcd14d76b2e1b3cb7d9dac0b9b48c1864fbc3f191a43ec4ae26bd75ee7672e5cfea98e699812124ee0626975da56dde8f1495ba5408cc02a18fa1ab6ab2143dccfee2ffe044d1f9986702849070d5d1fa0581230a8638bd42d28f42e6b1856b011a161b79c911886b3f6f7d699513c753abd4ae574353e284508e0e889a2ab3f8c12b720c185d53a1a9239869daf4bab2e96979d8e5288a87880559bb46a9f6b3a02dd4e8f34b7d58d48d36db28723c11b10173fd5eb107244d85eb45269c639e0491818e7b752d45a30098274368973499618ec4d2f327ca7d38c6866ada768bc86e3ec5ba172d9accc68b8ce127a9da3221acea7a946f66b671411a58ebf",
            "public_key":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0D5foSXWfe4pz6wRcgJ6unDvL4HDbD6u8j8\/VXGq2Zh1V97eYfgGV1NqDzIq54dkSt7hL4j6L7SEzWfkad+GU2TSniboXB9\/GW+xJEDriNgyC76VLKeFZ2btonV3ZFmZs0xA4pbZbyrlee+8WJpllDsb7AEav0LeO5tMIfIX1PgiotkLjgTdF4wcfobsU8RhTx6mS5+\/T3dJ7TL1EEtojwnTV+Cf1fHa\/kYRBEx8bs6LoEXZ9YSBDPA9jydXlJ+1kqliqG9zG8Ho0QjOKx6wn35dWkhZWg8MbREWJuEZZ5mYk6RJurmnDXVoiqN\/dPfcf2ilhxyXxIbURdK1AQf5jQIDAQAB",
            "peer":"3.97.76.137",
            "height":"0",
            "txIn":[

            ],
            "txOut":[
               {
                  "tx_id":"0",
                  "address":"Xa1KKZ9mqQchK7sfJ5iHj4KvpryZZTxV92Qm",
                  "value":"5000000000",
                  "script":"ExQbFWbYp8edDDnJEeDPbmwDz3wmxiAtqhZt7EvQ2jbJHcDvmYLg1LqFgE4Q27wB87bn4apZtWMhCLrF5UknjJPeoncsZPwREohnLnqjnkC5n9sFgmrwwbZze8C4yzc7Vd1FYA",
                  "lock_height":"3559",
                  "version":"0"
               }
            ]
         }
      ],
      "confirmations":0
   },
   "time":1643049048,
   "hash":"9f18e9ef41b262ec660bad10c0d4a2a093749e622889ec070e861448e92c38a9"
}

A bit about the above:

  • the network ID is so that we know its our coin - someone may fork our code and make their own coin, we want to make sure we only accept "bc01" blocks
  • date created is in epoch time (seconds since 1970)
  • block_id is the block identifier, nothing more
  • nonce is what the miner found (the secret!) to forge the new block
  • difficulty is between 1 and 256 (256 bits) = currently its only 25
  • hash and previous hash, I think you guys know - but its the hash of the transaction, and previous transaction hash
  • inside the transactions, you can see a public key and signature of the sender
  • tx in are transactions that are being "received"
  • tx out are transactions that are being "given"
  • The value is the amount x 100000000 - so 50 coin = 5000000000 - we don't deal in decimals in the back end, the users will see proper coin though "50.00"

The script is where the magic is... it's an encoded/compiled script that runs when someone wants to spend the coin. It looks like the scripting examples above.
Code:
ExQbFWbYp8edDDnJEeDPbmwDz3wmxiAtqhZt7EvQ2jbJHcDvmYLg1LqFgE4Q27wB87bn4apZtWMhCLrF5UknjJPeoncsZPwREohnLnqjnkC5n9sFgmrwwbZze8C4yzc7Vd1FYA

As for the rewards, I didn't want to create 21,000,000 coins, instead, I give out the same amount each year (and remove 4% per year to simulate inflation). I may be able to whip code together, but one thing I DO NOT know is economics... so this is either SUPER amazing, or complete crap.

Anyhow, I hope this helps someone with a project they want to do in the future, or even get someones curiosity about blockchains answered - or perhaps I have learned I've complety fucked it all up?!

If you would like to check the source code out, please check out my github repo: https://github.com/kladskull/xeros - perhaps you'd like to do some contribution as well?

If you have any questions, etc - just throw them below, I also have a /r/PHP thread which is getting a lot of down votes for some reason lol - I do realize PHP is not the best thing to code a block chain in, but there are a couple out there, and I think I've come super close to the bitcoin blockchain as best as I can, any how check the thread here: https://www.reddit.com/r/PHP/comments/t4ozp0/ive_made_a_100_php_p2p_blockchain_like_btc_in_php/
Transactions must be included in a block to be properly completed. When you send a transaction, it is broadcast to miners. Miners can then optionally include it in their next blocks. Miners will be more inclined to include your transaction if it has a higher transaction fee.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1710817519
Hero Member
*
Offline Offline

Posts: 1710817519

View Profile Personal Message (Offline)

Ignore
1710817519
Reply with quote  #2

1710817519
Report to moderator
bebfour
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
March 02, 2022, 06:13:36 PM
 #2

Sounds interesting. Did you have a discord set up or anywhere to discuss it?
kladskull (OP)
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
March 02, 2022, 08:45:14 PM
 #3

We do!! You can find it here:  https://discord.gg/mvacfndPXt
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!