Updates to testbench to fix bugs.
This commit is contained in:
parent
7140da7da0
commit
c8f1c9223f
|
@ -32,9 +32,9 @@ module blake2b_pipe_top
|
||||||
import blake2b_pkg::*;
|
import blake2b_pkg::*;
|
||||||
#(
|
#(
|
||||||
// If we fully unfold the pipeline, the message byte length is hard-coded
|
// If we fully unfold the pipeline, the message byte length is hard-coded
|
||||||
parameter MSG_LEN,
|
parameter MSG_LEN,
|
||||||
parameter MSG_VAR_BYTS = MSG_LEN, // Setting this != MSG_LEN will assume only those bytes are changing when fully unrolled
|
parameter [(8*MSG_LEN)-1:0] MSG_VAR_BM = {MSG_LEN*8{1'b1}}, // A bit mask of what bitds in the message will change, can be used to reduce logic
|
||||||
parameter CTL_BITS = 8
|
parameter CTL_BITS = 8
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
input i_clk, i_rst,
|
input i_clk, i_rst,
|
||||||
|
@ -53,7 +53,7 @@ localparam NUM_PIPE = 2 + NUM_PASSES*(NUM_ROUNDS*2) + 2*NUM_PASSES - 1;
|
||||||
|
|
||||||
logic [NUM_PIPE-1:0][15:0][63:0] v;
|
logic [NUM_PIPE-1:0][15:0][63:0] v;
|
||||||
logic [NUM_PIPE-1:0][7:0][63:0] h;
|
logic [NUM_PIPE-1:0][7:0][63:0] h;
|
||||||
logic [NUM_PIPE-1:0][MSG_VAR_BYTS*8-1:0] msg;
|
logic [NUM_PIPE-1:0][MSG_LEN*8-1:0] msg;
|
||||||
logic [MSG_LEN*8-1:0] msg_fixed;
|
logic [MSG_LEN*8-1:0] msg_fixed;
|
||||||
logic [7:0] byte_len;
|
logic [7:0] byte_len;
|
||||||
logic [NUM_PIPE-1:0][CTL_BITS-1:0] ctl;
|
logic [NUM_PIPE-1:0][CTL_BITS-1:0] ctl;
|
||||||
|
@ -94,7 +94,8 @@ generate
|
||||||
// First stage - depends if we are fully unrolling or not as where input comes from
|
// First stage - depends if we are fully unrolling or not as where input comes from
|
||||||
h[0] <= i_parameters ^ blake2b_pkg::IV;
|
h[0] <= i_parameters ^ blake2b_pkg::IV;
|
||||||
v[0] <= 0;
|
v[0] <= 0;
|
||||||
msg[0] <= i_block.dat;
|
for (int i = 0; i < MSG_LEN*8; i++)
|
||||||
|
msg[0][i] <= MSG_VAR_BM[i] ? i_block.dat[i] : 1'b0;
|
||||||
if (i_block.val) begin
|
if (i_block.val) begin
|
||||||
msg_fixed <= i_block.dat;
|
msg_fixed <= i_block.dat;
|
||||||
byte_len <= i_byte_len;
|
byte_len <= i_byte_len;
|
||||||
|
@ -151,18 +152,14 @@ generate
|
||||||
end
|
end
|
||||||
// Second stage
|
// Second stage
|
||||||
if (o_hash.rdy) begin
|
if (o_hash.rdy) begin
|
||||||
|
|
||||||
// Shift message down either from previous pipeline or from fixed portion
|
// Shift message down either from previous pipeline or from fixed portion
|
||||||
if (g0 < (NUM_PASSES - 1)) begin
|
if (g0 < (NUM_PASSES - 1)) begin
|
||||||
h[PIPE_G0+1] <= h[PIPE_G0];
|
h[PIPE_G0+1] <= h[PIPE_G0];
|
||||||
init_local_work_vector_pipe(PIPE_G0+1, LAST_BLOCK ? byte_len : 128 , LAST_BLOCK);
|
init_local_work_vector_pipe(PIPE_G0+1, LAST_BLOCK ? byte_len : 128 , LAST_BLOCK);
|
||||||
msg[PIPE_G0+1] <= 0;
|
|
||||||
for (int i = 0; i < 128; i++) begin
|
|
||||||
if ((g0+1)*128 + i < MSG_VAR_BYTS)
|
|
||||||
msg[PIPE_G0+1][i*8 +: 8] <= msg[PIPE_G0][((g0+1)*128 + i)*8 +: 8];
|
|
||||||
end
|
|
||||||
ctl[PIPE_G0+1] <= ctl[PIPE_G0];
|
ctl[PIPE_G0+1] <= ctl[PIPE_G0];
|
||||||
end
|
end
|
||||||
|
msg[PIPE_G0+1] <= msg[PIPE_G0];
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -194,11 +191,12 @@ generate
|
||||||
logic [63:0] msg0, msg1;
|
logic [63:0] msg0, msg1;
|
||||||
logic [16*64-1:0] msg_;
|
logic [16*64-1:0] msg_;
|
||||||
always_comb begin
|
always_comb begin
|
||||||
msg_ = msg[PIPE_G2-1];
|
msg_ = 0;
|
||||||
//for (int i = MSG_VAR_BYTS; i < 16*64; i++)
|
for (int i = 0; i < 1024; i++)
|
||||||
for (int i = 0; i < 128; i++)
|
if (((i + g0*1024) < MSG_LEN*8) && MSG_VAR_BM[i + (g0*1024)])
|
||||||
if (i + (g0*128) >= MSG_VAR_BYTS)
|
msg_[i] = msg[PIPE_G2-1][i + g0*1024];
|
||||||
msg_[i*8 +: 8] = msg_fixed_int[i*8 +: 8];
|
else
|
||||||
|
msg_[i] = msg_fixed_int[i];
|
||||||
for (int i = 0; i < 8; i ++) begin
|
for (int i = 0; i < 8; i ++) begin
|
||||||
msg0 = msg_[64*blake2b_pkg::SIGMA[16*(g1%10) + g2*8 + g3*2] +: 64];
|
msg0 = msg_[64*blake2b_pkg::SIGMA[16*(g1%10) + g2*8 + g3*2] +: 64];
|
||||||
msg1 = msg_[64*blake2b_pkg::SIGMA[16*(g1%10) + g2*8 + g3*2 + 1] +: 64];
|
msg1 = msg_[64*blake2b_pkg::SIGMA[16*(g1%10) + g2*8 + g3*2 + 1] +: 64];
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module blake2b_g_tb();
|
module blake2b_g_tb();
|
||||||
|
|
||||||
|
@ -43,10 +43,10 @@ begin
|
||||||
repeat (PIPELINES) @(posedge clk);
|
repeat (PIPELINES) @(posedge clk);
|
||||||
|
|
||||||
#1;
|
#1;
|
||||||
assert (o_a == 64'hf0c9aa0de38b1b89) else $fatal(0, "%m %t:ERROR, o_a did not match", $time);
|
assert (o_a == 64'hf0c9aa0de38b1b89) else $fatal(1, "%m %t:ERROR, o_a did not match", $time);
|
||||||
assert (o_b == 64'hbbdf863401fde49b) else $fatal(0, "%m %t:ERROR, o_b did not match", $time);
|
assert (o_b == 64'hbbdf863401fde49b) else $fatal(1, "%m %t:ERROR, o_b did not match", $time);
|
||||||
assert (o_c == 64'he85eb23c42183d3d) else $fatal(0, "%m %t:ERROR, o_c did not match", $time);
|
assert (o_c == 64'he85eb23c42183d3d) else $fatal(1, "%m %t:ERROR, o_c did not match", $time);
|
||||||
assert (o_d == 64'h7111fd8b6445099d) else $fatal(0, "%m %t:ERROR, o_d did not match", $time);
|
assert (o_d == 64'h7111fd8b6445099d) else $fatal(1, "%m %t:ERROR, o_d did not match", $time);
|
||||||
|
|
||||||
$display("test1 PASSED");
|
$display("test1 PASSED");
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
|
|
||||||
module blake2b_top_tb();
|
module blake2b_top_tb();
|
||||||
|
|
||||||
parameter USE_BLAKE2B_PIPE = 0; // This instantiates the pipelined version instead
|
parameter USE_BLAKE2B_PIPE = 1; // This instantiates the pipelined version instead
|
||||||
parameter USE_BLAKE2B_PIPE_MSG_LEN = 140; // Has to be the maximum of whatever test case
|
parameter USE_BLAKE2B_PIPE_MSG_LEN = 144; // Has to be the maximum of whatever test case
|
||||||
parameter MSG_VAR_BYTS = USE_BLAKE2B_PIPE_MSG_LEN;
|
parameter MSG_VAR_BM = {USE_BLAKE2B_PIPE_MSG_LEN*8{1'b1}};
|
||||||
|
|
||||||
import blake2b_pkg::*;
|
import blake2b_pkg::*;
|
||||||
import common_pkg::*;
|
import common_pkg::*;
|
||||||
|
@ -58,7 +58,7 @@ generate if ( USE_BLAKE2B_PIPE == 0 ) begin: DUT_GEN
|
||||||
end else begin
|
end else begin
|
||||||
blake2b_pipe_top #(
|
blake2b_pipe_top #(
|
||||||
.MSG_LEN ( USE_BLAKE2B_PIPE_MSG_LEN ),
|
.MSG_LEN ( USE_BLAKE2B_PIPE_MSG_LEN ),
|
||||||
.MSG_VAR_BYTS ( MSG_VAR_BYTS ),
|
.MSG_VAR_BM ( MSG_VAR_BM ),
|
||||||
.CTL_BITS ( 8 )
|
.CTL_BITS ( 8 )
|
||||||
)
|
)
|
||||||
DUT (
|
DUT (
|
||||||
|
@ -150,7 +150,6 @@ endtask
|
||||||
// Main testbench calls
|
// Main testbench calls
|
||||||
initial begin
|
initial begin
|
||||||
i_block.reset_source();
|
i_block.reset_source();
|
||||||
i_byte_len = 3;
|
|
||||||
out_hash.rdy = 1;
|
out_hash.rdy = 1;
|
||||||
parameters = {32'd0, 8'd1, 8'd1, 8'd0, 8'd64};
|
parameters = {32'd0, 8'd1, 8'd1, 8'd0, 8'd64};
|
||||||
#200ns;
|
#200ns;
|
||||||
|
|
|
@ -54,7 +54,7 @@ logic all_checks_done;
|
||||||
|
|
||||||
|
|
||||||
if_axi_stream #(.DAT_BYTS(BLAKE2B_DIGEST_BYTS), .CTL_BYTS(1)) blake2b_out_hash(i_clk);
|
if_axi_stream #(.DAT_BYTS(BLAKE2B_DIGEST_BYTS), .CTL_BYTS(1)) blake2b_out_hash(i_clk);
|
||||||
if_axi_stream #(.DAT_BYTS(EQUIHASH_BLAKE2B_PIPE == 0 ? 128 : EQUIHASH_GEN_BYTS )) blake2b_in_hash(i_clk);
|
if_axi_stream #(.DAT_BYTS(EQUIHASH_GEN_BYTS)) blake2b_in_hash(i_clk);
|
||||||
|
|
||||||
// We write the block into a port as it comes in and then read from the b port
|
// We write the block into a port as it comes in and then read from the b port
|
||||||
if_ram #(.RAM_WIDTH(DAT_BITS), .RAM_DEPTH(SOL_LIST_BYTS/DAT_BYTS)) equihash_sol_bram_if_a (i_clk, i_rst);
|
if_ram #(.RAM_WIDTH(DAT_BITS), .RAM_DEPTH(SOL_LIST_BYTS/DAT_BYTS)) equihash_sol_bram_if_a (i_clk, i_rst);
|
||||||
|
@ -81,8 +81,8 @@ always_ff @ (posedge i_clk) begin
|
||||||
equihash_sol_bram_if_a.d <= i_axi.dat;
|
equihash_sol_bram_if_a.d <= i_axi.dat;
|
||||||
|
|
||||||
if (i_axi.val && i_axi.rdy && ~cblockheader_val) begin
|
if (i_axi.val && i_axi.rdy && ~cblockheader_val) begin
|
||||||
cblockheader <= {cblockheader, i_axi.dat};
|
cblockheader[cblockheader_byts*8 +: DAT_BITS] <= i_axi.dat;
|
||||||
cblockheader_val <= (cblockheader_byts + DAT_BYTS) >= $bits(cblockheader_t)/8;
|
cblockheader_val <= (cblockheader_byts + DAT_BYTS) > $bits(cblockheader_t)/8;
|
||||||
cblockheader_byts <= cblockheader_byts + DAT_BYTS;
|
cblockheader_byts <= cblockheader_byts + DAT_BYTS;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -215,32 +215,22 @@ function hash_solution(input [N-1:0] curr, input [N*INDICIES_PER_HASH-1:0] in);
|
||||||
return curr;
|
return curr;
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
// Instantiate the Blake2b block
|
// Instantiate the Blake2b block - use high performance pipelined version
|
||||||
generate if ( EQUIHASH_BLAKE2B_PIPE == 0 ) begin: BLAKE2B_GEN
|
localparam [EQUIHASH_GEN_BYTS*8-1:0] EQUIHASH_GEN_BYTS_BM = {{(EQUIHASH_GEN_BYTS*8-21){1'b0}}, {21{1'b1}}}; // Only lower 21 bits of input to hash change
|
||||||
blake2b_top DUT (
|
blake2b_pipe_top #(
|
||||||
.i_clk ( i_clk ),
|
.MSG_LEN ( EQUIHASH_GEN_BYTS ),
|
||||||
.i_rst ( i_rst ),
|
.MSG_VAR_BM ( EQUIHASH_GEN_BYTS_BM ),
|
||||||
.i_parameters ( parameters ),
|
.CTL_BITS ( 8 )
|
||||||
.i_byte_len ( EQUIHASH_GEN_BYTS ),
|
)
|
||||||
.i_block ( blake2b_in_hash ),
|
blake2b_pipe_top_i (
|
||||||
.o_hash ( blake2b_out_hash )
|
.i_clk ( i_clk ),
|
||||||
);
|
.i_rst ( i_rst ),
|
||||||
end else begin
|
.i_parameters ( parameters ),
|
||||||
blake2b_pipe_top #(
|
.i_byte_len ( EQUIHASH_GEN_BYTS ),
|
||||||
.MSG_LEN ( EQUIHASH_GEN_BYTS ),
|
.i_block ( blake2b_in_hash ),
|
||||||
.MSG_VAR_BYTS ( 4 ), // Only lower 4 bytes of input to hash change
|
.o_hash ( blake2b_out_hash )
|
||||||
.CTL_BITS ( 8 )
|
);
|
||||||
)
|
|
||||||
DUT (
|
|
||||||
.i_clk ( i_clk ),
|
|
||||||
.i_rst ( i_rst ),
|
|
||||||
.i_parameters ( parameters ),
|
|
||||||
.i_byte_len ( EQUIHASH_GEN_BYTS ),
|
|
||||||
.i_block ( blake2b_in_hash ),
|
|
||||||
.o_hash ( blake2b_out_hash )
|
|
||||||
);
|
|
||||||
end
|
|
||||||
endgenerate
|
|
||||||
|
|
||||||
// Memory to store the equihash solution as it comes in. We use dual port,
|
// Memory to store the equihash solution as it comes in. We use dual port,
|
||||||
// one port for writing and one port for reading
|
// one port for writing and one port for reading
|
||||||
|
|
|
@ -22,7 +22,6 @@ package zcash_verif_pkg;
|
||||||
// Variables used in the equihash PoW
|
// Variables used in the equihash PoW
|
||||||
parameter [31:0] N = 200;
|
parameter [31:0] N = 200;
|
||||||
parameter [31:0] K = 9;
|
parameter [31:0] K = 9;
|
||||||
parameter EQUIHASH_BLAKE2B_PIPE = 1; // Do we use the pipelined (high performance but large area) Blake2b core
|
|
||||||
parameter INDICIES_PER_HASH = (512/N);
|
parameter INDICIES_PER_HASH = (512/N);
|
||||||
parameter COLLISION_BIT_LEN = N/(K+1);
|
parameter COLLISION_BIT_LEN = N/(K+1);
|
||||||
parameter BLAKE2B_DIGEST_BYTS = (N*INDICIES_PER_HASH)/8;
|
parameter BLAKE2B_DIGEST_BYTS = (N*INDICIES_PER_HASH)/8;
|
||||||
|
|
|
@ -65,7 +65,7 @@ file_to_axi #(
|
||||||
.FP ( 0 )
|
.FP ( 0 )
|
||||||
)
|
)
|
||||||
file_to_axi_block241 (
|
file_to_axi_block241 (
|
||||||
.i_file ({my_file_path_s, "/../data/block_241.bin"}),
|
.i_file ({my_file_path_s, "/../data/block_346.bin"}),
|
||||||
.i_clk ( clk ),
|
.i_clk ( clk ),
|
||||||
.i_rst ( rst ),
|
.i_rst ( rst ),
|
||||||
.i_start ( start_241 ),
|
.i_start ( start_241 ),
|
||||||
|
@ -82,15 +82,18 @@ DUT (
|
||||||
.o_mask_val ( mask_val )
|
.o_mask_val ( mask_val )
|
||||||
);
|
);
|
||||||
|
|
||||||
// This is a tests the sample block 241
|
// This is a tests the sample block 346 in the block chain
|
||||||
task test_block_241();
|
task test_block_346();
|
||||||
begin
|
begin
|
||||||
$display("Running test_block_241...");
|
$display("Running test_block_346...");
|
||||||
start_241 = 1;
|
start_241 = 1;
|
||||||
|
|
||||||
|
|
||||||
while(!done_241) @(posedge clk);
|
while(!done_241 && !mask_val) @(posedge clk);
|
||||||
$display("test_block_241 PASSED");
|
|
||||||
|
assert (~(|mask)) else $fatal(1, "%m %t ERROR: test_block_346 mask was non-zero", $time);
|
||||||
|
assert (~mask.XOR_FAIL) else $fatal(1, "%m %t ERROR: test_block_346 failed XOR mask check", $time);
|
||||||
|
$display("test_block_346 PASSED");
|
||||||
|
|
||||||
end
|
end
|
||||||
endtask
|
endtask
|
||||||
|
@ -99,7 +102,7 @@ endtask
|
||||||
initial begin
|
initial begin
|
||||||
#200ns;
|
#200ns;
|
||||||
|
|
||||||
test_block_241();
|
test_block_346();
|
||||||
|
|
||||||
#10us $finish();
|
#10us $finish();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue