hf-resistance

This commit is contained in:
Arionum
2018-02-05 04:11:33 +02:00
parent 50ed36734d
commit 6bf3ded17e
8 changed files with 37 additions and 16 deletions

View File

@@ -195,22 +195,26 @@ public function forge($nonce, $argon, $public_key, $private_key){
}
public function mine($public_key, $nonce, $argon, $difficulty=0, $current_id=0){
public function mine($public_key, $nonce, $argon, $difficulty=0, $current_id=0, $current_height=0){
global $_config;
if($current_id===0){
$current=$this->current();
$current_id=$current['id'];
}
$current_height=$current['height'];
}
if($difficulty===0) $difficulty=$this->difficulty();
$argon='$argon2i$v=19$m=16384,t=4,p=4'.$argon;
if($current_height>10800) $argon='$argon2i$v=19$m=524288,t=1,p=1'.$argon; //10800
else $argon='$argon2i$v=19$m=16384,t=4,p=4'.$argon;
$base="$public_key-$nonce-".$current_id."-$difficulty";
if(!password_verify($base,$argon)) { return false; }
if(!password_verify($base,$argon)) { return false; }
if($_config['testnet']==true) return true;
$hash=$base.$argon;
@@ -246,7 +250,7 @@ public function parse_block($block, $height, $data, $test=true){
foreach($data as &$x){
if(empty($x['src'])) $x['src']=$acc->get_address($x['public_key']);
if(!$trx->check($x)) return false;
if(!$trx->check($x,$height)) return false;
$balance[$x['src']]+=$x['val']+$x['fee'];

View File

@@ -1,6 +1,6 @@
<?php
define("VERSION", "0.1a");
define("VERSION", "0.2b");
date_default_timezone_set("Europe/Amsterdam");

View File

@@ -50,7 +50,7 @@ class Transaction {
_log("$x[id] - Transaction has empty src");
continue;
}
if(!$this->check($trans)){
if(!$this->check($trans, $current['height'])){
_log("$x[id] - Transaction Check Failed");
continue;
}
@@ -114,8 +114,13 @@ class Transaction {
}
public function check($x){
public function check($x, $height=0){
if($height===0){
$block=new Block;
$current=$block->current();
$height=$current['height'];
}
$acc= new Account;
$info=$x['val']."-".$x['fee']."-".$x['dst']."-".$x['message']."-".$x['version']."-".$x['public_key']."-".$x['date'];
@@ -125,6 +130,7 @@ class Transaction {
$fee=$x['val']*0.0025;
$fee=number_format($fee,8,".","");
if($fee<0.00000001) $fee=0.00000001;
if($height>10800&&$fee>10) $fee=10; //10800
if($fee!=$x['fee']) { _log("$x[id] - Fee not 0.25%"); return false; }
if(!$acc->valid($x['dst'])) { _log("$x[id] - Invalid destination address"); return false; }