data/full_repos/permissive/420518472/src/fpgaminer_top.v
1: b'%Error: data/full_repos/permissive/420518472/src/fpgaminer_top.v:56: Cannot find file containing module: \'sha256_transform\'\n sha256_transform #(.LOOP(LOOP)) uut (\n ^~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/420518472/src,data/full_repos/permissive/420518472/sha256_transform\n             data/full_repos/permissive/420518472/src,data/full_repos/permissive/420518472/sha256_transform.v\n             data/full_repos/permissive/420518472/src,data/full_repos/permissive/420518472/sha256_transform.sv\n             sha256_transform\n             sha256_transform.v\n             sha256_transform.sv\n             obj_dir/sha256_transform\n             obj_dir/sha256_transform.v\n             obj_dir/sha256_transform.sv\n%Error: data/full_repos/permissive/420518472/src/fpgaminer_top.v:65: Cannot find file containing module: \'sha256_transform\'\n sha256_transform #(.LOOP(LOOP)) uut2 (\n ^~~~~~~~~~~~~~~~\n%Warning-WIDTH: data/full_repos/permissive/420518472/src/fpgaminer_top.v:101: Logical Operator LOGNOT expects 1 bit on the LHS, but LHS\'s VARREF \'cnt\' generates 6 bits.\n                                                                            : ... In instance fpgaminer_top\n assign leds[6] = !cnt;\n                  ^\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Warning-WIDTH: data/full_repos/permissive/420518472/src/fpgaminer_top.v:108: Operator ASSIGNDLY expects 6 bits on the Assign RHS, but Assign RHS\'s CONST \'1\'h0\' generates 1 bits.\n                                                                            : ... In instance fpgaminer_top\n   cnt <= 1\'b0;\n       ^~\n%Error: Exiting due to 2 error(s), 2 warning(s)\n'
module fpgaminer_top (
    input wire hash_clk,
	input wire [255:0] midstate,
	input wire [95:0] work_data,
	input wire [31:0] nonce_min,
	input wire [31:0] nonce_max,
	input wire reset,
	output reg [31:0] golden_nonce = 32'd0,
	output reg new_golden_nonce = 1'd0,
	output wire [7:0] leds
);






	parameter LOOP_LOG2 = 5;



	localparam [5:0] LOOP = (6'd1 << LOOP_LOG2);






	localparam [31:0] GOLDEN_NONCE_OFFSET = (32'd1 << (7 - LOOP_LOG2)) + 32'd1;

	reg [511:0] data = 512'd0;
    reg [31:0] nonce = 32'd0;

	wire [255:0] hash;
    wire [255:0] hash2;


	reg [5:0] cnt = 6'd0;
	wire feedback;
	reg wait_for_work = 1'b1;



	reg [255:0] midstate_buf = 256'd0;

    reg [95:0] data_buf = 96'd0;

	wire sha_clk = 1'd0;
	assign sha_clk = wait_for_work ? 1'b0 : hash_clk;




	sha256_transform #(.LOOP(LOOP)) uut (
		.feedback(feedback),
		.clk(hash_clk),
		.cnt(cnt),
		.rx_state(midstate_buf),
		.rx_input(data),
		.tx_hash(hash)
	);

	sha256_transform #(.LOOP(LOOP)) uut2 (
		.feedback(feedback),
		.clk(hash_clk),
		.cnt(cnt),
		.rx_state(256'h5be0cd191f83d9ab9b05688c510e527fa54ff53a3c6ef372bb67ae856a09e667),
		.rx_input({256'h0000010000000000000000000000000000000000000000000000000080000000, hash}),
		.tx_hash(hash2)
	);	
	

	reg feedback_d1 = 1'd0;
	reg golden_nonce_found = 1'd0;
	wire [5:0] cnt_next;
	wire [31:0] nonce_next;
	wire feedback_next;


	assign cnt_next = (LOOP == 1) ? 6'd0 : (cnt + 6'd1) & (LOOP-1);





	assign feedback_next = cnt_next != 0;
	assign feedback = cnt != 0;


	assign nonce_next = reset ? nonce_min : (feedback_next ? nonce : (nonce + 32'd1));
	

    assign leds[0] = !wait_for_work;
    assign leds[1] = !reset;
	assign leds[2] = !nonce[0];
	assign leds[3] = !golden_nonce_found;
	assign leds[4] = !new_golden_nonce;
	assign leds[5] = !feedback;
	assign leds[6] = !cnt;
	assign leds[7] = !(hash_clk == sha_clk);

	always @ (posedge hash_clk)
	begin
		if (reset) begin
			wait_for_work <= 1'b0;
			cnt <= 1'b0;
			golden_nonce_found <= 1'b0;
			feedback_d1 <= 1'b0;
		end


		midstate_buf <= midstate;
		data_buf <= work_data;

		feedback_d1 <= feedback;
		cnt <= cnt_next;
		new_golden_nonce <= golden_nonce_found;




		data <= {384'h000002800000000000000000000000000000000000000000000000000000000000000000000000000000000080000000, nonce_next, data_buf[95:0]};
		nonce <= nonce_next;


		golden_nonce_found <= (hash2[255:224] == 32'h00000000) && !feedback_d1 && !wait_for_work;
		if(golden_nonce_found)
		begin
			wait_for_work <= 1'b1;
			case (LOOP)
				1: begin 
					golden_nonce <= nonce - 32'd131;
					`ifdef SIM
					$display ("golden nonce found: %8x\n", nonce - 32'd131);
					`endif
				end
				2: begin 
					golden_nonce <= nonce - 32'd66;
					`ifdef SIM
					$display ("golden nonce found: %8x\n", nonce - 32'd66);
					`endif
				end
				default: begin
					golden_nonce <= nonce - GOLDEN_NONCE_OFFSET;
					`ifdef SIM
					$display ("golden nonce found: %8x\n", nonce - GOLDEN_NONCE_OFFSET);
					`endif
				end
			endcase;
		end

		`ifdef SIM
		if (!feedback_d1 && !wait_for_work)
			$display ("nonce: %8x\nhash2: %64x\n", nonce, hash2);
		`endif
	end
endmodule
module fpgaminer_top (
    input wire hash_clk,
	input wire [255:0] midstate,
	input wire [95:0] work_data,
	input wire [31:0] nonce_min,
	input wire [31:0] nonce_max,
	input wire reset,
	output reg [31:0] golden_nonce = 32'd0,
	output reg new_golden_nonce = 1'd0,
	output wire [7:0] leds
);







	parameter LOOP_LOG2 = 5;



	localparam [5:0] LOOP = (6'd1 << LOOP_LOG2);






	localparam [31:0] GOLDEN_NONCE_OFFSET = (32'd1 << (7 - LOOP_LOG2)) + 32'd1;

	reg [511:0] data = 512'd0;
    reg [31:0] nonce = 32'd0;

	wire [255:0] hash;
    wire [255:0] hash2;


	reg [5:0] cnt = 6'd0;
	wire feedback;
	reg wait_for_work = 1'b1;



	reg [255:0] midstate_buf = 256'd0;

    reg [95:0] data_buf = 96'd0;

	wire sha_clk = 1'd0;
	assign sha_clk = wait_for_work ? 1'b0 : hash_clk;




	sha256_transform #(.LOOP(LOOP)) uut (
		.feedback(feedback),
		.clk(hash_clk),
		.cnt(cnt),
		.rx_state(midstate_buf),
		.rx_input(data),
		.tx_hash(hash)
	);

	sha256_transform #(.LOOP(LOOP)) uut2 (
		.feedback(feedback),
		.clk(hash_clk),
		.cnt(cnt),
		.rx_state(256'h5be0cd191f83d9ab9b05688c510e527fa54ff53a3c6ef372bb67ae856a09e667),
		.rx_input({256'h0000010000000000000000000000000000000000000000000000000080000000, hash}),
		.tx_hash(hash2)
	);	
	

	reg feedback_d1 = 1'd0;
	reg golden_nonce_found = 1'd0;
	wire [5:0] cnt_next;
	wire [31:0] nonce_next;
	wire feedback_next;


	assign cnt_next = (LOOP == 1) ? 6'd0 : (cnt + 6'd1) & (LOOP-1);





	assign feedback_next = cnt_next != 0;
	assign feedback = cnt != 0;


	assign nonce_next = reset ? nonce_min : (feedback_next ? nonce : (nonce + 32'd1));
	

    assign leds[0] = !wait_for_work;
    assign leds[1] = !reset;
	assign leds[2] = !nonce[0];
	assign leds[3] = !golden_nonce_found;
	assign leds[4] = !new_golden_nonce;
	assign leds[5] = !feedback;
	assign leds[6] = !cnt;
	assign leds[7] = !(hash_clk == sha_clk);

	always @ (posedge hash_clk)
	begin
		if (reset) begin
			wait_for_work <= 1'b0;
			cnt <= 1'b0;
			golden_nonce_found <= 1'b0;
			feedback_d1 <= 1'b0;
		end


		midstate_buf <= midstate;
		data_buf <= work_data;

		feedback_d1 <= feedback;
		cnt <= cnt_next;
		new_golden_nonce <= golden_nonce_found;




		data <= {384'h000002800000000000000000000000000000000000000000000000000000000000000000000000000000000080000000, nonce_next, data_buf[95:0]};
		nonce <= nonce_next;


		golden_nonce_found <= (hash2[255:224] == 32'h00000000) && !feedback_d1 && !wait_for_work;
		if(golden_nonce_found)
		begin
			wait_for_work <= 1'b1;
			case (LOOP)
				1: begin 
					golden_nonce <= nonce - 32'd131;
					`ifdef SIM
					$display ("golden nonce found: %8x\n", nonce - 32'd131);
					`endif
				end
				2: begin 
					golden_nonce <= nonce - 32'd66;
					`ifdef SIM
					$display ("golden nonce found: %8x\n", nonce - 32'd66);
					`endif
				end
				default: begin
					golden_nonce <= nonce - GOLDEN_NONCE_OFFSET;
					`ifdef SIM
					$display ("golden nonce found: %8x\n", nonce - GOLDEN_NONCE_OFFSET);
					`endif
				end
			endcase;
		end

		`ifdef SIM
		if (!feedback_d1 && !wait_for_work)
			$display ("nonce: %8x\nhash2: %64x\n", nonce, hash2);
		`endif
	end
endmodule