data/full_repos/permissive/478243883/Merkle_Root_Hash.v
1: b"%Error: data/full_repos/permissive/478243883/Merkle_Root_Hash.v:213: Can't find definition of variable: 'row_count'\n                        row_count               <= row_count -1;                        \n                                                   ^~~~~~~~~\n%Error: Exiting due to 1 error(s)\n"
module Merkle_Root_Hash (
    TX_ID_input,
    total_TX_ID,
    TX_ID_valid,
    clk,
    merkle_root,
    merkle_root_valid
);








input [1023:0] TX_ID_input;
input [7:0] total_TX_ID;
input TX_ID_valid;
input clk;


output reg [255:0] merkle_root;
output reg merkle_root_valid;







reg [7:0] hash_counter;
reg parity;
reg [1023:0] TX_ID_reg;
reg [1023:0] TX_ID_reg_temp;
reg [2:0] hash_state;
reg [7:0] total_TX_ID_reg;








reg ready_to_hash;
reg [511:0] input_message;
reg [255:0] initial_hashes;


wire [255:0] digest;
wire Hashing_Done;


parameter INITIAL_HASHES  = 256'h6a09e667bb67ae853c6ef372a54ff53a510e527f9b05688c1f83d9ab5be0cd19;
parameter FIRST_HASH_MSG  = 512'h80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200;
parameter SECOND_HASH_MSG = 256'h8000000000000000000000000000000000000000000000000000000000000100;


SHA_256_Top SHA_256_inst(
    .ready_to_hash(ready_to_hash),
    .clk(clk),
    .input_message(input_message),
    .initial_hashes(initial_hashes),
    .digest(digest),
    .Hashing_Done(Hashing_Done)
);






always@(posedge clk)
begin


