diff --git a/equihash_verifi/README.md b/equihash_verifi/README.md deleted file mode 100644 index 8b13789..0000000 --- a/equihash_verifi/README.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/equihash_verifi/src/rtl/equihash_verifi_top.sv b/equihash_verifi/src/rtl/equihash_verifi_top.sv deleted file mode 100644 index 42ebc9b..0000000 --- a/equihash_verifi/src/rtl/equihash_verifi_top.sv +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This module is the top system level for the equihash verifier system. It takes in an AXI stream which - * represents block chain data and verifies that it is correct. - */ - -module equihash_verifi_top( - input i_clk, i_rst, - - if_axi_stream.sink i_data, - output logic o_valid -); - -if_axi_stream #(.DAT_BYTS(128)) blake2b_in(clk); -if_axi_stream #(.DAT_BYTS(64)) blake2b_out(clk); - - -always_ff @ (posedge i_clk) begin - i_data.rdy <= blake2b_in.rdy; - blake2b_in.val <= i_data.val; - blake2b_in.sop <= i_data.sop; - blake2b_in.eop <= i_data.eop; - blake2b_in.dat <= i_data.dat; - blake2b_in.err <= 0; - blake2b_in.mod <= 0; - blake2b_in.ctl <= 0; - - blake2b_out.rdy <= 1; - o_valid <= (blake2b_out.val && blake2b_out.dat == {64{1'b1}}); -end - - -// The Blake2 core for generating hashes - -logic [64*8-1:0] blake2_parameters; -always_comb begin - blake2_parameters = {32'd0, 8'd1, 8'd1, 8'd0, 8'd64}; -end - -blake2_top #( - .EQUIHASH( 1 ) -) -blake2_top ( - .i_clk ( i_clk ), - .i_rst ( i_rst ), - .i_byte_len ( 8'd128 ), - .i_parameters ( blake2_parameters ), - .i_block ( blake2b_in ), - .o_hash ( blake2b_out ) -); - -endmodule \ No newline at end of file diff --git a/ip_cores/blake2b/src/rtl/blake2b_pipe_top.sv b/ip_cores/blake2b/src/rtl/blake2b_pipe_top.sv index a443a7c..47b6af6 100644 --- a/ip_cores/blake2b/src/rtl/blake2b_pipe_top.sv +++ b/ip_cores/blake2b/src/rtl/blake2b_pipe_top.sv @@ -3,7 +3,14 @@ In order to get maximum throughput, the entire message block is required on the first clock cycle, so all hashes are single clock with .sop and .eop high. + You can optionally unroll the entire pipeline but this will use a large number of resources. + If you only unroll one pass, you need to interleave the hashes to get the best performance. + So the first part of input message comes on first clock cycle, and the next part comes 26 clocks later. + Does not support using keys. + + Futher optimization to save area is fixing part of input message constant for + all hashes (just have nonce as input that changes and place this in i_block.ctl). Copyright (C) 2019 Benjamin Devlin and Zcash Foundation @@ -24,7 +31,9 @@ module blake2b_pipe_top import blake2b_pkg::*; #( - // Since we fully unfold the pipeline, the message byte length is hard-coded + // Do we fully unroll the pipeline (lot of resources) or just un-roll one pass + parameter FULLY_UNROLL = 0, + // If we fully unfold the pipeline, the message byte length is hard-coded parameter MSG_LEN = 3, parameter CTL_BITS = 8 ) @@ -137,6 +146,8 @@ generate h[PIPE_G0+1] <= h[PIPE_G0]; init_local_work_vector_pipe(PIPE_G0+2, LAST_BLOCK); // Need to pull msg and ctl from the shift register if we have more than one pass + // and we fully unrolled. Otherwise next input will be on input. Assert the control + // matches. msg_out.rdy <= 1; if (g0 > 0) begin msg[PIPE_G0+1] <= msg_out.dat; @@ -149,7 +160,7 @@ generate end - if (g0 > 0) begin: GEN_MSG_FIFO + if (g0 > 0 && FULLY_UNROLL != 0) begin: GEN_MSG_FIFO always_ff @ (posedge i_clk) begin if (msg_in.val && msg_in.rdy) begin diff --git a/ip_cores/common/src/rtl/common_if.sv b/ip_cores/common/src/rtl/common_if.sv index 662f766..756b489 100644 --- a/ip_cores/common/src/rtl/common_if.sv +++ b/ip_cores/common/src/rtl/common_if.sv @@ -15,10 +15,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -*/ +*/ interface if_axi_stream # ( - parameter DAT_BYTS = 8, + parameter DAT_BYTS = 128, parameter CTL_BYTS = 8 )( input clk diff --git a/zcash_verifi/README.md b/zcash_verifi/README.md new file mode 100644 index 0000000..9b9b52b --- /dev/null +++ b/zcash_verifi/README.md @@ -0,0 +1 @@ +This is the design for verifing the Zcash blockchain on an FPGA diff --git a/zcash_verifi/src/data/block_241.bin b/zcash_verifi/src/data/block_241.bin new file mode 100644 index 0000000..fbb4089 Binary files /dev/null and b/zcash_verifi/src/data/block_241.bin differ diff --git a/zcash_verifi/src/rtl/zcash_verif_pkg.sv b/zcash_verifi/src/rtl/zcash_verif_pkg.sv new file mode 100644 index 0000000..8a4dfc9 --- /dev/null +++ b/zcash_verifi/src/rtl/zcash_verif_pkg.sv @@ -0,0 +1,22 @@ +/* + Parameter values and tasks for the verification system. + + Copyright (C) 2019 Benjamin Devlin and Zcash Foundation + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +package zcash_verif_pkg; + +endpackage \ No newline at end of file diff --git a/zcash_verifi/src/rtl/zcash_verif_system.sv b/zcash_verifi/src/rtl/zcash_verif_system.sv new file mode 100644 index 0000000..33094c2 --- /dev/null +++ b/zcash_verifi/src/rtl/zcash_verif_system.sv @@ -0,0 +1,69 @@ +/* + This takes in an AXI stream of a block and runs verification + checks (detailed in the architecture document). When all the checks are + completed the o_val will go high, and o_mask bit mask will be 1 for any + checks that failed. + + Copyright (C) 2019 Benjamin Devlin and Zcash Foundation + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +module zcash_verif_system( + input i_clk, i_rst, + + if_axi_stream.sink i_axi, + output logic [31:0] o_mask, + output logic o_val +); + +if_axi_stream #(.DAT_BYTS(128)) blake2b_in(clk); +if_axi_stream #(.DAT_BYTS(64)) blake2b_out(clk); + + +always_ff @ (posedge i_clk) begin + i_data.rdy <= blake2b_in.rdy; + blake2b_in.val <= i_data.val; + blake2b_in.sop <= i_data.sop; + blake2b_in.eop <= i_data.eop; + blake2b_in.dat <= i_data.dat; + blake2b_in.err <= 0; + blake2b_in.mod <= 0; + blake2b_in.ctl <= 0; + + blake2b_out.rdy <= 1; + o_valid <= (blake2b_out.val && blake2b_out.dat == {64{1'b1}}); +end + + +// The Blake2 core for generating hashes + +logic [64*8-1:0] blake2_parameters; +always_comb begin + blake2_parameters = {32'd0, 8'd1, 8'd1, 8'd0, 8'd64}; +end + +blake2_top #( + .EQUIHASH( 1 ) +) +blake2_top ( + .i_clk ( i_clk ), + .i_rst ( i_rst ), + .i_byte_len ( 8'd128 ), + .i_parameters ( blake2_parameters ), + .i_block ( blake2b_in ), + .o_hash ( blake2b_out ) +); + +endmodule \ No newline at end of file diff --git a/equihash_verifi/synth/equihash_verifi_top.xdc b/zcash_verifi/synth/zcash_verif_top.xdc similarity index 100% rename from equihash_verifi/synth/equihash_verifi_top.xdc rename to zcash_verifi/synth/zcash_verif_top.xdc