From 96253847e07fb0db206f0361ecc2bec55590788b Mon Sep 17 00:00:00 2001 From: "Rosalind M. Stflorant" Date: Thu, 8 Jul 2021 12:04:36 +0200 Subject: [PATCH] library update (8a8f4a6) on Thu Jul 8 11:50:36 AM CEST 2021 --- bin/signtx.pl | 69 +++++++++++++++--- config.yml | 30 ++++++++ curltest.sh | 25 +++++++ genesis.yml | 2 +- lib | 2 +- notes.md | 7 +- salts/Genesis.yml | 2 +- secrets/coinbase.yml | Bin 0 -> 210 bytes secrets/keys.yml | Bin 0 -> 1331 bytes t/blockaddr.t | 8 +- t/eckeys.t | 13 +++- t/genesis.t | 17 +++-- t/khash.t | 24 ++++++ t/mbase.t | 20 +++++ t/merkleroot.t | 15 ++++ ...5c5oKqb9Zof3xeC5Q2ZQjSaWv7FU4rAxe2s3sP.yml | 14 ++++ txpool/txcoin.yml | 11 +++ 17 files changed, 227 insertions(+), 32 deletions(-) create mode 100644 config.yml create mode 100644 secrets/coinbase.yml create mode 100644 secrets/keys.yml create mode 100644 t/khash.t create mode 100644 t/mbase.t create mode 100644 t/merkleroot.t create mode 100644 txpool/Ztxrms5c5oKqb9Zof3xeC5Q2ZQjSaWv7FU4rAxe2s3sP.yml create mode 100644 txpool/txcoin.yml diff --git a/bin/signtx.pl b/bin/signtx.pl index 7d7a5bc..8de0985 100755 --- a/bin/signtx.pl +++ b/bin/signtx.pl @@ -4,6 +4,8 @@ BEGIN { if (-e $ENV{SITE}.'/lib') { use lib $ENV{SITE}.'/lib'; } } use config; +use essential qw(sdate version); +use misc qw(khash yamlify); use TXPOOL qw(saveTxPool); use CAStore qw(CASWrite); use ECKeys qw(ecsign ecverif getPeerid loadKeys); @@ -14,9 +16,19 @@ foreach my $id (keys %{$keys}) { my $pub = $keys->{$id}{public}; $keys->{$pub}{id} = $id; } -#printf "--- keys %s...\n",Dump($keys); +my $keyfile = $ENV{SITE}.'/secrets/coinbase.yml'; +if (-e $keyfile) { + my $local_keys = &loadKeys($keyfile); + if (exists $keys->{coinbase}) { + $keys->{coinbase}{private} = $local_keys->{coinbase}{private}; + } else { + $keys->{coinbase} = $local_keys->{coinbase}; + } +} +printf "--- keys %s...\n",Dump($keys); my $txf = shift; +my $date = (exists $tx->{timestamp})? &sdate($tx->{timestamp}) : &sdate(time); my $tx = LoadFile($txf); @@ -25,48 +37,81 @@ my %signatures = (); my %delta = (); foreach my $sign (@{$tx->{signatures}}) { my ($pub) = keys %{$sign}; - $signatures{$pub} = $sign->{$pub}; + $signatures{$pub} = $sign->{$pub}[0]; $delta{$pub} = 0; } printf "--- signatures %s...\n",Dump(\%signatures); foreach my $in (@{$tx->{inputs}}) { my ($pub) = keys %{$in}; + my $id = (exists $keys->{$pub}{id}) ? $keys->{$pub}{id} : $pub; + $pub = $keys->{$id}{public} if (exists $keys->{$id}{public}); my $value = $in->{$pub}; $valuein += $value; $delta{$pub} -= $value; - printf "in: %s from %s (%s)\n",$value,$pub,$keys->{$pub}{id}; + printf "in: %s from %s (%s)\n",$pub,$id; } foreach my $out (@{$tx->{outputs}}) { my ($pub) = keys %{$out}; + my $id = (exists $keys->{$pub}{id}) ? $keys->{$pub}{id} : $pub; + $pub = $keys->{$id}{public} if (exists $keys->{$id}{public}); my $value = $out->{$pub}; $valueout += $value; $delta{$pub} += $value; - printf "out: %s to %s (%s)\n",$value,$pub,$keys->{$pub}{id}; + printf "out: %s to %s (%s)\n",$value,$pub,$id; } if ($valuein != $valueout) { printf "error: i:%s != o:%s\n",$valuein,$valueout; } +my $txi = { + timestamp => $tx->{timestamp}, + inputs => $tx->{inputs} +}; +my $txo = { + timestamp => $tx->{timestamp}, + message => $tx->{message}, + outputs => $tx->{outputs} +}; +my $txio = { + timestamp => $tx->{timestamp}, + message => $tx->{message}, + inputs => $tx->{inputs}, + outputs => $tx->{outputs} + +}; + my $txihash = khash('SHA256',yamlify($txi)); + my $txohash = khash('SHA256',yamlify($txo)); + my $txhash = khash('SHA256',yamlify($txio)); foreach my $pub (keys %delta) { my $value = -$delta{$pub}; if (exists $signatures{$pub}) { my $id = (exists $keys->{$pub}{id}) ? $keys->{$pub}{id} : $pub; my $key58 = (exists $keys->{$id}{public}) ? $keys->{$id}{public} : $pub; - my $msg = qq'["$pub","$value","$tx->{payload}"]'; + my $msg; + if ($value > 0) { # input + $msg = qq'["$pub","$value","$tx->{message}"]'; + } else { # output + $msg = qq'["$id","$value","$tx->{txohash}"]'; + } printf "msg: %s\n",$msg; if (defined $signatures{$pub}) { - my $sig = $signatures{$pub}; + my $sig = $signatures{$pub}[0]; my $sigok = &ecverif($key58,$sig,$msg); printf "signature for %s (%s) ? %s\n",$id,$key58,($sigok)?'ok':'invalid'; if (! $sigok) { - my $sig = &ecsign($id,$msg); + my $sig = &ecsign($id,$msg); printf "sig: %s: %s (corrected)\n",$id,$sig; - $signatures{$pub} = $sig; + $signatures{$pub} = [ $sig, $date ]; } } else { - my $sig = &ecsign($id,$msg); - printf "sig: %s: %s\n",$id,$sig; - $signatures{$pub} = $sig; + my $id = (exists $keys->{$pub}{id}) ? $keys->{$pub}{id} : $pub; + if (exists $keys->{$id}{private}) { + my $sig = &ecsign($id,$msg); + printf "sig: %s: %s\n",$id,$sig; + $signatures{$pub} = [ $sig, $date ]; + } else { + printf "sig: don't have private key for %s\n",$id; + } } } } @@ -80,7 +125,7 @@ printf "--- %s.sig: %s...\n",$txf,Dump($tx); DumpFile("$txf.sig",$tx); $tx->{nonce} = 3976914969180171529, -my $txaddr = CASWrite('txpool',$tx,$tx->{nonce},'txpool',5); +my $txaddr = CASWrite($ENV{SITE}.'/txpool',$tx,$tx->{nonce},'txpool',$config->{difficulty}); push @{$TXPOOL},$txaddr; &saveTxPool($TXPOOL); diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..140f18c --- /dev/null +++ b/config.yml @@ -0,0 +1,30 @@ +--- # toychain's config +version: 1.06 +chain: toychain +apiver: '0.0' +ipfsgw: 8390 +port: 8089 + +# p2p network = api+1 +apis: + - 127.0.0.1:8091 + - 127.0.0.2:8093 + - 127.0.0.3:8095 + - 127.0.0.4:8097 + - 127.0.0.5:8099 + +# block parameters : +bkver: 0 +bkreward: 100 +genhash: Z9BEepHz9jLWzNebDEZTrEKusuU9zomFoaaPxngCQ5D39 +nullhash: Z9BEeWD4Mww7yrXyPRXrfM2y6FxsQGfaNPzC8DxWq4ATq +txgen: Ztxrms5c5oKqb9Zof3xeC5Q2ZQjSaWv7FU4rAxe2s3sP +txcoin: ZCBuCkQFRBeiGnANEwb65TZptSTUpm62WYS4Xj9gkMLU +txcoin: ZCBtx9SS9n57R2cx3AAuRDKJ4b9WsWA5MoTVEtxGQAdV + + +# Proof of Work option +difficulty: 5 +maxdiff: 7 +# CAstore options +trackmode: 1 diff --git a/curltest.sh b/curltest.sh index 5c5e51b..592dc68 100644 --- a/curltest.sh +++ b/curltest.sh @@ -4,6 +4,8 @@ #curl http://127.0.0.1:8089/api/0.0/audit curl http://127.0.0.1:8089/api/0.0/getheight echo '' +curl http://127.0.0.1:8089/api/0.0/getheads +echo '' curl http://127.0.0.1:8089/api/0.0/getchain echo '' curl -s http://127.0.0.1:8089/api/0.0/getblock?n=30 @@ -12,4 +14,27 @@ curl -s http://127.0.0.1:8089/api/0.0/gettx?txaddr=ZTxB1ritiikyhjTXg28V7AjfqwkDy echo '' curl -s http://127.0.0.1:8089/api/0.0/gettx?txaddr=ZtxqdiZ8wwpEN5dScJf1byU6hjfBLoSrFmCrUVNJmqPc echo '' +curl -s http://127.0.0.1:8089/api/0.0/gettx?txaddr=Ztxrms5c5oKqb9Zof3xeC5Q2ZQjSaWv7FU4rAxe2s3sP +echo '' cat txpool/tx.yml | sed -e "s/$/%0a/g" | curl -s -X POST http://127.0.0.1:8089/api/0.0/settx -d @- + +curl -s http://127.0.0.1:8089/api/0.0/gettx?txaddr=ZtxiE2X3R7DbmrZXQrfkrRjcgvYjjJhLVBZjTJMY1zVi +echo '' +curl -s "http://127.0.0.1:8089/api/0.0/getcas?dir=txpool&addr=Ztxr9MNA86n7sW127Q3UWh8RbgiJC2KisuYySzQ8Ymht" +echo '' +curl -s http://127.0.0.1:8089/api/0.0/getpool +echo '' +curl -s http://127.0.0.1:8089/api/0.0/minepool +echo '' +curl -s "http://127.0.0.1:8089/api/0.0/getcas?addr=ZNULLSNLDcn169AJMjXuVLrQBPDFZoF3nzz4HiqvaFsA&dir=CAStore" +echo '' +curl -s "http://127.0.0.1:8089/api/0.0/getcas?dir=CAStore&addr=ZGenknVsHjkBSf2jd3Wh8rc4hG7iPCK2kTa6yg3QRBym" +echo '' +curl -s http://127.0.0.1:8089/api/0.0/getblock?addr=ZGenehF7J4vFSyMHVQaiB9uRwbb2MYXVgM3Kbu2LoBDt +echo '' +curl -s http://127.0.0.1:8089/api/0.0/getblock?hash=Z9BEepHz9jLWzNebDEZTrEKusuU9zomFoaaPxngCQ5D39 +echo '' +curl -s http://127.0.0.1:8089/api/0.0/getblock?hash=Z9Pa9kcag3TBc6EX671u6Zwk7N6M7jTuQ5HPtjzDrpx4f +curl -s http://127.0.0.1:8089/api/0.0/getblock?addr=ZBK1DZmxXtbjgFjn1BuPscUoEFeRXf9MK3ikj6HobzkJ +echo '' +curl -s http://127.0.0.1:8089/api/0.0/getpool diff --git a/genesis.yml b/genesis.yml index 754a9de..781ba46 100644 --- a/genesis.yml +++ b/genesis.yml @@ -9,7 +9,7 @@ meta: salt: ~ # used in address computation txroot: ~ audit: - peerid: QmcfHufAK9ErQ9ZKJF7YX68KntYYBJngkGDoVKcZEJyRve + peerid: Z21GdiEggiGa7TPNaqGY8coBy97LoRNpPVu9fxig75nstq tics: 1623830817245864895 ip: 83.78.4.228 prev: ZdtrjkYsAYUeBCs4DRjtVYwPevpxvHjGT2PRauANr3Vao diff --git a/lib b/lib index 108a4b5..8a8f4a6 160000 --- a/lib +++ b/lib @@ -1 +1 @@ -Subproject commit 108a4b5442111374e51ecdc66992520aad233724 +Subproject commit 8a8f4a627abf429965d7d9db4ff519e83f57945c diff --git a/notes.md b/notes.md index ad0b987..dba10c4 100644 --- a/notes.md +++ b/notes.md @@ -16,11 +16,11 @@ minimally sized blocks : - segreated signature, timestamp, audit etc. - block: {address, previous, pow} + - use balances for state rather than TXO to avoid the need keep txo states, and link txi to utxo ## observation ... - - revokable block if sign w/ a DH on txo and ECDSA on txi - txroot (merkle root can be global) @@ -46,4 +46,7 @@ long unpredictable queue time (mempools) can deter speculator as it would be like "lotery" lotery is a "gamified" tax extractor. - +- PoW can be replaced by ZK proof of some Work +- should it be txo which carries the burden of proof of work ? +- validator already do a great job making the system "alive" that's already work ! +- How to mitigate DDoS on Mempool ? diff --git a/salts/Genesis.yml b/salts/Genesis.yml index f47e5e0..7a88f88 100644 --- a/salts/Genesis.yml +++ b/salts/Genesis.yml @@ -1 +1 @@ -salt: 8163726776410142252 +salt: 8163726776976957032 diff --git a/secrets/coinbase.yml b/secrets/coinbase.yml new file mode 100644 index 0000000000000000000000000000000000000000..47ab19737195d5e8d69074c4f095765f8b1f1d87 GIT binary patch literal 210 zcmV;@04@IjM@dveQdv+`02S2EvpIPA;3s5l3RmM6_rfi?evjk!rP8-EP~uEqP!pde zlFoEhr?s@^yx+zEEdZc*saw`#we0~M(s(?=a#B+#j`A5Ih>goa5AkAn%k3^D3@7>^ zs194v^1>L1gBPTYYTTZwJ9qLiy>cTtD2xcvS12T*D4eOBITxzQ6CmwFAQ`ibpqe_i zelLgZ2ja&xqu?4^5BgOcbx%E>6ShrWb45#IqzBX2d`u!3 M2p}KIWux7En0g^#g8%>k literal 0 HcmV?d00001 diff --git a/secrets/keys.yml b/secrets/keys.yml new file mode 100644 index 0000000000000000000000000000000000000000..3437c4286efed7029b49907e00ab46bca277d662 GIT binary patch literal 1331 zcmV-31)IQBb`TSD z*vz%Lph;N|xs;GG@|PPW^OjzLKxOvRo6QA_%XcrqV{zr~24+Lb@j$^8l`+YyCPQ_M zWKU`tF16eE9pRYV*NhM{14(=yebW=L9TYh&$_o4Wq44T_OR5&`ad%2AzIfxZrT^WA zPcd2_b7&hVfr;G7a3`zw=#&%G7X3HXF9a)D&5HB+n6AOS5Bg7{e^HqQxhv=Vx61_cm`P3Hr4_ zJ<6aDnM>U|uLv3>4e+4A63)v?gLj^GfI5+=NIr!S6R@P9YN-;8lLS$oaj2pn!J8Oq-&=0OBvM2s_e7RHt*z( z1v?$r%cR=6*SajKP91XM=+w_0KbYCz9>Nij5>9vlp>a{bW_IcC7<6T8e8@=H0$ya^ zt1%VX3;=oxu>*CspLy%37>@@F`v#*5fH=~VB}pslD;BNpx5aW`I%)~!$mC$Ne5}ov zKV@gbTg!#eh^2Rjzs!$YX?TtKN^I5013A)_StTo940-OX_!X9iJs)P6acaqSHn7!X z(a%{Jy9$)dAU(PhP;4V*Z9TM*N;@B64D7s1BOVsG&=O>vLI0DsAT~7Ld$xHyi@CkRO zqiBx+@6=(lp}H9a@ca24KXbI4);??X&9aZku_nbKPtQxi*gf^EW zc-_~oU~R8pvTo`9j?tliI&kt;<%sSEfpYOHHy@66aH$)74YRXTLqG3n<+Bthn6vqj zb6m;LHoNY#+3b)`Bgyi{1ZT0H2fy!C$47n3E+~4vE-74j@F5w;v_+xHjIFpgxhYqs z-1E7h#jyrN9i>WH0=(s{$PtOCdBGNHoC)h=-72hWgJoDi8>%(!FTnQS`6HiYjS#t9f#ncGLmJ~5?Oa{3*Zda%E13m zMq3WPwR5eGg1#>H>Kx9Fkrspmq-Z!S$28sVcfAfW`}_YXX0$6tH*H@I>Qy9|efQ)) z2d*K;i=PHY;5+blGMVNT+9c&t(9SRn01hkVZ&1tsA7)aD+yBQLIUsR_&A7Q(uZl}N zPgv5_Hu1w_f4DLD6Ys=EH8k4$$n^fQy9A9h4+#p;zKLQQ&$}l)!T%6;06n0W1PbpQ pgB#F`J;wS`?UI@0>!@Bv)L{bkaddr}; +printf "chain.hash %s\n",$toychain::chain->[-1]; +printf "head.addr %s\n",$toychain::HEADs[0]->{bkaddr}; + # f96885aa : 21.4min # 044ce1de : 20.5min @@ -28,8 +30,8 @@ printf "n0:%s\n",$n0; displayBlock($toychain::genesis); -my $addr = &blockHash($toychain::genesis); -printf "genesis.addr: %s\n",$addr; +my $hash = &blockHash($toychain::genesis); +printf "genesis.hash %s\n",$hash; print ".\n"; exit $?; diff --git a/t/eckeys.t b/t/eckeys.t index 5eef2cc..6888acf 100644 --- a/t/eckeys.t +++ b/t/eckeys.t @@ -1,17 +1,20 @@ BEGIN { if (-e $ENV{SITE}.'/lib') { use lib $ENV{SITE}.'/lib'; } } +use essential qw(keyw); use encode qw(mbase58); -use ECKeys qw($keys ecsign ecverif eckeygen saveKeys); +use ECKeys qw($keys ecsign ecverif eckeygen saveKeys loadKeys); use YAML::Syck qw(Dump); +my $other = &loadKeys('secrets/coinbase.yml'); +$keys->{coinbase} = $other->{coinbase}; + my $anon = eckeygen('anonymous' => 'This is an anonymous ECDSA key'); my $id = eckeygen('identity' => 'Doctor I·T (demo)'); my $miner = eckeygen('miner' => 'Toycoin Mining Rig Corp.'); -my $miner = eckeygen('coinbase' => 'ToyChain Blockchain Bot'); -&saveKeys(); - +my $distrib = eckeygen('distribution' => 'ToyChain Distribution Account'); printf "keys: %s\n",Dump($keys); +&saveKeys('keyfile.yml',$keys); my $sig = &ecsign('coinbase',qq'["coinbase","50","This is a coinbase transaction of 50 coins"]'); printf "- 50 coinbase: %s\n",$sig; @@ -20,7 +23,9 @@ printf "- default coinbase: %s\n",$sig; $sig = &ecsign('identity',"this message is signed by $keys->{identity}{name}"); printf "sig: %s\n",$sig; +print "validating \n"; my $valid = &ecverif($keys->{identity}{public},$sig,"this message is signed by $keys->{identity}{name}"); +printf "valid: %s\n",$valid; exit $?; diff --git a/t/genesis.t b/t/genesis.t index 627fa3a..e142644 100644 --- a/t/genesis.t +++ b/t/genesis.t @@ -2,20 +2,21 @@ BEGIN { if (-e $ENV{SITE}.'/lib') { use lib $ENV{SITE}.'/lib'; } } -use toychain; +use Genesis; +use functions qw(displayBlock); use DAG qw(DAGRead); -my $headblock = $toychain::HEADs[0]; -my $headhash = $headblock->{bkhash}; -my $headaddr = $headblock->{bkaddr}; -printf "headhash%s\n",$headhash; -printf "headaddr%s\n",$headaddr; +my $genblock = $Genesis::genblock; +my $genhash = $Genesis::genhash; +my $genaddr = $gendblock->{bkaddr}; +printf "genhash%s\n",$genhash; +printf "genaddr%s\n",$genaddr; -my $blk = &DAGRead($headhash,'blocks'); +my $genbk = &DAGRead('blocks',$genhash); #printf "--- blk %s...\n",Dump($blk); -&displayBlock($blk); +&displayBlock($genbk); exit $?; diff --git a/t/khash.t b/t/khash.t new file mode 100644 index 0000000..16b8475 --- /dev/null +++ b/t/khash.t @@ -0,0 +1,24 @@ +#!/usr/bin/perl + +BEGIN { if (-e $ENV{SITE}.'/lib') { use lib $ENV{SITE}.'/lib'; } } +use misc qw(khash); +use encode qw(mbase58 mbase36 mbase16); + +my $hash; + +$hash = &khash('MD5',undef); +printf "md5: %s\n",mbase16($hash); +$hash = &khash('SHA1',undef); +printf "sha1: %s\n",mbase16($hash); +$hash = &khash('SHA256',undef); +printf "sha2: %s\n",mbase16($hash); + +$hash = &khash('SHA256','Hello World!'); +printf "kh58: %s\n",mbase58($hash); + +$hash = &khash('SHA3_224','Hello World!'); +printf "kh36: %s\n",mbase36($hash); + +exit $?; +1; + diff --git a/t/mbase.t b/t/mbase.t new file mode 100644 index 0000000..4581076 --- /dev/null +++ b/t/mbase.t @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +BEGIN { if (-e $ENV{SITE}.'/lib') { use lib $ENV{SITE}.'/lib'; } } + +use seed qw(rand64); +use encode qw(mbase58 mbase36 mbase16); + +my $seed = &seed::setseed('testing mbase* subroutines'); +my $r = rand64(); +my $q = pack'Q',$r; +printf "seed: %s\n",$seed; +printf "r: %s\n",$r; +printf "q: 0x%s\n",unpack'H*',$q; +printf "r58: %s\n",&mbase58($q); +printf "r36: %s\n",&mbase36($q); +printf "r16: %s\n",&mbase16($q); + +exit $?; + +1; diff --git a/t/merkleroot.t b/t/merkleroot.t new file mode 100644 index 0000000..152efec --- /dev/null +++ b/t/merkleroot.t @@ -0,0 +1,15 @@ +#!/usr/bin/perl + +BEGIN { if (-e $ENV{SITE}.'/lib') { use lib $ENV{SITE}.'/lib'; } } + +use TXPOOL qw(computeMerkleRoot mbase16); + +my $a = [qw(a b c d e f g)]; + +my $mr = &computeMerkleRoot($a); + +printf "mr: %s\n",mbase16($mr); + +exit $?; + +1; diff --git a/txpool/Ztxrms5c5oKqb9Zof3xeC5Q2ZQjSaWv7FU4rAxe2s3sP.yml b/txpool/Ztxrms5c5oKqb9Zof3xeC5Q2ZQjSaWv7FU4rAxe2s3sP.yml new file mode 100644 index 0000000..2fe2d4f --- /dev/null +++ b/txpool/Ztxrms5c5oKqb9Zof3xeC5Q2ZQjSaWv7FU4rAxe2s3sP.yml @@ -0,0 +1,14 @@ +--- +inputs: + - + coinbase: 50 +nonce: '3976914969180171529' +outputs: + - + Z21GdiEggiGa7TPNaqGY8coBy97LoRNpPVu9fxig75nstq: 50 +payload: This is a coinbase transaction of 50 coins for the genesis block +pow: '3976914969180650994' +signatures: + - + coinbase: Zan1RjVTw7GPVyd7aygjWSrGCtX3M8CVRu3NAyqLC8MToNPE93ju4RrFFjunnbeTYnudR2gSKCamK82xjEfWEtGzGvTRDw25MG +timestamp: '1623683269225552702' diff --git a/txpool/txcoin.yml b/txpool/txcoin.yml new file mode 100644 index 0000000..0042a1a --- /dev/null +++ b/txpool/txcoin.yml @@ -0,0 +1,11 @@ +--- +timestamp: '1625385951347499858' +inputs: + - coinbase: 100 +nonce: '3976914969180171529' +outputs: + - Z21GdiEggiGa7TPNaqGY8coBy97LoRNpPVu9fxig75nstq: 100 +message: This is a coinbase transaction of 100 coins to be distributed to Z21GdiEggiGa7TPNaqGY8coBy97LoRNpPVu9fxig75nstq +pow: '3976914969180292365' +signatures: + - coinbase: ~