if (TX_ID_valid == 1)
    begin

    hash_state                  <= 0;

    ready_to_hash               <= 0;
    input_message               <= 512'b0;
    initial_hashes              <= 256'b0;

    total_TX_ID_reg             <= {1'b0, total_TX_ID[7:1]};
    hash_counter                <= {1'b0, total_TX_ID[7:1]};
    TX_ID_reg                   <= TX_ID_input;
    parity                      <= total_TX_ID[1];
    TX_ID_reg_temp[4863:0]      <= 0;     

    merkle_root_valid           <= 0;
    end


else 
    begin
    case(hash_state)


        3'd0:
            begin              

            if ((parity == 1) & (hash_counter == 0))
                begin
                input_message   <= {TX_ID_reg[255:0],TX_ID_reg[255:0]};
                end
            else
                begin
                input_message   <= TX_ID_reg[((hash_counter-1)*512) +: 512];
                end
            initial_hashes      <= INITIAL_HASHES;
            ready_to_hash       <= 1;
            hash_state          <= 3'd1;
            merkle_root_valid   <= 0;
            end


        3'd1:
            begin            
            merkle_root_valid   <= 0;

            if (Hashing_Done)
                begin
                input_message   <= FIRST_HASH_MSG;
                initial_hashes  <= digest;
                ready_to_hash   <= 1;
                hash_state      <= 3'd2;
                end

            else
                begin
                ready_to_hash   <= 0; 
                input_message   <= 512'b0;
                initial_hashes  <= 256'b0;
                hash_state      <= 3'd1;
                end
            end


        3'd2:
            begin            
            merkle_root_valid   <= 0;

            if (Hashing_Done)
                begin
                input_message   <= {digest, SECOND_HASH_MSG};
                initial_hashes  <= INITIAL_HASHES;
                ready_to_hash   <= 1;
                hash_state      <= 3'd3;
                end

            else
                begin
                ready_to_hash   <= 0; 
                input_message   <= 512'b0;
                initial_hashes  <= 256'b0;
                hash_state      <= 3'd2;
                end
            end


        3'd3:
            begin            

            if (Hashing_Done)
                begin

                if (hash_counter == 1)
                    begin                        

                    if (total_TX_ID_reg == 1)
                        begin
                        merkle_root         <= digest;
                        merkle_root_valid   <= 1;
                        hash_state          <= 3'd4;
                        end

                    else
                        begin  
                        merkle_root_valid       <= 0;
                        total_TX_ID_reg         <= {1'b0, total_TX_ID_reg[7:1]};
                        hash_counter            <= {1'b0, total_TX_ID_reg[7:1]};
                        TX_ID_reg_temp          <= 0;                         
                        TX_ID_reg[((total_TX_ID_reg-1)*256) +: 256] <= TX_ID_reg_temp[((total_TX_ID_reg-1)*256) +: 256];
                        TX_ID_reg[255:0]        <= digest; 
                        row_count               <= row_count -1;                        
                        parity                  <= total_TX_ID_reg[1];
                        hash_state              <= 3'd0;
                        end
                    end

                else
                    begin
                    TX_ID_reg_temp[((hash_counter-1)*256) +: 256]      <= digest;
                    merkle_root_valid   <= 0;
                    hash_counter        <= hash_counter - 1;
                    hash_state          <= 3'd0;
                    end
                end

            else
                begin
                merkle_root_valid   <= 0;                   
                ready_to_hash       <= 0; 
                input_message       <= 512'b0;
                initial_hashes      <= 256'b0;
                hash_state          <= 3'd3;
                end
            end


        3'd4:
            begin            
            merkle_root_valid   <= 0;               
            ready_to_hash       <= 0; 
            input_message       <= 512'b0;
            initial_hashes      <= 256'b0;
            hash_state          <= 3'd4;
            end

        default: hash_state = 3'd4;
    endcase
    end
end



endmodule
module Merkle_Root_Hash (
    TX_ID_input,
    total_TX_ID,
    TX_ID_valid,
    clk,
    merkle_root,
    merkle_root_valid
);









input [1023:0] TX_ID_input;
input [7:0] total_TX_ID;
input TX_ID_valid;
input clk;


output reg [255:0] merkle_root;
output reg merkle_root_valid;







reg [7:0] hash_counter;
reg parity;
reg [1023:0] TX_ID_reg;
reg [1023:0] TX_ID_reg_temp;
reg [2:0] hash_state;
reg [7:0] total_TX_ID_reg;








reg ready_to_hash;
reg [511:0] input_message;
reg [255:0] initial_hashes;


wire [255:0] digest;
wire Hashing_Done;


parameter INITIAL_HASHES  = 256'h6a09e667bb67ae853c6ef372a54ff53a510e527f9b05688c1f83d9ab5be0cd19;
parameter FIRST_HASH_MSG  = 512'h80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200;
parameter SECOND_HASH_MSG = 256'h8000000000000000000000000000000000000000000000000000000000000100;


SHA_256_Top SHA_256_inst(
    .ready_to_hash(ready_to_hash),
    .clk(clk),
    .input_message(input_message),
    .initial_hashes(initial_hashes),
    .digest(digest),
    .Hashing_Done(Hashing_Done)
);






always@(posedge clk)
begin


if (TX_ID_valid == 1)
    begin

    hash_state                  <= 0;

    ready_to_hash               <= 0;
    input_message               <= 512'b0;
    initial_hashes              <= 256'b0;

    total_TX_ID_reg             <= {1'b0, total_TX_ID[7:1]};
    hash_counter                <= {1'b0, total_TX_ID[7:1]};
    TX_ID_reg                   <= TX_ID_input;
    parity                      <= total_TX_ID[1];
    TX_ID_reg_temp[4863:0]      <= 0;     

    merkle_root_valid           <= 0;
    end


else 
    begin
    case(hash_state)


        3'd0:
            begin              

            if ((parity == 1) & (hash_counter == 0))
                begin
                input_message   <= {TX_ID_reg[255:0],TX_ID_reg[255:0]};
                end
            else
                begin
                input_message   <= TX_ID_reg[((hash_counter-1)*512) +: 512];
                end
            initial_hashes      <= INITIAL_HASHES;
            ready_to_hash       <= 1;
            hash_state          <= 3'd1;
            merkle_root_valid   <= 0;
            end


        3'd1:
            begin            
            merkle_root_valid   <= 0;

            if (Hashing_Done)
                begin
                input_message   <= FIRST_HASH_MSG;
                initial_hashes  <= digest;
                ready_to_hash   <= 1;
                hash_state      <= 3'd2;
                end

            else
                begin
                ready_to_hash   <= 0; 
                input_message   <= 512'b0;
                initial_hashes  <= 256'b0;
                hash_state      <= 3'd1;
                end
            end


        3'd2:
            begin            
            merkle_root_valid   <= 0;

            if (Hashing_Done)
                begin
                input_message   <= {digest, SECOND_HASH_MSG};
                initial_hashes  <= INITIAL_HASHES;
                ready_to_hash   <= 1;
                hash_state      <= 3'd3;
                end

            else
                begin
                ready_to_hash   <= 0; 
                input_message   <= 512'b0;
                initial_hashes  <= 256'b0;
                hash_state      <= 3'd2;
                end
            end


        3'd3:
            begin            

            if (Hashing_Done)
                begin

                if (hash_counter == 1)
                    begin                        

                    if (total_TX_ID_reg == 1)
                        begin
                        merkle_root         <= digest;
                        merkle_root_valid   <= 1;
                        hash_state          <= 3'd4;
                        end

                    else
                        begin  
                        merkle_root_valid       <= 0;
                        total_TX_ID_reg         <= {1'b0, total_TX_ID_reg[7:1]};
                        hash_counter            <= {1'b0, total_TX_ID_reg[7:1]};
                        TX_ID_reg_temp          <= 0;                         
                        TX_ID_reg[((total_TX_ID_reg-1)*256) +: 256] <= TX_ID_reg_temp[((total_TX_ID_reg-1)*256) +: 256];
                        TX_ID_reg[255:0]        <= digest; 
                        row_count               <= row_count -1;                        
                        parity                  <= total_TX_ID_reg[1];
                        hash_state              <= 3'd0;
                        end
                    end

                else
                    begin
                    TX_ID_reg_temp[((hash_counter-1)*256) +: 256]      <= digest;
                    merkle_root_valid   <= 0;
                    hash_counter        <= hash_counter - 1;
                    hash_state          <= 3'd0;
                    end
                end

            else
                begin
                merkle_root_valid   <= 0;                   
                ready_to_hash       <= 0; 
                input_message       <= 512'b0;
                initial_hashes      <= 256'b0;
                hash_state          <= 3'd3;
                end
            end


        3'd4:
            begin            
            merkle_root_valid   <= 0;               
            ready_to_hash       <= 0; 
            input_message       <= 512'b0;
            initial_hashes      <= 256'b0;
            hash_state          <= 3'd4;
            end

        default: hash_state = 3'd4;
    endcase
    end
end



endmodule