Browse Source

library update (8a8f4a6) on Thu Jul 8 11:50:36 AM CEST 2021

master
Rosalind M. Stflorant 4 years ago
committed by Brooke L. Rediker
parent
commit
96253847e0
  1. 69
      bin/signtx.pl
  2. 30
      config.yml
  3. 25
      curltest.sh
  4. 2
      genesis.yml
  5. 2
      lib
  6. 7
      notes.md
  7. 2
      salts/Genesis.yml
  8. BIN
      secrets/coinbase.yml
  9. BIN
      secrets/keys.yml
  10. 8
      t/blockaddr.t
  11. 13
      t/eckeys.t
  12. 17
      t/genesis.t
  13. 24
      t/khash.t
  14. 20
      t/mbase.t
  15. 15
      t/merkleroot.t
  16. 14
      txpool/Ztxrms5c5oKqb9Zof3xeC5Q2ZQjSaWv7FU4rAxe2s3sP.yml
  17. 11
      txpool/txcoin.yml

69
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);

30
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

25
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

2
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

2
lib

@ -1 +1 @@
Subproject commit 108a4b5442111374e51ecdc66992520aad233724
Subproject commit 8a8f4a627abf429965d7d9db4ff519e83f57945c

7
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 ?

2
salts/Genesis.yml

@ -1 +1 @@
salt: 8163726776410142252
salt: 8163726776976957032

BIN
secrets/coinbase.yml

BIN
secrets/keys.yml

8
t/blockaddr.t

@ -16,7 +16,9 @@ use seed qw(rand64);
use toychain qw(blockHash displayBlock);
use YAML::Syck qw(Dump);
print "// testing blockaddr\n";
printf "chain.addr: %s\n",$toychain::chain->{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 $?;

13
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 $?;

17
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 $?;

24
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;

20
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;

15
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;

14
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'

11
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: ~
Loading…
Cancel
Save