Thread: Function Conversion

  1. #1
    Registered User
    Join Date
    Jun 2018
    Posts
    5

    Function Conversion

    Hello everyone, i am new to this forum and also to C, i am a linux user that runs a crypto currency minning pool, i am trying to fix a bug in my pool that disconnects clients, its a long story but i will try to resume in short words, i noticed that functions and libraries in my pool code are not the same on the miner program, this small differences produce a warning in the user end that eventually escalates to an error and disconnect, i managed to change all code to be 100% from the miner client on my stratum code in the pool, i can compile and it runs but i have a logical error that now closes my port and restart the stratum service, i cant find the right way to match the existing stratum, database, etc on my side because the result from the new code is a similar function but defined in another way, i copied my original code and then the code from the miner program that i changed to see if someone can help me convert a void and const void to char const char, i cannot change the function on my side because it affects the rest of the program, so i have to find a way to adapt this new code so i can have the expected output

    Original Code
    Code:
    #include <stdlib.h>
    #include <stdint.h>
    #include <string.h>
    #include <stdio.h>
    #include "Lyra2z.h"
    #define _ALIGN(x) __attribute__ ((aligned(x)))
    //extern uint64_t lyra2z330_height;
    void lyra2z330_hash(const char* input, char* output, uint32_t len)
    {
    uint32_t _ALIGN(64) hash[8];
    LYRA2z((void*)hash, 32, (void*)input, len, (void*)input, len, 2, 330, 256);
    memcpy(output, hash, 32);
    }
    New Code

    Code:
    #include <memory.h>
    #include "algo-gate-api.h"
    #include "Lyra2.h"
    #include "avxdefs.h"
    __thread uint64_t* lyra2z330_wholeMatrix;
    void lyra2z330_hash(void *state, const void *input, uint32_t height)
    {
    uint32_t _ALIGN(256) hash[16];
    LYRA2Z( lyra2z330_wholeMatrix, hash, 32, input, 80, input, 80,
    2, 330, 256 );
    memcpy(state, hash, 32);
    }
    bool lyra2z330_thread_init()
    {
    const int64_t ROW_LEN_INT64 = BLOCK_LEN_INT64 * 256; // nCols
    const int64_t ROW_LEN_BYTES = ROW_LEN_INT64 * 8;
    int i = (int64_t)ROW_LEN_BYTES * 330; // nRows;
    lyra2z330_wholeMatrix = _mm_malloc( i, 64 );
    return lyra2z330_wholeMatrix;
    }
    So my main problem is that i need to have the lyra2z330_hash Function in the format of the original code, but i cannot find a way to successfully convert the new function to match the previous one format, AKA convert the void and const void to char const char, any help will be appreciated, thanks

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    Is LYRA2Z supposed to be the same as LYRA2z ? If so, you don't even have the same number of parameters.

    And it looks like the state and input parameters of lyra2z330_hash are in the wrong order compared to the original code.

    Maybe you are supposed to pass the matrix when you call the function like this:
    Code:
    lyra2z330_hash((char*)lyra2z330_wholeMatrix, state, height);
    And maybe the function should be something like this:
    Code:
    void lyra2z330_hash(const char *input, char *state, uint32_t height) {
      uint32_t _ALIGN(256) hash[16];
      LYRA2Z((void*)hash, 32, (void*)input, 80, (void*)input,  80, 2, 330, 256);
      memcpy(state, hash, 32);
    }
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Jun 2018
    Posts
    5
    Quote Originally Posted by john.c View Post
    Is LYRA2Z supposed to be the same as LYRA2z ? If so, you don't even have the same number of parameters.

    And it looks like the state and input parameters of lyra2z330_hash are in the wrong order compared to the original code.

    Maybe you are supposed to pass the matrix when you call the function like this:
    Code:
    lyra2z330_hash((char*)lyra2z330_wholeMatrix, state, height);
    And maybe the function should be something like this:
    Code:
    void lyra2z330_hash(const char *input, char *state, uint32_t height) {
      uint32_t _ALIGN(256) hash[16];
      LYRA2Z((void*)hash, 32, (void*)input, 80, (void*)input,  80, 2, 330, 256);
      memcpy(state, hash, 32);
    }
    Hello John and thank you for your help, I did change the Lyra2.h file so LYRA2Z is calculated as the miner program does, also tried to use (void*) before each parameter and did change the order of the parameters to match the original code, none of these changes worked, when i posted the code i copied and pasted each code from their original corresponding sources assuming that in the way i did something wrong, and i didn't want to corrupt the initial code, i will make those changes, compile and post the results, Thaks

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    Reading code in a table is way too much of a headache for me.

    Perhaps you could post it so it looks like John's code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jun 2018
    Posts
    5

    New compil

    Hello Salem, i can't find a way to post as John did, i will post on the table this time and figure it out on my next post how to do it, sorry for that...

    So this is my new lyra2z330.c file folowing John's advises
    Code:
    #include <stdlib.h>
    #include <stdint.h>
    #include <string.h>
    #include <stdio.h>
    #include <stdbool.h>
    #include "Lyra2.h"
    #define _ALIGN(x) __attribute__ ((aligned(x)))
    __thread uint64_t* lyra2z330_wholeMatrix;
    void lyra2z330_hash(const char *input, char *state, uint32_t height)
    {
    uint32_t _ALIGN(256) hash[16];
    LYRA2Z((void*)hash, 32, (void*)input, 80, (void*)input, 80, 2, 330, 256);
    memcpy(state, hash, 32);
    memcpy(state, hash, 32);
    }
    bool lyra2z330_thread_init()
    {
    const int64_t ROW_LEN_INT64 = BLOCK_LEN_INT64 * 256; // nCols
    const int64_t ROW_LEN_BYTES = ROW_LEN_INT64 * 8;
    int i = (int64_t)ROW_LEN_BYTES * 330; // nRows;
    lyra2z330_wholeMatrix = _mm_malloc( i, 64 );
    return lyra2z330_wholeMatrix;
    }
    This is the error i get when compiling

    Code:
    lyra2z330.c: In function ‘lyra2z330_hash’:
    lyra2z330.c:16:29: warning: passing argument 2 of ‘LYRA2Z’ makes pointer from integer without a cast [-Wint-conversion]
             LYRA2Z((void*)hash, 32, (void*)input, 80, (void*)input,  80, 2, 330, 256);
                                 ^
    In file included from lyra2z330.c:6:0:
    Lyra2.h:53:5: note: expected ‘void *’ but argument is of type ‘int’
     int LYRA2Z( uint64_t*, void *K, uint64_t kLen, const void *pwd,
         ^
    lyra2z330.c:16:33: warning: passing argument 3 of ‘LYRA2Z’ makes integer from pointer without a cast [-Wint-conversion]
             LYRA2Z((void*)hash, 32, (void*)input, 80, (void*)input,  80, 2, 330, 256);
                                     ^
    In file included from lyra2z330.c:6:0:
    Lyra2.h:53:5: note: expected ‘uint64_t {aka long unsigned int}’ but argument is of type ‘void *’
     int LYRA2Z( uint64_t*, void *K, uint64_t kLen, const void *pwd,
         ^
    lyra2z330.c:16:47: warning: passing argument 4 of ‘LYRA2Z’ makes pointer from integer without a cast [-Wint-conversion]
             LYRA2Z((void*)hash, 32, (void*)input, 80, (void*)input,  80, 2, 330, 256);
                                                   ^
    In file included from lyra2z330.c:6:0:
    Lyra2.h:53:5: note: expected ‘const void *’ but argument is of type ‘int’
     int LYRA2Z( uint64_t*, void *K, uint64_t kLen, const void *pwd,
         ^
    lyra2z330.c:16:51: warning: passing argument 5 of ‘LYRA2Z’ makes integer from pointer without a cast [-Wint-conversion]
             LYRA2Z((void*)hash, 32, (void*)input, 80, (void*)input,  80, 2, 330, 256);
                                                       ^
    In file included from lyra2z330.c:6:0:
    Lyra2.h:53:5: note: expected ‘uint64_t {aka long unsigned int}’ but argument is of type ‘void *’
     int LYRA2Z( uint64_t*, void *K, uint64_t kLen, const void *pwd,
         ^
    lyra2z330.c:16:66: warning: passing argument 6 of ‘LYRA2Z’ makes pointer from integer without a cast [-Wint-conversion]
             LYRA2Z((void*)hash, 32, (void*)input, 80, (void*)input,  80, 2, 330, 256);
                                                                      ^
    In file included from lyra2z330.c:6:0:
    Lyra2.h:53:5: note: expected ‘const void *’ but argument is of type ‘int’
     int LYRA2Z( uint64_t*, void *K, uint64_t kLen, const void *pwd,
         ^
    lyra2z330.c:16:9: error: too few arguments to function ‘LYRA2Z’
             LYRA2Z((void*)hash, 32, (void*)input, 80, (void*)input,  80, 2, 330, 256);
             ^
    In file included from lyra2z330.c:6:0:
    Lyra2.h:53:5: note: declared here
     int LYRA2Z( uint64_t*, void *K, uint64_t kLen, const void *pwd,
         ^
    makefile:36: recipe for target 'lyra2z330.o' failed
    make[1]: *** [lyra2z330.o] Error 1
    make[1]: Leaving directory '/home/pool/yiimp/stratum/algos'
    Makefile:38: recipe for target 'projectcode1' failed
    make: *** [projectcode1] Error 2
    cp: cannot stat 'stratum': No such file or directory


    and this is my lyra2z.h file, where LYRA2Z is declared

    Code:
    #ifndef LYRA2_H_
    #define LYRA2_H_
    #include <stdint.h>
    #include "sha3-defs.h"
    //typedef unsigned char byte;
    //Block length required so Blake2's Initialization Vector (IV) is not overwritten (THIS SHOULD NOT BE MODIFIED)
    #define BLOCK_LEN_BLAKE2_SAFE_INT64 8 //512 bits (=64 bytes, =8 uint64_t)
    #define BLOCK_LEN_BLAKE2_SAFE_BYTES (BLOCK_LEN_BLAKE2_SAFE_INT64 * 8) //same as above, in bytes
    #ifdef BLOCK_LEN_BITS
    #define BLOCK_LEN_INT64 (BLOCK_LEN_BITS/64) //Block length: 768 bits (=96 bytes, =12 uint64_t)
    #define BLOCK_LEN_BYTES (BLOCK_LEN_BITS/8) //Block length, in bytes
    #else //default block lenght: 768 bits
    #define BLOCK_LEN_INT64 12 //Block length: 768 bits (=96 bytes, =12 uint64_t)
    #define BLOCK_LEN_BYTES (BLOCK_LEN_INT64 * 8) //Block length, in bytes
    #endif
    #define BLOCK_LEN_M256I (BLOCK_LEN_INT64 / 4 )
    #define BLOCK_LEN_M128I (BLOCK_LEN_INT64 / 2 )
    int LYRA2RE( void *K, uint64_t kLen, const void *pwd,
    uint64_t pwdlen, const void *salt, uint64_t saltlen,
    uint64_t timeCost, uint64_t nRows, uint64_t nCols );
    int LYRA2REV2( uint64_t*, void *K, uint64_t kLen, const void *pwd,
    uint64_t pwdlen, const void *salt, uint64_t saltlen,
    uint64_t timeCost, uint64_t nRows, uint64_t nCols );
    int LYRA2Z( uint64_t*, void *K, uint64_t kLen, const void *pwd,
    uint64_t pwdlen, const void *salt, uint64_t saltlen,
    uint64_t timeCost, uint64_t nRows, uint64_t nCols );
    int LYRA2(void *K, int64_t kLen, const void *pwd, int32_t pwdlen, const void *salt, int32_t saltlen, int64_t timeCost, const int16_t nRows, const int16_t nCols);
    #endif /* LYRA2_H_ */

  6. #6
    Guest
    Guest
    Surandino, paste your code between [code][/code] tags, and make sure formatting doesn't carry over from your editor. It should be plain text.

  7. #7
    Registered User
    Join Date
    Jun 2018
    Posts
    5
    Code:
    #include <stdlib.h>
    #include <stdint.h>
    #include <string.h>
    #include <stdio.h>
    #include <stdbool.h>
    #include "Lyra2.h"
    
    #define _ALIGN(x) __attribute__ ((aligned(x)))
    
    __thread uint64_t* lyra2z330_wholeMatrix;
    
    void lyra2z330_hash(const char *input, char *state, uint32_t height)
    {
        uint32_t _ALIGN(256) hash[16];
    
            LYRA2Z( lyra2z330_wholeMatrix, (void*)hash, 32, (void*)input, 80, (void*)input, 80,
                     2, 330, 256 );
    
        memcpy(state, hash, 32);
    }
    
    bool lyra2z330_thread_init()
    {
       const int64_t ROW_LEN_INT64 = BLOCK_LEN_INT64 * 256; // nCols
       const int64_t ROW_LEN_BYTES = ROW_LEN_INT64 * 8;
       int i = (int64_t)ROW_LEN_BYTES * 330; // nRows;
       lyra2z330_wholeMatrix = _mm_malloc( i, 64 );
       return lyra2z330_wholeMatrix;
    }
    Ok this code compiled ok, but i think i have a logical error because my miner client send a result and the stratum rejects it and closes

  8. #8
    Registered User
    Join Date
    Jun 2018
    Posts
    5
    thanks Adrian, pasting plain text worked... cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. string conversion strtol function
    By lmanukyan in forum C Programming
    Replies: 1
    Last Post: 01-28-2016, 12:42 PM
  2. Currency Conversion - Function Problems
    By annleft in forum C Programming
    Replies: 3
    Last Post: 11-03-2013, 06:44 PM
  3. Replies: 8
    Last Post: 12-16-2012, 06:48 PM
  4. Library Conversion (Static .lib -> function)
    By jmsold2 in forum C++ Programming
    Replies: 5
    Last Post: 10-05-2006, 06:07 PM
  5. Replies: 2
    Last Post: 02-07-2002, 09:39 AM

Tags for this Thread