Skip to content

Commit

Permalink
Merge pull request ElementsProject#13 from sg777/local
Browse files Browse the repository at this point in the history
resolved LN errors
  • Loading branch information
jl777 authored May 23, 2018
2 parents 31629ee + 240f490 commit 6d88452
Show file tree
Hide file tree
Showing 18 changed files with 1,076 additions and 57 deletions.
2 changes: 1 addition & 1 deletion bitcoin/chainparams.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const struct chainparams networks[] = {
.genesis_blockhash = {{{.u.u8 = {0x00, 0x00, 0x00, 0x6e, 0x75, 0xf6, 0xaa, 0x0e, 0xfd, 0xbf, 0x7d, 0xb0, 0x31, 0x32, 0xaa, 0x4e, 0x4d, 0x0c, 0x84, 0x95, 0x15, 0x37, 0xa6, 0xf5, 0xa7, 0xc3, 0x9a, 0x0a, 0x9d, 0x30, 0xe1, 0xe7}}}},
.rpc_port = 57776,
.cli = "chips-cli",
.cli_args = "",
.cli_args = NULL,
.dust_limit = 10000,
.when_lightning_became_cool = 1,
.testnet = false},
Expand Down
1 change: 0 additions & 1 deletion ccan/ccan/tal/link/LICENSE

This file was deleted.

1 change: 1 addition & 0 deletions ccan/ccan/tal/link/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../../licenses/BSD-MIT
Binary file added lightning.IAB
Binary file not shown.
Binary file added lightning.IAD
Binary file not shown.
Binary file added lightning.IMB
Binary file not shown.
Binary file added lightning.IMD
Binary file not shown.
Binary file added lightning.PFI
Binary file not shown.
Binary file added lightning.PO
Binary file not shown.
Binary file added lightning.PR
Binary file not shown.
Binary file added lightning.PRI
Binary file not shown.
Binary file added lightning.PS
Binary file not shown.
Binary file added lightning.WK3
Binary file not shown.
9 changes: 7 additions & 2 deletions lightningd/bitcoind.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,14 @@ static bool extract_feerate(struct bitcoin_cli *bcli,

feeratetok = json_get_member(output, tokens, "feerate");
if (!feeratetok)
return false;
{
//return false;
// do nothing till some fix
}

return json_tok_double(output, feeratetok, feerate);
//return json_tok_double(output, feeratetok, feerate);
feerate=0.0002;
return true;
}

