From 3244deeaacc834ee9fad1118d442f2bfc176181d Mon Sep 17 00:00:00 2001 From: bsdevlin Date: Tue, 19 Feb 2019 09:31:31 -0500 Subject: [PATCH] Updates to naming of verif project, and extra blocks for testbench, example block file. --- equihash_verifi/README.md | 1 - .../src/rtl/equihash_verifi_top.sv | 51 ------------- ip_cores/blake2b/src/rtl/blake2b_pipe_top.sv | 15 +++- ip_cores/common/src/rtl/common_if.sv | 4 +- zcash_verifi/README.md | 1 + zcash_verifi/src/data/block_241.bin | Bin 0 -> 1619 bytes zcash_verifi/src/rtl/zcash_verif_pkg.sv | 22 ++++++ zcash_verifi/src/rtl/zcash_verif_system.sv | 69 ++++++++++++++++++ .../synth/zcash_verif_top.xdc | 0 9 files changed, 107 insertions(+), 56 deletions(-) delete mode 100644 equihash_verifi/README.md delete mode 100644 equihash_verifi/src/rtl/equihash_verifi_top.sv create mode 100644 zcash_verifi/README.md create mode 100644 zcash_verifi/src/data/block_241.bin create mode 100644 zcash_verifi/src/rtl/zcash_verif_pkg.sv create mode 100644 zcash_verifi/src/rtl/zcash_verif_system.sv rename equihash_verifi/synth/equihash_verifi_top.xdc => zcash_verifi/synth/zcash_verif_top.xdc (100%) 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 0000000000000000000000000000000000000000..fbb4089fd0c90dff38fa4b65faeefe65a0c2d332 GIT binary patch literal 1619 zcmaKsc{~#e0LM4?QP^ylIaWg|G1hFQoMSm+CP`&$8*)5PDw<>6524ObpL;P=@Ccgrol8mbCkWuGVhsQj-SlC=-D zwaXj9xsAk9;BTw)>yC;2vx(wB}buIuw=$qovyO_vJJPP?#NcO zCpPIR3N$4yJr6`3Y%Gg`YrVr51)W^t;!-%cVR+0Cx{i@S)N1@{K=&D$o z+2*3!ElO&4&Smf3!Ogmaz>M`~c&a>#@K9R0FBCuUfAS9&C~mFrC$T$rU&%w-J6LoQ zAv}vYoa&5yXRTxbBr;j=U$u}TfNypmvu!^b~gHUX3X;m)$TxTDoy#C?$p$K zAF(^IBSP2G6dJ|DxTNe_C>@^V%#5rtO3&OHRW>`ZM2Qk?IL$e_aBY5Gl(6aDs%-mHXNvW&YhhtSIjnRc08H zlL0$v%CTsoTRiEK-M~yDN`}y~bm?{zDwthes<+tVhC78~IDZJj81x z%iAY>TDwk@^1+*J$gRh|(!#gDCrWa|xOx*#WYYs)Eu>2!9QC(ta3=nBR^+OD-1kx>UB`b7`EUmm+xq|-RWI`$Q28cSFM)79U0$6{NZkEMf-en zSx>39n3fi1nPq$xNxxMgfak{_yMGU(;Pddgy^vyAp4Z@MQ1&fVTF|R!%>XdU|Di%q7vq@h_&%|f-+EHKqZuTA<0tx|L_8yKrdwFc!H915-}?d6JS%zS&Tb zThGRVbxw-rdUi#wpuvN=z75cUm^}+eU^DM)VmyiLv!6k?3vh=jZ>o90NobRnLKR7| zpm;l*FzK>dU53;DuBPg^_M+~^P7*&FT7Plj_(Nps+3)Kx)QZ^e*6fhY%riHeC%qn2 z=P^)}`(CC28d8Tn*sZ+L&#s#mWz~i&4iuv2UmhU|LPD3S7ULhL=(Q#Gi-AA!`g_Fw z$6nbFDaaiL0)84fgjD(00=Y>p!R@0j=4u@rJ7a=!@T8@!gS!#qjKWWn3?r8pebce` ku6}p=^`Tn@VY*eI`i!&hvp1r{s*bm-^7d;-r2Gv31r&bL0ssI2 literal 0 HcmV?d00001 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