struct estimatefee {
Expand Down
Binary file modified privatebet/bet
Binary file not shown.
111 changes: 80 additions & 31 deletions privatebet/bet.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,10 @@ int main(int argc,const char *argv[])

range = (range % 52) + 1;
numplayers = (numplayers % (CARDS777_MAXPLAYERS-1)) + 2;
range=2;
range=4;
numplayers=2;
Maxplayers=2;
printf("%s:%d, range:%d, numplayers:%d\n",__FUNCTION__,__LINE__,range,numplayers);

// for dcv
if((argc==2)&&(strcmp(argv[1],"dcv")==0))
{
Expand All @@ -472,14 +472,14 @@ int main(int argc,const char *argv[])
BET_dcv->maxplayers = (Maxplayers < CARDS777_MAXPLAYERS) ? Maxplayers : CARDS777_MAXPLAYERS;
BET_dcv->maxchips = CARDS777_MAXCHIPS;
BET_dcv->chipsize = CARDS777_CHIPSIZE;
BET_dcv->numplayers=numplayers;
BET_dcv->numplayers=0;
BET_betinfo_set(BET_dcv,"demo",range,0,Maxplayers);
if ( OS_thread_create(&dcv_t,NULL,(void *)BET_hostdcv,(void *)BET_dcv) != 0 )
if ( OS_thread_create(&dcv_t,NULL,(void *)BET_p2p_hostloop,(void *)BET_dcv) != 0 )
{
printf("error launching BET_hostloop for pub.%d pull.%d\n",BET_dcv->pubsock,BET_dcv->pullsock);
exit(-1);
}
if(pthread_join(dcv_t,NULL))
if(pthread_join(dcv_t,NULL))
{
printf("\nError in joining the main thread for dcv");
}
Expand All @@ -497,7 +497,7 @@ int main(int argc,const char *argv[])
BET_bvv->numplayers=numplayers;
BET_bvv->myplayerid=0;
BET_betinfo_set(BET_bvv,"demo",range,0,Maxplayers);
if ( OS_thread_create(&bvv_t,NULL,(void *)BET_clientbvv,(void *)BET_bvv) != 0 )
if ( OS_thread_create(&bvv_t,NULL,(void *)BET_p2p_bvvloop,(void *)BET_bvv) != 0 )
{
printf("error launching BET_clientloop for sub.%d push.%d\n",BET_bvv->subsock,BET_bvv->pushsock);
exit(-1);
Expand All @@ -509,7 +509,7 @@ int main(int argc,const char *argv[])
}

// for players
else if((argc==3)&&(strcmp(argv[1],"player")==0))
else if((argc==2)&&(strcmp(argv[1],"player")==0))
{
char *ptr;
i=0;
Expand All @@ -526,9 +526,9 @@ int main(int argc,const char *argv[])
BET_players[i]->maxchips = CARDS777_MAXCHIPS;
BET_players[i]->chipsize = CARDS777_CHIPSIZE;
BET_players[i]->numplayers=numplayers;
BET_players[i]->myplayerid=atoi(argv[2]);
//BET_players[i]->myplayerid=atoi(argv[2]);
BET_betinfo_set(BET_players[i],"demo",range,0,Maxplayers);
if (OS_thread_create(&players_t[i],NULL,(void *)BET_clientplayer,(void *)BET_players[i]) != 0 )
if (OS_thread_create(&players_t[i],NULL,(void *)BET_p2p_clientloop,(void *)BET_players[i]) != 0 )
{
printf("error launching BET_clientloop for sub.%d push.%d\n",BET_players[i]->subsock,BET_players[i]->pushsock);
exit(-1);
Expand Down Expand Up @@ -611,6 +611,13 @@ struct pair256 deckgen_common1(struct pair256 *randcards,int32_t numcards)
return(key);
}

void deckgen_common2(struct pair256 *randcards,int32_t numcards)
{
for (int32_t i=0; i<numcards; i++)
randcards[i].priv=curve25519_keypair(&randcards[i].prod);

}


void dekgen_vendor_perm(int numcards)
{
Expand All @@ -627,7 +634,7 @@ struct pair256 deckgen_player(bits256 *playerprivs,bits256 *playercards,int32_t
BET_permutation(permis,numcards);
for (i=0; i<numcards; i++)
{
playerprivs[i] = randcards[permis[i]].priv;
playerprivs[i] = randcards[i].priv; //permis[i]
playercards[i]=curve25519(playerprivs[i],key.prod);
}
return(key);
Expand Down Expand Up @@ -800,32 +807,34 @@ int32_t players_init(int32_t numplayers,int32_t numcards,bits256 deckid)
printf("numplayers.%d numcards.%d deck %s -> numgames.%d playererrs.%d ordering.(good.%d bad.%d) decode.[good %d, bad %d]\n",numplayers,numcards,bits256_str(str,deckid),numgames,playererrs,good,bad,decodegood,decodebad);
return(playererrs);
}
struct pair256 sg777_deckgen_vendor(int32_t playerid, bits256 *cardprods,bits256 *finalcards,int32_t numcards,bits256 *playercards,bits256 deckid) // given playercards[], returns cardprods[] and finalcards[]
int32_t sg777_deckgen_vendor(int32_t playerid, bits256 *cardprods,bits256 *finalcards,int32_t numcards,bits256 *playercards,bits256 deckid) // given playercards[], returns cardprods[] and finalcards[]
{
static struct pair256 key,randcards[256]; static bits256 active_deckid,hash_temp[CARDS777_MAXCARDS];
int32_t i,j,permis[256]; bits256 hash,xoverz,tmp[256];
if ( bits256_cmp(deckid,active_deckid) != 0 )
key=deckgen_common1(randcards,numcards);

for (i=0; i<numcards; i++)
{
xoverz = xoverz_donna(curve25519(randcards[i].priv,playercards[i]));
vcalc_sha256(0,hash.bytes,xoverz.bytes,sizeof(xoverz));
hash_temp[i]=hash; //optimization
tmp[i] = fmul_donna(curve25519_fieldelement(hash),randcards[i].priv);

}

for (i=0; i<numcards; i++)
static struct pair256 randcards[256]; static bits256 active_deckid,hash_temp[CARDS777_MAXCARDS];
int32_t retval=1; bits256 hash,xoverz,tmp[256];
char str[65];

if ( bits256_cmp(deckid,active_deckid) != 0 )
deckgen_common2(randcards,numcards);
else
retval=-1;

for (int32_t i=0; i<numcards; i++)
{
xoverz = xoverz_donna(curve25519(randcards[i].priv,playercards[i]));
vcalc_sha256(0,hash.bytes,xoverz.bytes,sizeof(xoverz));
hash_temp[i]=hash; //optimization
tmp[i] = fmul_donna(curve25519_fieldelement(hash),randcards[i].priv);

}

for (int32_t i=0; i<numcards; i++)
{
finalcards[i] = tmp[permis_d[i]];
g_hash[playerid][i]=hash_temp[permis_d[i]];//optimization
cardprods[i] = randcards[i].prod; // same cardprods[] returned for each player


}

return key;

}
return retval;
}
bits256 t_sg777_player_decode(struct privatebet_info *bet,int32_t cardID,int numplayers,struct pair256 key,bits256 public_key_b,bits256 blindedcard,bits256 *cardprods,bits256 *playerprivs,int32_t numcards)
{
Expand Down Expand Up @@ -1001,6 +1010,46 @@ bits256 sg777_player_decode(int32_t playerid,int32_t cardID,int numplayers,struc
return(tmp);
}

struct pair256 p2p_bvv_init(bits256 *keys,struct pair256 b_key,bits256 *blindings,bits256 *blindedcards,bits256 *finalcards,int32_t numcards,int32_t numplayers,int32_t playerid,bits256 deckid)
{
int32_t i,j,k,M,permi,permis[256]; uint8_t space[8192]; bits256 cardshares[CARDS777_MAXPLAYERS],basepoint,temp_hash[CARDS777_MAXCARDS];
char str[65],share_str[177];
struct enc_share temp;
/*
for (i=0; i<numcards; i++){
temp_hash[i]=g_hash[playerid][i];
}*/
for (i=0; i<numcards; i++)
{
blindings[i] = rand256(1);
blindedcards[i] = fmul_donna(finalcards[permis_b[i]],blindings[i]);
//g_hash[playerid][i]=temp_hash[permis_b[i]];//optimization
}
printf("\n%s:%d:For Player id:%d",__FUNCTION__,__LINE__,playerid);

for(i=0;i<numcards;i++)
{
printf("\nDCV card:%s",bits256_str(str,finalcards[permis_b[i]]));
printf("\nBVV card:%s",bits256_str(str,blindedcards[i]));
}

M = (numplayers/2) + 1;

gfshare_calc_sharenrs(sharenrs,numplayers,deckid.bytes,sizeof(deckid)); // same for all players for this round

for (i=0; i<numcards; i++)
{
gfshare_calc_shares(cardshares[0].bytes,blindings[i].bytes,sizeof(bits256),sizeof(bits256),M,numplayers,sharenrs,space,sizeof(space));
// create combined allshares
for (j=0; j<numplayers; j++) {
BET_ciphercreate(b_key.priv,keys[j],temp.bytes,cardshares[j].bytes,sizeof(cardshares[j]));
memcpy(g_shares[numplayers*numcards*playerid+ i*numplayers + j].bytes,temp.bytes,sizeof(temp));
}
}
// when all players have submitted their finalcards, blinding vendor can send encrypted allshares for each player, see cards777.c
return b_key;
}

struct pair256 sg777_blinding_vendor(struct pair256 *keys,struct pair256 b_key,bits256 *blindings,bits256 *blindedcards,bits256 *finalcards,int32_t numcards,int32_t numplayers,int32_t playerid,bits256 deckid)
{
int32_t i,j,k,M,permi,permis[256]; uint8_t space[8192]; bits256 cardshares[CARDS777_MAXPLAYERS],basepoint,temp_hash[CARDS777_MAXCARDS];
Expand Down
37 changes: 36 additions & 1 deletion privatebet/bet.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,39 @@ struct privatebet_share
struct pair256 player_key;
};

//added by sg777

struct deck_player_info
{
struct pair256 player_key;
bits256 cardpubkeys[CARDS777_MAXCARDS],cardprivkeys[CARDS777_MAXCARDS];
int32_t permis[CARDS777_MAXCARDS];
bits256 cardprods[CARDS777_MAXPLAYERS][CARDS777_MAXPLAYERS];
bits256 bvvblindcards[CARDS777_MAXPLAYERS][CARDS777_MAXCARDS];
bits256 dcvpubkey,bvvpubkey,deckid;
uint32_t numplayers,maxplayers,numcards;
};

struct deck_dcv_info
{
bits256 deckid;
struct pair256 dcv_key;
int32_t permis[CARDS777_MAXCARDS];
bits256 cardpubkeys[CARDS777_MAXPLAYERS][CARDS777_MAXCARDS];
bits256 dcvblindcards[CARDS777_MAXPLAYERS][CARDS777_MAXCARDS];
bits256 cardprods[CARDS777_MAXPLAYERS][CARDS777_MAXCARDS];
bits256 peerpubkeys[CARDS777_MAXPLAYERS];
uint32_t numplayers,maxplayers;
};

struct deck_bvv_info
{
bits256 deckid;
int32_t permis[CARDS777_MAXCARDS];
struct pair256 bvv_key;
bits256 bvvblindcards[CARDS777_MAXPLAYERS][CARDS777_MAXCARDS];
uint32_t numplayers,maxplayers;
};

bits256 *BET_process_packet(bits256 *cardpubs,bits256 *deckidp,bits256 senderpub,bits256 mypriv,uint8_t *decoded,int32_t maxsize,bits256 mypub,uint8_t *sendbuf,int32_t size,int32_t checkplayers,int32_t range);
cJSON *BET_hostrhashes(struct privatebet_info *bet);
Expand Down Expand Up @@ -346,10 +379,12 @@ bits256 card_rand256(int32_t privkeyflag,int8_t index);
struct pair256 deckgen_common(struct pair256 *randcards,int32_t numcards);
struct pair256 deckgen_common1(struct pair256 *randcards,int32_t numcards);
struct pair256 deckgen_player(bits256 *playerprivs,bits256 *playercards,int32_t *permis,int32_t numcards);
struct pair256 sg777_deckgen_vendor(int32_t playerid, bits256 *cardprods,bits256 *finalcards,int32_t numcards,bits256 *playercards,bits256 deckid);
int32_t sg777_deckgen_vendor(int32_t playerid, bits256 *cardprods,bits256 *finalcards,int32_t numcards,bits256 *playercards,bits256 deckid);
struct pair256 sg777_blinding_vendor(struct pair256 *keys,struct pair256 b_key,bits256 *blindings,bits256 *blindedcards,bits256 *finalcards,int32_t numcards,int32_t numplayers,int32_t playerid,bits256 deckid);
bits256 t_sg777_player_decode(struct privatebet_info *bet,int32_t cardID,int numplayers,struct pair256 key,bits256 public_key_b,bits256 blindedcard,bits256 *cardprods,bits256 *playerprivs,int32_t numcards);

struct pair256 p2p_bvv_init(bits256 *keys,struct pair256 b_key,bits256 *blindings,bits256 *blindedcards,bits256 *finalcards,int32_t numcards,int32_t numplayers,int32_t playerid,bits256 deckid);

bits256 curve25519_fieldelement(bits256 hash);


Loading

0 comments on commit 6d88452

Please sign in to comment.