├── .sonarcloud.properties ├── header.png ├── scripts ├── systemd │ ├── xcash-dpops.timer │ ├── xcash-rpc-wallet.timer │ ├── firewall.service │ ├── xcash-dpops.service │ ├── xcash-rpc-wallet.service │ ├── MongoDB.service │ ├── xcash-dpops-shared-delegate.service │ └── xcash-daemon.service ├── virtual_machines │ └── shutdown_script.sh ├── build │ ├── script.sh │ └── build_script_static.sh └── firewall │ ├── firewall_script_xcash_node.sh │ ├── firewall_script.sh │ └── firewall_shared_delegates_script.sh ├── src ├── functions │ ├── database_functions │ │ ├── cached_hashes.h │ │ ├── count_database_functions │ │ │ ├── count_database_functions.h │ │ │ └── count_database_functions.c │ │ ├── delete_database_functions │ │ │ ├── delete_database_functions.h │ │ │ └── delete_database_functions.c │ │ ├── insert_database_functions │ │ │ └── insert_database_functions.h │ │ ├── database_functions.h │ │ ├── update_database_functions │ │ │ └── update_database_functions.h │ │ ├── read_database_functions │ │ │ └── read_database_functions.h │ │ └── md5.h │ ├── file_functions │ │ ├── file_functions.h │ │ └── file_functions.c │ ├── network_functions │ │ ├── network_security_functions │ │ │ └── network_security_functions.h │ │ ├── network_wallet_functions │ │ │ └── network_wallet_functions.h │ │ ├── network_daemon_functions │ │ │ └── network_daemon_functions.h │ │ └── network_functions.h │ ├── organize_functions │ │ └── organize_functions.h │ ├── VRF_functions │ │ ├── VRF_functions.h │ │ ├── crypto_verify_16.h │ │ ├── fe_25_5 │ │ │ ├── constants.h │ │ │ └── base2.h │ │ ├── crypto_verify.c │ │ ├── convert.h │ │ ├── sha512EL.h │ │ ├── randombytes.h │ │ ├── keypair.c │ │ ├── crypto_vrf.h │ │ ├── vrf.h │ │ ├── crypto_vrf.c │ │ ├── randombytes.c │ │ ├── ed25519_ref10.h │ │ ├── convert.c │ │ └── prove.c │ ├── server_functions │ │ ├── server_functions.h │ │ └── delegate_server_functions │ │ │ └── delegate_server_functions.h │ ├── block_verifiers_functions │ │ ├── block_verifiers_update_functions │ │ │ └── block_verifiers_update_functions.h │ │ ├── block_verifiers_synchronize_functions │ │ │ ├── block_verifiers_synchronize_check_functions │ │ │ │ └── block_verifiers_synchronize_check_functions.h │ │ │ ├── block_verifiers_synchronize_functions.h │ │ │ └── block_verifiers_synchronize_server_functions │ │ │ │ └── block_verifiers_synchronize_server_functions.h │ │ ├── block_verifiers_server_functions │ │ │ └── block_verifiers_server_functions.h │ │ ├── block_verifiers_functions.h │ │ └── block_verifiers_thread_server_functions │ │ │ └── block_verifiers_thread_server_functions.h │ ├── shared_delegates_website_functions │ │ ├── shared_delegates_website_functions.h │ │ └── shared_delegate_website_thread_server_functions │ │ │ └── shared_delegate_website_thread_server_functions.h │ ├── delegates_website_functions │ │ └── delegates_website_functions.h │ ├── string_functions │ │ └── string_functions.h │ └── thread_functions │ │ └── thread_functions.h ├── tests │ ├── XCASH_DPOPS_test.h │ ├── VRF_functions_test │ │ └── VRF_functions_test.h │ ├── file_functions_test │ │ ├── file_functions_test.h │ │ └── file_functions_test.c │ ├── database_functions_test │ │ ├── database_functions_test.h │ │ ├── read_database_functions_test │ │ │ └── read_database_functions_test.h │ │ ├── count_database_functions_test │ │ │ ├── count_database_functions_test.h │ │ │ └── count_database_functions_test.c │ │ ├── delete_database_functions_test │ │ │ ├── delete_database_functions_test.h │ │ │ └── delete_database_functions_test.c │ │ ├── insert_database_functions_test │ │ │ ├── insert_database_functions_test.h │ │ │ └── insert_database_functions_test.c │ │ └── update_database_functions_test │ │ │ └── update_database_functions_test.h │ ├── string_functions_test │ │ └── string_functions_test.h │ ├── organize_functions_test │ │ └── organize_functions_test.h │ ├── blockchain_functions_test │ │ └── blockchain_functions_test.h │ ├── optimizations_functions_test │ │ └── optimizations_functions_test.h │ ├── delegate_website_functions_test │ │ └── delegate_website_functions_test.h │ ├── network_functions_test │ │ ├── network_daemon_functions_test │ │ │ ├── network_daemon_functions_test.h │ │ │ └── network_daemon_functions_test.c │ │ ├── network_wallet_functions_test │ │ │ ├── network_wallet_functions_test.h │ │ │ └── network_wallet_functions_test.c │ │ ├── network_functions_test.h │ │ └── network_security_functions_test │ │ │ └── network_security_functions_test.h │ ├── server_functions_test │ │ └── delegate_server_functions_test │ │ │ └── delegate_server_functions_test.h │ ├── shared_delegate_website_functions_test │ │ ├── shared_delegate_website_functions_test.h │ │ └── shared_delegate_website_thread_server_functions_test │ │ │ └── shared_delegate_website_thread_server_functions_test.h │ ├── block_verifiers_functions_test │ │ ├── block_verifiers_update_functions │ │ │ └── block_verifiers_update_functions_test.h │ │ ├── block_verifiers_server_functions_test │ │ │ ├── block_verifiers_server_functions_test.h │ │ │ └── block_verifiers_server_functions_test.c │ │ ├── block_verifiers_synchronize_functions_test │ │ │ ├── block_verifiers_synchronize_functions_test.h │ │ │ ├── block_verifiers_synchronize_check_functions_test │ │ │ │ ├── block_verifiers_synchronize_check_functions_test.h │ │ │ │ └── block_verifiers_synchronize_check_functions_test.c │ │ │ ├── block_verifiers_synchronize_server_functions_test │ │ │ │ └── block_verifiers_synchronize_server_functions_test.h │ │ │ └── block_verifiers_synchronize_functions_test.c │ │ └── block_verifiers_thread_server_functions_test │ │ │ └── block_verifiers_thread_server_functions_test.h │ ├── global_data │ │ └── variables_test.h │ └── reset_variables_allocated_on_the_heap_test │ │ └── reset_variables_allocated_on_the_heap_test.h └── XCASH_DPOPS.h ├── LICENSE ├── .vscode ├── launch.json ├── tasks.json └── settings.json ├── VRF_LICENSE ├── Makefile └── README.md /.sonarcloud.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/HEAD/header.png -------------------------------------------------------------------------------- /scripts/systemd/xcash-dpops.timer: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=xcash-dpops timer 3 | 4 | [Timer] 5 | OnBootSec=30sec 6 | 7 | [Install] 8 | WantedBy=timers.target 9 | 10 | -------------------------------------------------------------------------------- /scripts/systemd/xcash-rpc-wallet.timer: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=xcash-rpc-wallet timer 3 | 4 | [Timer] 5 | OnBootSec=20sec 6 | 7 | [Install] 8 | WantedBy=timers.target 9 | 10 | -------------------------------------------------------------------------------- /scripts/systemd/firewall.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=firewall 3 | Before=network-pre.target 4 | Wants=network-pre.target 5 | 6 | [Service] 7 | Type=oneshot 8 | RemainAfterExit=yes 9 | User=root 10 | ExecStart=${HOME}/firewall_script.sh 11 | 12 | [Install] 13 | WantedBy=network.target -------------------------------------------------------------------------------- /src/functions/database_functions/cached_hashes.h: -------------------------------------------------------------------------------- 1 | #ifndef CACHED_HASHES_H_ 2 | #define CACHED_HASHES_H_ 3 | 4 | int get_multi_hash(mongoc_client_t *client, const char *db_prefix, char *hash); 5 | int del_hash(mongoc_client_t *client, const char *db_name); 6 | int drop_all_hashes(mongoc_client_t *client); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/tests/XCASH_DPOPS_test.h: -------------------------------------------------------------------------------- 1 | #ifndef XCASH_PROOF_OF_STAKE_TEST_H_ /* Include guard */ 2 | #define XCASH_PROOF_OF_STAKE_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | void test(int settings); 11 | #endif -------------------------------------------------------------------------------- /src/tests/VRF_functions_test/VRF_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef VRF_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define VRF_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int VRF_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/file_functions_test/file_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define FILE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int file_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/database_functions_test/database_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef DATABASE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define DATABASE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int database_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/string_functions_test/string_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define STRING_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int string_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/organize_functions_test/organize_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef ORGANIZE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define ORGANIZE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int organize_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/blockchain_functions_test/blockchain_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCKCHAIN_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define BLOCKCHAIN_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int blockchain_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/optimizations_functions_test/optimizations_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef OPTIMIZATIONS_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define OPTIMIZATIONS_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int optimizations_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /scripts/virtual_machines/shutdown_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | curl -X POST http://127.0.0.1:18281/stop_daemon -H 'Content-Type: application/json' 4 | sleep 20s 5 | curl -X POST http://127.0.0.1:18285/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"stop_wallet"}' -H 'Content-Type: application/json' 6 | sleep 20s 7 | pkill -f mongod 8 | pkill -f mongo 9 | pkill -f xcash-wallet-rpc 10 | pkill -f xcashd 11 | pkill -f "/usr/share/code/code --user-data-dir /root/xcash-official/vscode/" 12 | shutdown now -------------------------------------------------------------------------------- /src/tests/delegate_website_functions_test/delegate_website_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef DELEGATE_WEBSITE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define DELEGATE_WEBSITE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int delegate_website_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/database_functions_test/read_database_functions_test/read_database_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef READ_DATABASE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define READ_DATABASE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int read_database_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/database_functions_test/count_database_functions_test/count_database_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef COUNT_DATABASE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define COUNT_DATABASE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int count_database_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/network_functions_test/network_daemon_functions_test/network_daemon_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_DAEMON_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define NETWORK_DAEMON_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int network_daemon_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/network_functions_test/network_wallet_functions_test/network_wallet_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_WALLET_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define NETWORK_WALLET_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int network_wallet_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/database_functions_test/delete_database_functions_test/delete_database_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef DELETE_DATABASE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define DELETE_DATABASE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int delete_database_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/database_functions_test/insert_database_functions_test/insert_database_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef INSERT_DATABASE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define INSERT_DATABASE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int insert_database_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/database_functions_test/update_database_functions_test/update_database_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef UPDATE_DATABASE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define UPDATE_DATABASE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int update_database_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/network_functions_test/network_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define NETWORK_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | void* create_server_on_separate_thread(void* parameters); 11 | int network_functions_test(void); 12 | #endif -------------------------------------------------------------------------------- /src/tests/server_functions_test/delegate_server_functions_test/delegate_server_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef DELEGATE_SERVER_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define DELEGATE_SERVER_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int delegate_server_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /scripts/systemd/xcash-dpops.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=X-Cash DPOPS Program background process 3 | After=network.target xcash-daemon.service xcash-rpc-wallet.service mongodb.service 4 | StartLimitIntervalSec=0 5 | 6 | [Service] 7 | Type=simple 8 | LimitNOFILE=infinity 9 | User=${USER} 10 | WorkingDirectory=${XCASH_DPOPS_DIR}build 11 | ExecStart=${XCASH_DPOPS_DIR}build/xcash-dpops --block-verifiers-secret-key ${BLOCK_VERIFIER_SECRET_KEY} 12 | Restart=always 13 | RestartSec=5 14 | 15 | [Install] 16 | WantedBy=multi-user.target 17 | -------------------------------------------------------------------------------- /src/tests/network_functions_test/network_security_functions_test/network_security_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_SECURITY_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define NETWORK_SECURITY_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int network_security_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/shared_delegate_website_functions_test/shared_delegate_website_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef SHARED_DELEGATE_WEBSITE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define SHARED_DELEGATE_WEBSITE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int shared_delegate_website_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/block_verifiers_functions_test/block_verifiers_update_functions/block_verifiers_update_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_UPDATE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_UPDATE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int block_verifiers_update_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/block_verifiers_functions_test/block_verifiers_server_functions_test/block_verifiers_server_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_SERVER_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_SERVER_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int block_verifiers_server_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /scripts/systemd/xcash-rpc-wallet.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=X-Cash RPC wallet background process 3 | After=network.target xcash-daemon.service 4 | 5 | [Service] 6 | Type=simple 7 | User=${USER} 8 | ExecStart=${XCASH_DIR}build/release/bin/xcash-wallet-rpc --wallet-file ${XCASH_WALLET_DIR}delegate-wallet --password ${WALLET_PASSWORD} --rpc-bind-port 18285 --confirm-external-bind --daemon-port 18281 --disable-rpc-login --trusted-daemon --log-file ${XCASH_LOGS_DIR}xcash-wallet-rpc.log 9 | Restart=always 10 | RestartSec=5 11 | 12 | [Install] 13 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /src/tests/global_data/variables_test.h: -------------------------------------------------------------------------------- 1 | #ifndef VARAIBLES_TEST_H_ /* Include guard */ 2 | #define VARAIBLES_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Global variables 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | extern char string1_test[BUFFER_SIZE]; 11 | extern char string2_test[BUFFER_SIZE]; 12 | extern char result_test[BUFFER_SIZE]; 13 | extern char data_test[BUFFER_SIZE]; 14 | extern int count_test; 15 | #endif -------------------------------------------------------------------------------- /src/tests/block_verifiers_functions_test/block_verifiers_synchronize_functions_test/block_verifiers_synchronize_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_SYNCHRONIZE_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_SYNCHRONIZE_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int block_verifiers_synchronize_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /scripts/systemd/MongoDB.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=MongoDB X-Cash Database Server 3 | After=network.target 4 | 5 | [Service] 6 | Type=forking 7 | User=${USER} 8 | Type=oneshot 9 | RemainAfterExit=yes 10 | PIDFile=${XCASH_DPOPS_INSTALLATION_DIR}systemdpid/mongod.pid 11 | ExecStart=${MONGODB_DIR}bin/mongod --fork --syslog --dbpath ${MONGODB_INSTALLATION_DIR} 12 | 13 | LimitFSIZE=infinity 14 | LimitCPU=infinity 15 | LimitAS=infinity 16 | LimitNOFILE=64000 17 | LimitNPROC=64000 18 | LimitMEMLOCK=infinity 19 | TasksMax=infinity 20 | TasksAccounting=false 21 | 22 | [Install] 23 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /scripts/systemd/xcash-dpops-shared-delegate.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=X-Cash DPOPS Program background process 3 | After=network.target xcash-daemon.service xcash-rpc-wallet.service mongodb.service 4 | 5 | [Service] 6 | Type=simple 7 | LimitNOFILE=infinity 8 | User=${USER} 9 | WorkingDirectory=${XCASH_DPOPS_DIR}build 10 | ExecStart=${XCASH_DPOPS_DIR}build/xcash-dpops --block-verifiers-secret-key ${BLOCK_VERIFIER_SECRET_KEY} --shared-delegates-website --fee ${DPOPS_FEE} --minimum-amount ${DPOPS_MINIMUM_AMOUNT} 11 | Restart=always 12 | RestartSec=5 13 | 14 | [Install] 15 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /src/tests/block_verifiers_functions_test/block_verifiers_thread_server_functions_test/block_verifiers_thread_server_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_THREAD_SERVER_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_THREAD_SERVER_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int block_verifiers_thread_server_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/reset_variables_allocated_on_the_heap_test/reset_variables_allocated_on_the_heap_test.h: -------------------------------------------------------------------------------- 1 | #ifndef RESET_VARAIBLES_ALLOCATED_ON_THE_HEAP_TEST_H_ /* Include guard */ 2 | #define RESET_VARAIBLES_ALLOCATED_ON_THE_HEAP_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | size_t get_program_memory_usage(const char* PROCESS_ID_FILE); 11 | int reset_variables_allocated_on_the_heap_test(void); 12 | #endif -------------------------------------------------------------------------------- /src/functions/file_functions/file_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_FUNCTIONS_H_ /* Include guard */ 2 | #define FILE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | long get_file_size(const char* FILE_NAME); 11 | long read_file(unsigned char *result, const char* FILE_NAME); 12 | int write_file(const char* DATA, const char* FILE_NAME); 13 | int append_file(const char* DATA, const char* FILE_NAME); 14 | #endif -------------------------------------------------------------------------------- /src/functions/network_functions/network_security_functions/network_security_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_SECURITY_FUNCTIONS_H_ /* Include guard */ 2 | #define NETWORK_SECURITY_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int sign_data(char *message); 11 | int validate_data(const char* MESSAGE); 12 | int verify_data(const char* MESSAGE, const int VERIFY_CURRENT_ROUND_PART_BACKUP_NODE_SETTINGS); 13 | #endif -------------------------------------------------------------------------------- /src/functions/database_functions/count_database_functions/count_database_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef COUNT_DATABASE_FUNCTIONS_H_ /* Include guard */ 2 | #define COUNT_DATABASE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int count_documents_in_collection(const char* DATABASE, const char* COLLECTION, const char* DATA); 11 | int count_all_documents_in_collection(const char* DATABASE, const char* COLLECTION); 12 | #endif -------------------------------------------------------------------------------- /src/functions/organize_functions/organize_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef ORGANIZE_FUNCTIONS_H_ /* Include guard */ 2 | #define ORGANIZE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int organize_invalid_reserve_proofs_settings(const void* STRING1, const void* STRING2); 11 | int organize_delegates_settings(const void* DELEGATES1, const void* DELEGATES2); 12 | int organize_delegates(struct delegates* delegates); 13 | #endif -------------------------------------------------------------------------------- /src/tests/shared_delegate_website_functions_test/shared_delegate_website_thread_server_functions_test/shared_delegate_website_thread_server_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef SHARED_DELEGATE_WEBSITE_THREAD_SERVER_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define SHARED_DELEGATE_WEBSITE_THREAD_SERVER_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int shared_delegate_website_thread_server_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /scripts/systemd/xcash-daemon.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=X-Cash Daemon background process 3 | After=network.target 4 | 5 | [Service] 6 | Type=forking 7 | User=${USER} 8 | PIDFile=${XCASH_DPOPS_INSTALLATION_DIR}systemdpid/xcash-daemon.pid 9 | ExecStart=${XCASH_DIR}build/release/bin/xcashd --data-dir ${XCASH_BLOCKCHAIN_INSTALLATION_DIR} --rpc-bind-ip 0.0.0.0 --p2p-bind-ip 0.0.0.0 --rpc-bind-port 18281 --restricted-rpc --confirm-external-bind --log-file ${XCASH_LOGS_DIR}xcash-daemon-log.txt --max-log-file-size 0 --detach --pidfile ${XCASH_SYSTEMPID_DIR}xcash-daemon.pid 10 | RuntimeMaxSec=15d 11 | Restart=always 12 | 13 | [Install] 14 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /src/tests/block_verifiers_functions_test/block_verifiers_synchronize_functions_test/block_verifiers_synchronize_check_functions_test/block_verifiers_synchronize_check_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_SYNCHRONIZE_CHECK_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_SYNCHRONIZE_CHECK_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int block_verifiers_synchronize_check_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/tests/block_verifiers_functions_test/block_verifiers_synchronize_functions_test/block_verifiers_synchronize_server_functions_test/block_verifiers_synchronize_server_functions_test.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_SYNCHRONIZE_SERVER_FUNCTIONS_TEST_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_SYNCHRONIZE_SERVER_FUNCTIONS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int block_verifiers_synchronize_server_functions_test(void); 11 | #endif -------------------------------------------------------------------------------- /src/functions/database_functions/delete_database_functions/delete_database_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef DELETE_DATABASE_FUNCTIONS_H_ /* Include guard */ 2 | #define DELETE_DATABASE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int delete_document_from_collection(const char* DATABASE, const char* COLLECTION, const char* DATA); 11 | int delete_collection_from_database(const char* DATABASE, const char* COLLECTION); 12 | int delete_database(const char* DATABASE); 13 | #endif -------------------------------------------------------------------------------- /src/functions/database_functions/insert_database_functions/insert_database_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef INSERT_DATABASE_FUNCTIONS_H_ /* Include guard */ 2 | #define INSERT_DATABASE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int insert_document_into_collection_json(const char* DATABASE, const char* COLLECTION, const char* DATA); 11 | int insert_multiple_documents_into_collection_json(const char* DATABASE, const char* COLLECTION, const char* DATA, const size_t DATA_TOTAL_LENGTH); 12 | #endif -------------------------------------------------------------------------------- /src/functions/network_functions/network_wallet_functions/network_wallet_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_WALLET_FUNCTIONS_H_ /* Include guard */ 2 | #define NETWORK_WALLET_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int get_public_address(void); 11 | long long int get_total_amount(void); 12 | int send_payment(const char* DATA, char *tx_hash, char *tx_key, const int SETTINGS); 13 | int check_reserve_proofs(char *result, const char* public_address, const char* reserve_proof); 14 | #endif -------------------------------------------------------------------------------- /src/XCASH_DPOPS.h: -------------------------------------------------------------------------------- 1 | #ifndef XCASH_DPOPS_TEST_H_ /* Include guard */ 2 | #define XCASH_DPOPS_TEST_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | void initialize_data(int parameters_count, char* parameters[]); 11 | void create_overall_database_connection(void); 12 | void get_delegates_data(void); 13 | int set_parameters(int parameters_count, char* parameters[]); 14 | void print_settings(void); 15 | void database_sync_check(void); 16 | void start_timer_threads(void); 17 | int main(int parameters_count, char* parameters[]); 18 | #endif -------------------------------------------------------------------------------- /src/functions/VRF_functions/VRF_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef VRF_FUNCTIONS_H_ /* Include guard */ 2 | #define VRF_FUNCTIONS_H_ 3 | 4 | 5 | /* 6 | ----------------------------------------------------------------------------------------------------------- 7 | Function prototypes 8 | ----------------------------------------------------------------------------------------------------------- 9 | */ 10 | 11 | int create_random_VRF_keys(unsigned char *public_key, unsigned char *secret_key); 12 | void generate_key(void); 13 | int sign_network_block_string(char *data, const char* MESSAGE); 14 | int VRF_sign_data(char *beta_string, char *proof, const char* data); 15 | int VRF_data_verify(const char* BLOCK_VERIFIERS_PUBLIC_KEY, const char* BLOCK_VERIFIERS_DATA_SIGNATURE, const char* DATA); 16 | #endif -------------------------------------------------------------------------------- /src/functions/database_functions/database_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef DATABASE_FUNCTIONS_H_ /* Include guard */ 2 | #define DATABASE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int check_if_database_collection_exist(const char* DATABASE, const char* COLLECTION); 11 | int get_database_data(char *database_data, const char* DATABASE, const char* COLLECTION); 12 | int get_database_data_hash(char *data_hash, const char* DATABASE, const char* COLLECTION); 13 | size_t get_database_collection_size(const char* DATABASE, const char* COLLECTION); 14 | void reserve_proofs_delegate_check(void); 15 | #endif -------------------------------------------------------------------------------- /src/functions/server_functions/server_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef SERVER_FUNCTIONS_H_ /* Include guard */ 2 | #define SERVER_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int create_server(const int MESSAGE_SETTINGS); 11 | void new_socket_thread(void); 12 | int server_limit_IP_addresses(const int SETTINGS, const char* IP_ADDRESS); 13 | int server_limit_public_addresses(const int SETTINGS, const char* MESSAGE); 14 | void socket_thread(const int CLIENT_SOCKET); 15 | void* socket_receive_data_thread(void* parameters); 16 | int server_receive_data_socket_get_files(const int CLIENT_SOCKET, const char* MESSAGE); 17 | #endif -------------------------------------------------------------------------------- /src/functions/database_functions/update_database_functions/update_database_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef UPDATE_DATABASE_FUNCTIONS_H_ /* Include guard */ 2 | #define UPDATE_DATABASE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int update_document_from_collection(const char* DATABASE, const char* COLLECTION, const char* DATA, const char* FIELD_NAME_AND_DATA); 11 | int update_multiple_documents_from_collection(const char* DATABASE, const char* COLLECTION, const char* DATA, const char* FIELD_NAME_AND_DATA); 12 | int update_all_documents_from_collection(const char* DATABASE, const char* COLLECTION, const char* DATA); 13 | #endif 14 | -------------------------------------------------------------------------------- /src/functions/network_functions/network_daemon_functions/network_daemon_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_DAEMON_FUNCTIONS_H_ /* Include guard */ 2 | #define NETWORK_DAEMON_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int check_if_blockchain_is_fully_synced(void); 11 | int get_current_block_height_network_data_nodes(void); 12 | int get_block_template(char *result); 13 | int submit_block_template(const char* DATA); 14 | int get_block_reserve_byte_data_hash(char *reserve_byte_data_hash, const char* BLOCK_HEIGHT); 15 | int get_current_block_height(char *result); 16 | int get_previous_block_hash(char *result); 17 | int get_previous_block_information(char *block_hash, char *block_reward, char *block_date_and_time); 18 | #endif -------------------------------------------------------------------------------- /src/functions/block_verifiers_functions/block_verifiers_update_functions/block_verifiers_update_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_UPDATE_FUNCTIONS_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_UPDATE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int get_block_verifiers_from_network_block(const int TOTAL_DELEGATES, const struct delegates* delegates, const size_t CURRENT_BLOCK_HEIGHT, const int SETTINGS); 11 | int update_block_verifiers_list(void); 12 | int update_databases(void); 13 | int add_block_verifiers_round_statistics(const char* BLOCK_HEIGHT); 14 | int add_round_statistics(void); 15 | int calculate_main_nodes_roles(void); 16 | void check_for_updates(void); 17 | int get_delegates_online_status(void); 18 | #endif -------------------------------------------------------------------------------- /src/functions/shared_delegates_website_functions/shared_delegates_website_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef SHARED_DELEGATES_WEBSITE_FUNCTIONS_H_ /* Include guard */ 2 | #define SHARED_DELEGATES_WEBSITE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int check_for_valid_start_and_amount_parameters(const char* START, const char* AMOUNT); 11 | int server_receive_data_socket_shared_delegates_website_get_statistics(const int CLIENT_SOCKET); 12 | int server_receive_data_socket_get_blocks_found(const int CLIENT_SOCKET,const char* DATA); 13 | int server_receive_data_socket_get_public_address_information(const int CLIENT_SOCKET, const char* DATA); 14 | int server_receive_data_socket_get_public_address_payment_information(const int CLIENT_SOCKET, const char* DATA); 15 | #endif 16 | -------------------------------------------------------------------------------- /src/functions/delegates_website_functions/delegates_website_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef DELEGATES_WEBSITE_FUNCTIONS_H_ /* Include guard */ 2 | #define DELEGATES_WEBSITE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int server_receive_data_socket_delegates_website_get_statistics(const int CLIENT_SOCKET); 11 | int server_receive_data_socket_get_delegates(const int CLIENT_SOCKET); 12 | int server_receive_data_socket_get_delegates_statistics(const int CLIENT_SOCKET, const char* DATA); 13 | int server_receive_data_socket_get_delegates_information(const int CLIENT_SOCKET, const char* DATA); 14 | int server_receive_data_socket_check_vote_status(const int CLIENT_SOCKET, const char* DATA); 15 | int server_receive_data_socket_get_delegates_voters_list(const int CLIENT_SOCKET, const char* DATA); 16 | int server_receive_data_socket_get_round_statistics(const int CLIENT_SOCKET, const char* DATA); 17 | #endif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018-2022 X-CASH-official 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/functions/block_verifiers_functions/block_verifiers_synchronize_functions/block_verifiers_synchronize_check_functions/block_verifiers_synchronize_check_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_SYNCHRONIZE_CHECK_FUNCTIONS_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_SYNCHRONIZE_CHECK_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int check_if_databases_are_synced(const int SETTINGS, const int RESERVE_BYTES_START_SETTINGS); 11 | int sync_check_reserve_proofs_database(int settings); 12 | int sync_check_majority_reserve_proofs_database(void); 13 | int sync_check_reserve_bytes_database(int settings, const int RESERVE_BYTES_START_SETTINGS); 14 | int sync_check_majority_reserve_bytes_database(const int RESERVE_BYTES_START_SETTINGS); 15 | int sync_check_delegates_database(int settings); 16 | int sync_check_majority_delegates_database(void); 17 | int sync_check_statistics_database(int settings); 18 | int sync_check_majority_statistics_database(void); 19 | #endif -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "(gdb) Launch", 9 | "type": "cppdbg", 10 | "request": "launch", 11 | //"preLaunchTask": "Build", 12 | "program": "${workspaceFolder}/build/xcash-dpops", 13 | "args": ["--block-verifiers-secret-key","c8c066b90e8059c505971e710267a48d01191a3d2be233f9081cde0e08f30ccfad98cadb3b13229c78709876955247cbef40d5b15c4842be605b0e8b30c97a7a","--test-mode","1"], 14 | "stopAtEntry": false, 15 | "cwd": "${workspaceFolder}", 16 | "environment": [], 17 | "externalConsole": false, 18 | "MIMode": "gdb", 19 | "setupCommands": [ 20 | { 21 | "description": "Enable pretty-printing for gdb", 22 | "text": "-enable-pretty-printing", 23 | "ignoreFailures": true 24 | } 25 | ] 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /src/functions/network_functions/network_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef NETWORK_FUNCTIONS_H_ /* Include guard */ 2 | #define NETWORK_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int check_if_IP_address_or_hostname(const char* HOST); 11 | int send_http_request(char *result, const char* HOST, const char* URL, const int PORT, const char* HTTP_SETTINGS, const char* HTTP_HEADERS[], const size_t HTTP_HEADERS_LENGTH, const char* DATA, const int DATA_TIMEOUT_SETTINGS); 12 | int send_and_receive_data_socket(char *result, const size_t RESULT_LENGTH, const char* HOST, const int PORT, const char* DATA, const int DATA_TIMEOUT_SETTINGS); 13 | int send_data_socket(const char* HOST, const int PORT, const char* DATA, const int DATA_TIMEOUT_SETTINGS); 14 | int send_data(const int SOCKET, unsigned char* data, const long DATA_LENGTH, const int MESSAGE_SETTINGS, const char* MESSAGE_DATA_SETTINGS); 15 | int receive_data(const int SOCKET, char *message, const size_t LENGTH, const int RECEIVE_DATA_SOCKET_TIMEOUT_SETTINGS, const int RECEIVE_DATA_SOCKET_TIMEOUT); 16 | #endif -------------------------------------------------------------------------------- /src/functions/shared_delegates_website_functions/shared_delegate_website_thread_server_functions/shared_delegate_website_thread_server_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef SHARED_DELEGATE_WEBSITE_THREAD_SERVER_FUNCTIONS_H_ /* Include guard */ 2 | #define SHARED_DELEGATE_WEBSITE_THREAD_SERVER_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int check_if_previous_block_producer(void); 11 | long long int add_block_to_blocks_found(void); 12 | int get_delegates_total_voters_count(const char* DELEGATES_PUBLIC_ADDRESS); 13 | long long int get_delegates_total_voters(struct voters* voters); 14 | int calculate_block_reward_for_each_delegate(long long int block_reward); 15 | void* block_height_timer_thread(void* parameters); 16 | long long int payment_timer_send_payment_and_update_databases(const char* PUBLIC_ADDRESS,const char* CURRENT_TOTAL,const char* TOTAL,const char* TX_HASH,const char* TX_KEY); 17 | int payment_timer_update_inactivity_count(const char* PUBLIC_ADDRESS,const char* CURRENT_TOTAL,const char* INACTIVITY_COUNT); 18 | int load_private_group_configuration(void); 19 | void* payment_timer_thread(void* parameters); 20 | #endif -------------------------------------------------------------------------------- /src/functions/block_verifiers_functions/block_verifiers_server_functions/block_verifiers_server_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_SERVER_FUNCTIONS_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_SERVER_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | void server_received_data_XCASH_DPOPS_test_data(const int CLIENT_SOCKET, char* MESSAGE); 11 | void server_receive_data_socket_block_verifiers_to_block_verifiers_invalid_reserve_proofs(const char* MESSAGE); 12 | void server_receive_data_socket_block_verifiers_to_network_data_nodes_block_verifiers_current_time(const int CLIENT_SOCKET); 13 | void server_receive_data_socket_main_network_data_node_to_block_verifier_start_block(const char* MESSAGE); 14 | void server_receive_data_socket_main_node_to_node_message_part_4(const char* MESSAGE); 15 | void server_receive_data_socket_node_to_node_majority(const char* MESSAGE); 16 | void server_receive_data_socket_node_to_node(const char* MESSAGE); 17 | void server_receive_data_socket_block_verifiers_to_block_verifiers_vrf_data(const char* MESSAGE); 18 | void server_receive_data_socket_block_verifiers_to_block_verifiers_block_blob_signature(const char* MESSAGE); 19 | #endif -------------------------------------------------------------------------------- /src/functions/database_functions/read_database_functions/read_database_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef READ_DATABASE_FUNCTIONS_H_ /* Include guard */ 2 | #define READ_DATABASE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int read_document_from_collection(const char* DATABASE, const char* COLLECTION, const char* DATA, char *result); 11 | int read_document_field_from_collection(const char* DATABASE, const char* COLLECTION, const char* DATA, const char* FIELD_NAME, char *result); 12 | int database_document_parse_json_data(const char* DATA, struct database_document_fields *result); 13 | int database_multiple_documents_parse_json_data(const char* data, struct database_multiple_documents_fields *result, const int document_count); 14 | int read_document_all_fields_from_collection(const char* DATABASE, const char* COLLECTION, const char* DATA, struct database_document_fields *result); 15 | int read_multiple_documents_all_fields_from_collection(const char* DATABASE, const char* COLLECTION, const char* DATA, struct database_multiple_documents_fields *result, const size_t DOCUMENT_COUNT_START, const size_t DOCUMENT_COUNT_TOTAL, const int DOCUMENT_OPTIONS, const char* DOCUMENT_OPTIONS_DATA); 16 | #endif -------------------------------------------------------------------------------- /src/functions/block_verifiers_functions/block_verifiers_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_FUNCTIONS_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int sync_all_delegates(void); 11 | int start_new_round(void); 12 | int start_blocks_create_vrf_data(void); 13 | int start_blocks_create_data(char* message, char* network_block_string); 14 | int start_current_round_start_blocks(void); 15 | int block_verifiers_create_VRF_secret_key_and_VRF_public_key(char* message); 16 | int block_verifiers_create_VRF_data(void); 17 | int block_verifiers_create_block_signature(char* message); 18 | void block_verifiers_create_vote_majority_results(char *result, const int SETTINGS); 19 | int block_verifiers_calculate_vote_majority_results(const int SETTINGS); 20 | int block_verifiers_create_vote_results(char* message); 21 | int block_verifiers_create_block_and_update_database(void); 22 | void print_block_producer(void); 23 | int block_verifiers_create_block(void); 24 | void sync_block_verifiers_minutes_and_seconds(const int MINUTES, const int SECONDS); 25 | int get_network_data_nodes_online_status(void); 26 | int block_verifiers_send_data_socket(const char* MESSAGE); 27 | #endif -------------------------------------------------------------------------------- /src/functions/server_functions/delegate_server_functions/delegate_server_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef DELEGATE_SERVER_FUNCTIONS_H_ /* Include guard */ 2 | #define DELEGATE_SERVER_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int block_verifiers_add_reserve_proof_check_if_data_is_valid(const char* MESSAGE, struct reserve_proof* reserve_proof); 11 | int add_reserve_proof_remove_previous_vote(const char* PUBLIC_ADDRESS_CREATE_RESERVE_PROOF_DATA); 12 | void server_receive_data_socket_node_to_block_verifiers_add_reserve_proof(const int CLIENT_SOCKET, const char* MESSAGE); 13 | int check_for_valid_delegate_name(const char* DELEGATE_NAME); 14 | int check_for_valid_ip_address(const char* HOST); 15 | void server_receive_data_socket_nodes_to_block_verifiers_register_delegates(const int CLIENT_SOCKET, const char* MESSAGE); 16 | int check_for_valid_delegate_fee(const char* MESSAGE); 17 | void server_receive_data_socket_nodes_to_block_verifiers_update_delegates(const int CLIENT_SOCKET, const char* MESSAGE); 18 | void server_receive_data_socket_nodes_to_block_verifiers_recover_delegates(const int CLIENT_SOCKET, const char* MESSAGE); 19 | void server_receive_data_socket_nodes_to_network_data_nodes_check_vote_status(const int CLIENT_SOCKET, const char* MESSAGE); 20 | #endif -------------------------------------------------------------------------------- /src/functions/block_verifiers_functions/block_verifiers_thread_server_functions/block_verifiers_thread_server_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_THREAD_SERVER_FUNCTIONS_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_THREAD_SERVER_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | int check_if_replayed_round(void); 11 | void* current_block_height_timer_thread(void* parameters); 12 | int check_reserve_proofs_timer_create_message(char *block_verifiers_message); 13 | int check_reserve_proofs_timer_get_database_data(const int CURRENT_RESERVE_PROOF_COUNT); 14 | int check_reserve_proofs_timer_update_delegates_total_vote_count(const int CURRENT_RESERVE_PROOF_COUNT); 15 | int check_reserve_proofs_timer_update_delegates_score(const int CURRENT_RESERVE_PROOF_COUNT); 16 | void check_reserve_proofs_timer_delete_reserve_proof(const int CURRENT_RESERVE_PROOF_COUNT); 17 | int check_reserve_proofs_timer_update_database(void); 18 | int select_random_unique_reserve_proof(struct reserve_proof* reserve_proof); 19 | int send_invalid_reserve_proof_to_block_verifiers(const struct reserve_proof* reserve_proof); 20 | void* check_reserve_proofs_timer_thread(void* parameters); 21 | void remove_inactive_delegates(void); 22 | void remove_block_heights_from_delegates(void); 23 | #endif 24 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "Build", 6 | "type": "shell", 7 | "command": "make", 8 | // use options.cwd property if the Makefile is not in the project root ${workspaceRoot} dir 9 | "options": { 10 | "cwd": "${workspaceRoot}/" 11 | }, 12 | // start the build without prompting for task selection, use "group": "build" otherwise 13 | "group": { 14 | "kind": "build", 15 | "isDefault": true 16 | }, 17 | "presentation": { 18 | "echo": true, 19 | "reveal": "always", 20 | "focus": false, 21 | "panel": "shared" 22 | }, 23 | // arg passing example: in this case is executed make QUIET=0 24 | "args": ["debug","-j","`nproc`"], 25 | // Use the standard less compilation problem matcher. 26 | "problemMatcher": { 27 | "owner": "cpp", 28 | "fileLocation": ["absolute"], 29 | "pattern": { 30 | "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", 31 | "file": 1, 32 | "line": 2, 33 | "column": 3, 34 | "severity": 4, 35 | "message": 5 36 | } 37 | } 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /src/functions/VRF_functions/crypto_verify_16.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 - 2019 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | #ifndef crypto_verify_16_H 24 | #define crypto_verify_16_H 25 | 26 | #include 27 | 28 | #define crypto_verify_16_BYTES 16U 29 | size_t crypto_verify_16_bytes(void); 30 | 31 | int crypto_verify_16(const unsigned char *x, const unsigned char *y) 32 | __attribute__ ((warn_unused_result)); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/functions/string_functions/string_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef STRING_FUNCTIONS_H_ /* Include guard */ 2 | #define STRING_FUNCTIONS_H_ 3 | 4 | 5 | /* 6 | ----------------------------------------------------------------------------------------------------------- 7 | Function prototypes 8 | ----------------------------------------------------------------------------------------------------------- 9 | */ 10 | 11 | int parse_json_data(const char* DATA, const char* FIELD_NAME, char *result, const size_t RESULT_TOTAL_LENGTH); 12 | int create_json_data_from_database_document_array(const struct database_document_fields* database_data, char *result, const char* DOCUMENT_FIELDS); 13 | int create_json_data_from_database_multiple_documents_array(const struct database_multiple_documents_fields* database_data, char *result, const char* DOCUMENT_FIELDS); 14 | int create_json_data_from_delegates_array(const struct delegates* delegates, char *result, const char* DOCUMENT_FIELDS); 15 | int create_json_data_from_votes_array(const struct votes* votes, char *result, const char* DOCUMENT_FIELDS); 16 | size_t string_count(const char* DATA, const char* STRING); 17 | int parse_http_response(char *result); 18 | int check_for_invalid_strings(const char* MESSAGE); 19 | void string_replace(char *data, const size_t DATA_TOTAL_LENGTH, const char* STR1, const char* STR2); 20 | void string_replace_limit(char *data, const size_t DATA_TOTAL_LENGTH, const char* STR1, const char* STR2, const int COUNT); 21 | int parse_reserve_bytes_data(char *result, const char* RESERVE_BYTES, const int ITEM); 22 | int random_string(char *result, const size_t LENGTH); 23 | #endif -------------------------------------------------------------------------------- /src/functions/thread_functions/thread_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef THREAD_FUNCTIONS_H_ /* Include guard */ 2 | #define THREAD_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | void* read_file_thread(void* parameters); 11 | void* write_file_thread(void* parameters); 12 | void* append_file_thread(void* parameters); 13 | void* insert_document_into_collection_json_thread(void* parameters); 14 | void* insert_multiple_documents_into_collection_json_thread(void* parameters); 15 | void* read_document_from_collection_thread(void* parameters); 16 | void* read_document_field_from_collection_thread(void* parameters); 17 | void* read_document_all_fields_from_collection_thread(void* parameters); 18 | void* read_multiple_documents_all_fields_from_collection_thread(void* parameters); 19 | void* update_document_from_collection_thread(void* parameters); 20 | void* update_all_documents_from_collection_thread(void* parameters); 21 | void* delete_document_from_collection_thread(void* parameters); 22 | void* delete_collection_from_database_thread(void* parameters); 23 | void* delete_database_thread(void* parameters); 24 | void* count_documents_in_collection_thread(void* parameters); 25 | void* count_all_documents_in_collection_thread(void* parameters); 26 | void* get_database_data_thread(void* parameters); 27 | void* get_database_data_hash_thread(void* parameters); 28 | int thread_settings(pthread_t thread_id); 29 | #endif -------------------------------------------------------------------------------- /src/functions/database_functions/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 3 | * MD5 Message-Digest Algorithm (RFC 1321). 4 | * 5 | * Homepage: 6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 7 | * 8 | * Author: 9 | * Alexander Peslyak, better known as Solar Designer 10 | * 11 | * This software was written by Alexander Peslyak in 2001. No copyright is 12 | * claimed, and the software is hereby placed in the public domain. 13 | * In case this attempt to disclaim copyright and place the software in the 14 | * public domain is deemed null and void, then the software is 15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 16 | * general public under the following terms: 17 | * 18 | * Redistribution and use in source and binary forms, with or without 19 | * modification, are permitted. 20 | * 21 | * There's ABSOLUTELY NO WARRANTY, express or implied. 22 | * 23 | * See md5.c for more information. 24 | */ 25 | 26 | #ifdef HAVE_OPENSSL 27 | #include 28 | #elif !defined(_MD5_H) 29 | #define _MD5_H 30 | 31 | /* Any 32-bit or wider unsigned integer data type will do */ 32 | typedef unsigned int MD5_u32plus; 33 | 34 | typedef struct { 35 | MD5_u32plus lo, hi; 36 | MD5_u32plus a, b, c, d; 37 | unsigned char buffer[64]; 38 | MD5_u32plus block[16]; 39 | } MD5_CTX; 40 | 41 | extern void MD5_Init(MD5_CTX *ctx); 42 | extern void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size); 43 | extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /scripts/build/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -r /var/www/html/build/ 4 | mkdir /var/www/html/build/ 5 | 6 | lxc start ubuntu-1804 7 | lxc exec ubuntu-1804 -- bash -c "source ~/.profile ; $(curl -sSL https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/master/scripts/build/build_script.sh)" 8 | lxc file pull ubuntu-1804/root/xcash-official/build/ /var/www/html/build/ubuntu-1804 9 | lxc stop ubuntu-1804 10 | 11 | lxc start ubuntu-1910 12 | lxc exec ubuntu-1910 -- bash -c "source ~/.profile ; $(curl -sSL https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/master/scripts/build/build_script.sh)" 13 | lxc file pull ubuntu-1910/root/xcash-official/build/ /var/www/html/build/ubuntu-1910 14 | lxc stop ubuntu-1910 15 | 16 | lxc start ubuntu-1804-static-x-cash-build 17 | lxc exec ubuntu-1804-static-x-cash-build -- bash -c "source ~/.profile ; $(curl -sSL https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/master/scripts/build/build_script_static.sh)" 18 | lxc file pull ubuntu-1804-static-x-cash-build/root/xcash-official/build/STEP_10_XCASH_BUILD_STATIC.txt /var/www/html/build/ubuntu-1804/STEP_10_XCASH_BUILD_STATIC.txt 19 | lxc stop ubuntu-1804-static-x-cash-build 20 | 21 | lxc start ubuntu-1910-static-x-cash-build 22 | lxc exec ubuntu-1910-static-x-cash-build -- bash -c "source ~/.profile ; $(curl -sSL https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/master/scripts/build/build_script_static.sh)" 23 | lxc file pull ubuntu-1910-static-x-cash-build/root/xcash-official/build/STEP_10_XCASH_BUILD_STATIC.txt /var/www/html/build/ubuntu-1910/STEP_10_XCASH_BUILD_STATIC.txt 24 | lxc stop ubuntu-1910-static-x-cash-build 25 | -------------------------------------------------------------------------------- /src/functions/block_verifiers_functions/block_verifiers_synchronize_functions/block_verifiers_synchronize_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_SYNCHRONIZE_FUNCTIONS_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_SYNCHRONIZE_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | void sync_network_data_nodes_database(void); 11 | void sync_block_verifiers_database(void); 12 | int sync_all_block_verifiers_list(const int SETTINGS, const int NETWORK_DATA_NODES_ONLINE_SETTINGS); 13 | int get_synced_block_verifiers(void); 14 | void get_block_verifier_for_syncing_database(int settings, const char* DELEGATES_IP_ADDRESS, char *block_verifiers_ip_address, const int DATABASE_SETTINGS); 15 | int sync_check_reserve_proofs_specific_database(const char* DATABASE_DATA, const char* BLOCK_VERIFIERS_IP_ADDRESS); 16 | int sync_check_reserve_bytes_specific_database(const char* DATABASE_DATA, const char* BLOCK_VERIFIERS_IP_ADDRESS, size_t starting_reserve_bytes_database, const size_t CURRENT_RESERVE_BYTES_DATABASE); 17 | int sync_reserve_proofs_database(int settings, const char* DELEGATES_IP_ADDRESS); 18 | int sync_reserve_bytes_database(int settings, const int RESERVE_BYTES_START_SETTINGS, const char* DELEGATES_IP_ADDRESS); 19 | int sync_delegates_database(int settings, const char* DELEGATES_IP_ADDRESS); 20 | int sync_statistics_database(int settings, const char* DELEGATES_IP_ADDRESS); 21 | int sync_delegates_database_fixed(int settings, const char* DELEGATES_IP_ADDRESS); 22 | #endif -------------------------------------------------------------------------------- /src/functions/VRF_functions/fe_25_5/constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | /* 37095705934669439343138083508754565189542113879843219016388785533085940283555 */ 25 | static const fe25519 d = { 26 | -10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116 27 | }; 28 | 29 | /* 2 * d = 30 | * 16295367250680780974490674513165176452449235426866156013048779062215315747161 31 | */ 32 | static const fe25519 d2 = { 33 | -21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199 }; 34 | 35 | /* sqrt(-1) */ 36 | static const fe25519 sqrtm1 = { 37 | -32595792, -7943725, 9377950, 3500415, 12389472, -272473, -25146209, -2005654, 326686, 11406482 38 | }; 39 | 40 | /* A = 486662 */ 41 | static const fe25519 curve25519_A = { 42 | 486662, 0, 0, 0, 0, 0, 0, 0, 0, 0 43 | }; 44 | -------------------------------------------------------------------------------- /src/functions/VRF_functions/crypto_verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 - 2019 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | #include 24 | #include 25 | 26 | #include "crypto_verify_16.h" 27 | 28 | size_t crypto_verify_16_bytes(void){ 29 | 30 | return crypto_verify_16_BYTES; 31 | } 32 | 33 | 34 | static inline int 35 | crypto_verify_n(const unsigned char *x_, const unsigned char *y_, 36 | const int n) 37 | { 38 | const volatile unsigned char *volatile x = x_; 39 | const volatile unsigned char *volatile y = y_; 40 | volatile uint_fast16_t d = 0U; 41 | int i; 42 | 43 | for (i = 0; i < n; i++) { 44 | d |= x[i] ^ y[i]; 45 | } 46 | return (1 & ((d - 1) >> 8)) - 1; 47 | } 48 | 49 | int crypto_verify_16(const unsigned char *x, const unsigned char *y) 50 | { 51 | return crypto_verify_n(x, y, crypto_verify_16_BYTES); 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/functions/VRF_functions/convert.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | #include "ed25519_ref10.h" 24 | 25 | #ifndef CONVERT_H 26 | #define CONVERT_H 27 | 28 | static const unsigned char SUITE = 0x04; /* ECVRF-ED25519-SHA512-Elligator2 */ 29 | 30 | void _vrf_ietfdraft03_point_to_string(unsigned char string[32], 31 | const ge25519_p3 *point); 32 | 33 | int _vrf_ietfdraft03_string_to_point(ge25519_p3 *point, 34 | const unsigned char string[32]); 35 | 36 | int _vrf_ietfdraft03_decode_proof(ge25519_p3 *Gamma, unsigned char c[16], 37 | unsigned char s[32], 38 | const unsigned char pi[80]); 39 | 40 | void _vrf_ietfdraft03_hash_to_curve_elligator2_25519(unsigned char H_string[32], 41 | const ge25519_p3 *Y_point, 42 | const unsigned char *alpha, 43 | const unsigned long long alphalen); 44 | 45 | void _vrf_ietfdraft03_hash_points(unsigned char c[16], const ge25519_p3 *P1, 46 | const ge25519_p3 *P2, const ge25519_p3 *P3, 47 | const ge25519_p3 *P4); 48 | 49 | #endif -------------------------------------------------------------------------------- /src/functions/VRF_functions/sha512EL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 - 2019 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | #ifndef SHA512EL_H 25 | #define SHA512EL_H 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | typedef struct crypto_hash_sha512_state { 33 | uint64_t state[8]; 34 | uint64_t count[2]; 35 | uint8_t buf[128]; 36 | } crypto_hash_sha512_state; 37 | 38 | 39 | size_t crypto_hash_sha512_statebytes(void); 40 | 41 | #define crypto_hash_sha512_BYTES 64U 42 | size_t crypto_hash_sha512_bytes(void); 43 | 44 | 45 | int crypto_hash_sha512(unsigned char *out, const unsigned char *in, 46 | unsigned long long inlen); 47 | 48 | 49 | int crypto_hash_sha512_init(crypto_hash_sha512_state *state); 50 | 51 | 52 | int crypto_hash_sha512_update(crypto_hash_sha512_state *state, 53 | const unsigned char *in, 54 | unsigned long long inlen); 55 | 56 | 57 | int crypto_hash_sha512_final(crypto_hash_sha512_state *state, 58 | unsigned char *out); 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/functions/VRF_functions/randombytes.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | #ifndef randombytes_H 24 | #define randombytes_H 25 | 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | typedef struct randombytes_implementation { 32 | const char *(*implementation_name)(void); /* required */ 33 | uint32_t (*random)(void); /* required */ 34 | uint32_t (*uniform)(const uint32_t upper_bound); /* optional, a default implementation will be used if NULL */ 35 | void (*buf)(void * const buf, const size_t size); /* required */ 36 | int (*close)(void); /* optional */ 37 | } randombytes_implementation; 38 | 39 | #define randombytes_SEEDBYTES 32U 40 | size_t randombytes_seedbytes(void); 41 | 42 | void randombytes_buf(void * const buf, const size_t size); 43 | 44 | uint32_t randombytes_random(void); 45 | 46 | uint32_t randombytes_uniform(const uint32_t upper_bound); 47 | 48 | int randombytes_close(void); 49 | 50 | int randombytes_set_implementation(randombytes_implementation *impl); 51 | 52 | const char *randombytes_implementation_name(void); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/functions/block_verifiers_functions/block_verifiers_synchronize_functions/block_verifiers_synchronize_server_functions/block_verifiers_synchronize_server_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCK_VERIFIERS_SYNCHRONIZE_SERVER_FUNCTIONS_H_ /* Include guard */ 2 | #define BLOCK_VERIFIERS_SYNCHRONIZE_SERVER_FUNCTIONS_H_ 3 | 4 | /* 5 | ----------------------------------------------------------------------------------------------------------- 6 | Function prototypes 7 | ----------------------------------------------------------------------------------------------------------- 8 | */ 9 | 10 | void server_receive_data_socket_get_current_block_height(const char* CLIENT_IP_ADDRESS); 11 | void server_receive_data_socket_send_current_block_height(const char* MESSAGE); 12 | void server_receive_data_socket_node_to_network_data_nodes_get_previous_current_next_block_verifiers_list(const int CLIENT_SOCKET); 13 | void server_receive_data_socket_node_to_network_data_nodes_get_current_block_verifiers_list(const int CLIENT_SOCKET); 14 | void server_receive_data_socket_network_data_nodes_to_network_data_nodes_database_sync_check(const char* MESSAGE); 15 | void server_receive_data_socket_node_to_block_verifiers_get_reserve_bytes_database_hash(const int CLIENT_SOCKET, const char* MESSAGE); 16 | void server_receive_data_socket_node_to_block_verifiers_check_if_current_block_verifier(const int CLIENT_SOCKET); 17 | void server_receive_data_socket_block_verifiers_to_block_verifiers_reserve_proofs_database_sync_check_all_update(const int CLIENT_SOCKET, const char* MESSAGE); 18 | void server_receive_data_socket_block_verifiers_to_block_verifiers_reserve_proofs_database_download_file_update(const int CLIENT_SOCKET, const char* MESSAGE); 19 | void server_receive_data_socket_block_verifiers_to_block_verifiers_reserve_bytes_database_sync_check_all_update(const int CLIENT_SOCKET, const char* MESSAGE); 20 | void server_receive_data_socket_block_verifiers_to_block_verifiers_reserve_bytes_database_download_file_update(const int CLIENT_SOCKET, const char* MESSAGE); 21 | void server_receive_data_socket_block_verifiers_to_block_verifiers_delegates_database_sync_check_update(const int CLIENT_SOCKET, const char* MESSAGE); 22 | void server_receive_data_socket_block_verifiers_to_block_verifiers_delegates_database_download_file_update(const int CLIENT_SOCKET); 23 | void server_receive_data_socket_block_verifiers_to_block_verifiers_statistics_database_sync_check_update(const int CLIENT_SOCKET, const char* MESSAGE); 24 | void server_receive_data_socket_block_verifiers_to_block_verifiers_statistics_database_download_file_update(const int CLIENT_SOCKET); 25 | #endif -------------------------------------------------------------------------------- /src/functions/VRF_functions/keypair.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | #include 25 | 26 | #include "sha512EL.h" 27 | #include "vrf.h" 28 | #include "ed25519_ref10.h" 29 | #include "randombytes.h" 30 | 31 | int crypto_vrf_ietfdraft03_keypair(unsigned char pk[crypto_vrf_ietfdraft03_PUBLICKEYBYTES], 32 | unsigned char sk[crypto_vrf_ietfdraft03_SECRETKEYBYTES]) 33 | { 34 | unsigned char seed[32]; 35 | 36 | randombytes_buf(seed, sizeof seed); 37 | crypto_vrf_ietfdraft03_keypair_from_seed(pk, sk, seed); 38 | memset(seed, 0, sizeof seed); 39 | 40 | return 0; 41 | } 42 | 43 | int crypto_vrf_ietfdraft03_keypair_from_seed(unsigned char pk[crypto_vrf_ietfdraft03_PUBLICKEYBYTES], 44 | unsigned char sk[crypto_vrf_ietfdraft03_SECRETKEYBYTES], 45 | const unsigned char seed[crypto_vrf_ietfdraft03_SEEDBYTES]) 46 | { 47 | ge25519_p3 A; 48 | 49 | crypto_hash_sha512(sk, seed, 32); 50 | sk[0] &= 248; 51 | sk[31] &= 127; 52 | sk[31] |= 64; 53 | ge25519_scalarmult_base(&A, sk); 54 | ge25519_p3_tobytes(pk, &A); 55 | memmove(sk, seed, 32); 56 | memmove(sk + 32, pk, 32); 57 | 58 | return 0; 59 | } 60 | 61 | void crypto_vrf_ietfdraft03_sk_to_pk(unsigned char pk[crypto_vrf_ietfdraft03_PUBLICKEYBYTES], 62 | const unsigned char skpk[crypto_vrf_ietfdraft03_SECRETKEYBYTES]) 63 | { 64 | memmove(pk, skpk+32, 32); 65 | } 66 | 67 | void crypto_vrf_ietfdraft03_sk_to_seed(unsigned char seed[crypto_vrf_ietfdraft03_SEEDBYTES], 68 | const unsigned char skpk[crypto_vrf_ietfdraft03_SECRETKEYBYTES]) 69 | { 70 | memmove(seed, skpk, 32); 71 | } 72 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "network[BLOCK_VALIDATION_NODES_TOTAL_AMOUNT]security[BLOCK_VALIDATION_NODES_TOTAL_AMOUNT]functions.h": "c", 4 | "define_macros_functions.h": "c", 5 | "variables_test.h": "c", 6 | "thread_server_functions.h": "c", 7 | "array": "c", 8 | "string_view": "c", 9 | "system_error": "c", 10 | "database_functions_test.h": "c", 11 | "reset_variables_allocated_on_the_heap_test.h": "c", 12 | "network_functions.h": "c", 13 | "network_daemon_functions.h": "c", 14 | "in.h": "c", 15 | "network_functions_test.h": "c", 16 | "database_functions.h": "c", 17 | "string": "c", 18 | "convert.h": "c", 19 | "time.h": "c", 20 | "sstream": "c", 21 | "algorithm": "c", 22 | "initializer_list": "cpp", 23 | "utility": "cpp", 24 | "insert_database_functions.h": "c", 25 | "block_verifiers_functions.h": "c", 26 | "block_verifiers_update_functions.h": "c", 27 | "network_security_functions.h": "c", 28 | "unistd.h": "c", 29 | "pthread.h": "c", 30 | "string_functions.h": "c", 31 | "signal.h": "c", 32 | "xcash_dpops_test.h": "c", 33 | "organize_functions.h": "c", 34 | "insert_database_functions_test.h": "c", 35 | "vrf_functions_test.h": "c", 36 | "define_macro_functions.h": "c", 37 | "define_macros_test.h": "c", 38 | "read_database_functions_test.h": "c", 39 | "delegate_website_functions_test.h": "c", 40 | "block_verifiers_thread_server_functions.h": "c", 41 | "initialize_and_reset_structs_define_macros.h": "c", 42 | "block_verifiers_synchronize_functions.h": "c", 43 | "block_verifiers_synchronize_check_functions.h": "c", 44 | "block_verifiers_server_functions_test.h": "c", 45 | "delete_database_functions_test.h": "c", 46 | "block_verifiers_synchronize_server_functions.h": "c", 47 | "optimizations_functions_test.h": "c", 48 | "mongoc.h": "c", 49 | "bson.h": "c", 50 | "tuple": "c", 51 | "define_macros.h": "c", 52 | "stdio.h": "c", 53 | "variables.h": "c", 54 | "optional": "c", 55 | "istream": "c", 56 | "ostream": "c", 57 | "type_traits": "c", 58 | "network_wallet_functions.h": "c", 59 | "read_database_functions.h": "c", 60 | "vrf_functions.h": "c", 61 | "blockchain_functions.h": "c", 62 | "delete_database_functions.h": "c", 63 | "structures.h": "c", 64 | "count_database_functions.h": "c", 65 | "ranges": "c", 66 | "functional": "c", 67 | "deque": "c", 68 | "unordered_map": "c", 69 | "vector": "c" 70 | } 71 | } -------------------------------------------------------------------------------- /src/tests/network_functions_test/network_wallet_functions_test/network_wallet_functions_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "define_macro_functions.h" 8 | #include "define_macros.h" 9 | #include "variables.h" 10 | #include "define_macros_test.h" 11 | 12 | #include "network_wallet_functions.h" 13 | #include "network_functions.h" 14 | #include "server_functions.h" 15 | #include "string_functions.h" 16 | #include "VRF_functions.h" 17 | 18 | #include "variables_test.h" 19 | #include "network_wallet_functions_test.h" 20 | 21 | /* 22 | ----------------------------------------------------------------------------------------------------------- 23 | Functions 24 | ----------------------------------------------------------------------------------------------------------- 25 | */ 26 | 27 | /* 28 | ----------------------------------------------------------------------------------------------------------- 29 | Name: network_wallet_functions_test 30 | Description: Test the network_wallet functions 31 | Return: The number of passed network_wallet functions test 32 | ----------------------------------------------------------------------------------------------------------- 33 | */ 34 | 35 | int network_wallet_functions_test(void) 36 | { 37 | // reset the variables 38 | memset(data_test,0,sizeof(data_test)); 39 | count_test = 0; 40 | 41 | // write the start test message 42 | fprintf(stderr,"\033[1;34m%s\nnetwork wallet functions test - Total test: %d\n%s\n\n\033[0m",TEST_OUTLINE,NETWORK_WALLET_FUNCTIONS_TEST,TEST_OUTLINE); 43 | 44 | // test the get_total_amount function 45 | if (get_total_amount() == 0) 46 | { 47 | color_print("FAILED! Test for get_total_amount","red"); 48 | } 49 | else 50 | { 51 | color_print("PASSED! Test for get_total_amount","green"); 52 | count_test++; 53 | } 54 | 55 | // test the get_public_address function 56 | memset(xcash_wallet_public_address,0,sizeof(xcash_wallet_public_address)); 57 | if (get_public_address() == 1) 58 | { 59 | color_print("PASSED! Test for get_public_address","green"); 60 | count_test++; 61 | } 62 | else 63 | { 64 | color_print("FAILED! Test for get_public_address","red"); 65 | } 66 | 67 | // test the check_reserve_proofs function 68 | memset(data_test,0,strnlen(data_test,BUFFER_SIZE)); 69 | if (check_reserve_proofs(data_test,CHECK_RESERVE_PROOF_TEST_PUBLIC_ADDRESS,CHECK_RESERVE_PROOF_TEST_RESERVE_PROOF) == 1 && strncmp(data_test,CHECK_RESERVE_PROOF_TEST_AMOUNT,2) == 0) 70 | { 71 | color_print("PASSED! Test for check_reserve_proofs","green"); 72 | count_test++; 73 | } 74 | else 75 | { 76 | color_print("FAILED! Test for check_reserve_proofs","red"); 77 | } 78 | 79 | // write the end test message 80 | fprintf(stderr,"\033[1;33m\n\n%s\nnetwork wallet functions test - Passed test: %d, Failed test: %d\n%s\n\n\n\033[0m",TEST_OUTLINE,count_test,NETWORK_WALLET_FUNCTIONS_TEST-count_test,TEST_OUTLINE); 81 | return count_test; 82 | } 83 | -------------------------------------------------------------------------------- /src/functions/VRF_functions/crypto_vrf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | #ifndef crypto_vrf_H 25 | #define crypto_vrf_H 26 | 27 | /* 28 | * THREAD SAfe25519TY: crypto_vrf_keypair() is thread-safe25519 provided that 29 | * sodium_init() was called before. 30 | * 31 | * Other functions, including crypto_vrf_keypair_from_seed(), are always 32 | * thread-safe25519. 33 | */ 34 | 35 | #include 36 | 37 | #include "vrf.h" 38 | 39 | 40 | #define crypto_vrf_PUBLICKEYBYTES crypto_vrf_ietfdraft03_PUBLICKEYBYTES 41 | size_t crypto_vrf_publickeybytes(void); 42 | 43 | #define crypto_vrf_SECRETKEYBYTES crypto_vrf_ietfdraft03_SECRETKEYBYTES 44 | size_t crypto_vrf_secretkeybytes(void); 45 | 46 | #define crypto_vrf_SEEDBYTES crypto_vrf_ietfdraft03_SEEDBYTES 47 | size_t crypto_vrf_seedbytes(void); 48 | 49 | #define crypto_vrf_PROOFBYTES crypto_vrf_ietfdraft03_PROOFBYTES 50 | size_t crypto_vrf_proofbytes(void); 51 | 52 | #define crypto_vrf_OUTPUTBYTES crypto_vrf_ietfdraft03_OUTPUTBYTES 53 | size_t crypto_vrf_outputbytes(void); 54 | 55 | #define crypto_vrf_PRIMITIVE "ietfdraft03" 56 | const char *crypto_vrf_primitive(void); 57 | 58 | int crypto_vrf_keypair(unsigned char *pk, unsigned char *sk); 59 | 60 | int crypto_vrf_keypair_from_seed(unsigned char *pk, unsigned char *sk, 61 | const unsigned char *seed); 62 | 63 | int crypto_vrf_is_valid_key(const unsigned char *pk) 64 | __attribute__ ((warn_unused_result)); 65 | 66 | int crypto_vrf_prove(unsigned char *proof, const unsigned char *sk, 67 | const unsigned char *m, unsigned long long mlen); 68 | 69 | int crypto_vrf_verify(unsigned char *output, 70 | const unsigned char *pk, 71 | const unsigned char *proof, 72 | const unsigned char *m, unsigned long long mlen) 73 | __attribute__ ((warn_unused_result)); 74 | 75 | int crypto_vrf_proof_to_hash(unsigned char *hash, const unsigned char *proof); 76 | 77 | void crypto_vrf_sk_to_pk(unsigned char *pk, const unsigned char *skpk); 78 | 79 | void crypto_vrf_sk_to_seed(unsigned char *seed, const unsigned char *skpk); 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /VRF_LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018-2019 X-CASH Project, Derived from 2018, Amir derived from 2018 Algorand LLC Derived from 2013-2019 Frank Denis 4 | 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | MIT License 25 | 26 | Copyright (c) 2018, Amir 27 | 28 | Permission is hereby granted, free of charge, to any person obtaining a copy 29 | of this software and associated documentation files (the "Software"), to deal 30 | in the Software without restriction, including without limitation the rights 31 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 32 | copies of the Software, and to permit persons to whom the Software is 33 | furnished to do so, subject to the following conditions: 34 | 35 | The above copyright notice and this permission notice shall be included in all 36 | copies or substantial portions of the Software. 37 | 38 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 39 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 40 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 41 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 42 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 43 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 44 | SOFTWARE. 45 | 46 | /* 47 | * ISC License 48 | * 49 | * Copyright (c) 2013-2019 50 | * Frank Denis 51 | * 52 | * Permission to use, copy, modify, and/or distribute this software for any 53 | * purpose with or without fee is hereby granted, provided that the above 54 | * copyright notice and this permission notice appear in all copies. 55 | * 56 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 57 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 58 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 59 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 60 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 61 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 62 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 63 | */ 64 | -------------------------------------------------------------------------------- /src/functions/VRF_functions/vrf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 - 2019 Amir Hossein Alikhah Mishamandani 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | #include 23 | #ifndef VRF_H 24 | #define VRF_H 25 | 26 | #define crypto_vrf_ietfdraft03_PUBLICKEYBYTES 32U 27 | size_t crypto_vrf_ietfdraft03_publickeybytes(void); 28 | 29 | #define crypto_vrf_ietfdraft03_SECRETKEYBYTES 64U 30 | size_t crypto_vrf_ietfdraft03_secretkeybytes(void); 31 | 32 | #define crypto_vrf_ietfdraft03_SEEDBYTES 32U 33 | size_t crypto_vrf_ietfdraft03_seedbytes(void); 34 | 35 | #define crypto_vrf_ietfdraft03_PROOFBYTES 80U 36 | size_t crypto_vrf_ietfdraft03_proofbytes(void); 37 | 38 | #define crypto_vrf_ietfdraft03_OUTPUTBYTES 64U 39 | size_t crypto_vrf_ietfdraft03_outputbytes(void); 40 | 41 | int crypto_vrf_ietfdraft03_prove(unsigned char *proof, 42 | const unsigned char *sk, 43 | const unsigned char *m, 44 | unsigned long long mlen); 45 | 46 | int crypto_vrf_ietfdraft03_keypair(unsigned char pk[crypto_vrf_ietfdraft03_PUBLICKEYBYTES], 47 | unsigned char sk[crypto_vrf_ietfdraft03_SECRETKEYBYTES]); 48 | 49 | int crypto_vrf_ietfdraft03_keypair_from_seed(unsigned char pk[crypto_vrf_ietfdraft03_PUBLICKEYBYTES], 50 | unsigned char sk[crypto_vrf_ietfdraft03_SECRETKEYBYTES], 51 | const unsigned char seed[crypto_vrf_ietfdraft03_SEEDBYTES]); 52 | 53 | void crypto_vrf_ietfdraft03_sk_to_pk(unsigned char pk[crypto_vrf_ietfdraft03_PUBLICKEYBYTES], 54 | const unsigned char skpk[crypto_vrf_ietfdraft03_SECRETKEYBYTES]); 55 | 56 | void crypto_vrf_ietfdraft03_sk_to_seed(unsigned char seed[crypto_vrf_ietfdraft03_SEEDBYTES], 57 | const unsigned char skpk[crypto_vrf_ietfdraft03_SECRETKEYBYTES]); 58 | 59 | int crypto_vrf_ietfdraft03_is_valid_key(const unsigned char *pk) 60 | __attribute__ ((warn_unused_result)); 61 | 62 | int crypto_vrf_ietfdraft03_verify(unsigned char *output, 63 | const unsigned char *pk, 64 | const unsigned char *proof, 65 | const unsigned char *m, 66 | unsigned long long mlen) 67 | __attribute__ ((warn_unused_result)); 68 | 69 | int crypto_vrf_ietfdraft03_proof_to_hash(unsigned char *hash, 70 | const unsigned char *proof); 71 | #endif -------------------------------------------------------------------------------- /src/functions/VRF_functions/crypto_vrf.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include "vrf.h" 26 | #include "crypto_vrf.h" 27 | size_t 28 | crypto_vrf_publickeybytes(void) 29 | { 30 | return crypto_vrf_PUBLICKEYBYTES; 31 | } 32 | 33 | size_t 34 | crypto_vrf_secretkeybytes(void) 35 | { 36 | return crypto_vrf_SECRETKEYBYTES; 37 | } 38 | 39 | size_t 40 | crypto_vrf_seedbytes(void) 41 | { 42 | return crypto_vrf_SEEDBYTES; 43 | } 44 | 45 | size_t 46 | crypto_vrf_proofbytes(void) 47 | { 48 | return crypto_vrf_PROOFBYTES; 49 | } 50 | 51 | size_t 52 | crypto_vrf_outputbytes(void) 53 | { 54 | return crypto_vrf_OUTPUTBYTES; 55 | } 56 | 57 | const char * 58 | crypto_vrf_primitive(void) 59 | { 60 | return crypto_vrf_PRIMITIVE; 61 | } 62 | 63 | int 64 | crypto_vrf_keypair(unsigned char *pk, unsigned char *sk) 65 | { 66 | return crypto_vrf_ietfdraft03_keypair(pk, sk); 67 | } 68 | 69 | int crypto_vrf_keypair_from_seed(unsigned char *pk, unsigned char *sk, const unsigned char *seed){ 70 | 71 | return crypto_vrf_ietfdraft03_keypair_from_seed(pk, sk, seed); 72 | } 73 | 74 | int 75 | crypto_vrf_is_valid_key(const unsigned char *pk) 76 | { 77 | return crypto_vrf_ietfdraft03_is_valid_key(pk); 78 | } 79 | 80 | int 81 | crypto_vrf_prove(unsigned char *proof, const unsigned char *skpk, 82 | const unsigned char *m, const unsigned long long mlen) 83 | { 84 | return crypto_vrf_ietfdraft03_prove(proof, skpk, m, mlen); 85 | } 86 | 87 | int 88 | crypto_vrf_verify(unsigned char *output, const unsigned char *pk, 89 | const unsigned char *proof, const unsigned char *m, 90 | const unsigned long long mlen) 91 | { 92 | return crypto_vrf_ietfdraft03_verify(output, pk, proof, m, mlen); 93 | } 94 | 95 | int 96 | crypto_vrf_proof_to_hash(unsigned char *hash, const unsigned char *proof) 97 | { 98 | return crypto_vrf_ietfdraft03_proof_to_hash(hash, proof); 99 | } 100 | 101 | void 102 | crypto_vrf_sk_to_pk(unsigned char *pk, const unsigned char *skpk) 103 | { 104 | crypto_vrf_ietfdraft03_sk_to_pk(pk, skpk); 105 | } 106 | 107 | void 108 | crypto_vrf_sk_to_seed(unsigned char *seed, const unsigned char *skpk) 109 | { 110 | crypto_vrf_ietfdraft03_sk_to_seed(seed, skpk); 111 | } 112 | -------------------------------------------------------------------------------- /src/functions/VRF_functions/randombytes.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include "randombytes.h" 31 | #include "common.h" 32 | 33 | #ifndef RANDOMBYTES_DEFAULT_IMPLEMENTATION 34 | #define RANDOMBYTES_DEFAULT_IMPLEMENTATION 35 | #endif 36 | 37 | 38 | /* C++Builder defines a "random" macro */ 39 | #undef random 40 | 41 | static const randombytes_implementation *implementation; 42 | 43 | #ifndef RANDOMBYTES_DEFAULT_IMPLEMENTATION 44 | # define RANDOMBYTES_DEFAULT_IMPLEMENTATION NULL 45 | #endif 46 | 47 | static void randombytes_init_if_needed(void){ 48 | 49 | implementation = NULL; 50 | } 51 | 52 | int randombytes_set_implementation(randombytes_implementation *impl){ 53 | 54 | implementation = impl; 55 | return 0; 56 | } 57 | 58 | const char *randombytes_implementation_name(void) 59 | { 60 | randombytes_init_if_needed(); 61 | return implementation->implementation_name(); 62 | } 63 | 64 | uint32_t randombytes_random(void){ 65 | 66 | randombytes_init_if_needed(); 67 | return implementation->random(); 68 | } 69 | 70 | uint32_t randombytes_uniform(const uint32_t upper_bound) 71 | { 72 | uint32_t min; 73 | uint32_t r; 74 | 75 | randombytes_init_if_needed(); 76 | if (implementation->uniform != NULL) { 77 | return implementation->uniform(upper_bound); 78 | } 79 | if (upper_bound < 2) { 80 | return 0; 81 | } 82 | min = (1U + ~upper_bound) % upper_bound; /* = 2**32 mod upper_bound */ 83 | do { 84 | r = randombytes_random(); 85 | } while (r < min); 86 | /* r is now clamped to a set whose size mod upper_bound == 0 87 | * the worst case (2**31+1) requires ~ 2 attempts */ 88 | 89 | return r % upper_bound; 90 | } 91 | 92 | void randombytes_buf(void * const buf, const size_t size) 93 | { 94 | randombytes_init_if_needed(); 95 | if (size > (size_t) 0U) { 96 | implementation->buf(buf, size); 97 | } 98 | } 99 | 100 | size_t 101 | randombytes_seedbytes(void) 102 | { 103 | return randombytes_SEEDBYTES; 104 | } 105 | 106 | int 107 | randombytes_close(void) 108 | { 109 | if (implementation != NULL && implementation->close != NULL) { 110 | return implementation->close(); 111 | } 112 | return 0; 113 | } 114 | 115 | void 116 | randombytes(unsigned char * const buf, const unsigned long long buf_len) 117 | { 118 | assert(buf_len <= SIZE_MAX); 119 | randombytes_buf(buf, (size_t) buf_len); 120 | } 121 | -------------------------------------------------------------------------------- /src/functions/VRF_functions/fe_25_5/base2.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | { 25 | { 25967493, -14356035, 29566456, 3660896, -12694345, 4014787, 27544626, -11754271, -6079156, 2047605 }, 26 | { -12545711, 934262, -2722910, 3049990, -727428, 9406986, 12720692, 5043384, 19500929, -15469378 }, 27 | { -8738181, 4489570, 9688441, -14785194, 10184609, -12363380, 29287919, 11864899, -24514362, -4438546 } 28 | }, 29 | { 30 | { 15636291, -9688557, 24204773, -7912398, 616977, -16685262, 27787600, -14772189, 28944400, -1550024 }, 31 | { 16568933, 4717097, -11556148, -1102322, 15682896, -11807043, 16354577, -11775962, 7689662, 11199574 }, 32 | { 30464156, -5976125, -11779434, -15670865, 23220365, 15915852, 7512774, 10017326, -17749093, -9920357 } 33 | }, 34 | { 35 | { 10861363, 11473154, 27284546, 1981175, -30064349, 12577861, 32867885, 14515107, -15438304, 10819380 }, 36 | { 4708026, 6336745, 20377586, 9066809, -11272109, 6594696, -25653668, 12483688, -12668491, 5581306 }, 37 | { 19563160, 16186464, -29386857, 4097519, 10237984, -4348115, 28542350, 13850243, -23678021, -15815942 } 38 | }, 39 | { 40 | { 5153746, 9909285, 1723747, -2777874, 30523605, 5516873, 19480852, 5230134, -23952439, -15175766 }, 41 | { -30269007, -3463509, 7665486, 10083793, 28475525, 1649722, 20654025, 16520125, 30598449, 7715701 }, 42 | { 28881845, 14381568, 9657904, 3680757, -20181635, 7843316, -31400660, 1370708, 29794553, -1409300 } 43 | }, 44 | { 45 | { -22518993, -6692182, 14201702, -8745502, -23510406, 8844726, 18474211, -1361450, -13062696, 13821877 }, 46 | { -6455177, -7839871, 3374702, -4740862, -27098617, -10571707, 31655028, -7212327, 18853322, -14220951 }, 47 | { 4566830, -12963868, -28974889, -12240689, -7602672, -2830569, -8514358, -10431137, 2207753, -3209784 } 48 | }, 49 | { 50 | { -25154831, -4185821, 29681144, 7868801, -6854661, -9423865, -12437364, -663000, -31111463, -16132436 }, 51 | { 25576264, -2703214, 7349804, -11814844, 16472782, 9300885, 3844789, 15725684, 171356, 6466918 }, 52 | { 23103977, 13316479, 9739013, -16149481, 817875, -15038942, 8965339, -14088058, -30714912, 16193877 } 53 | }, 54 | { 55 | { -33521811, 3180713, -2394130, 14003687, -16903474, -16270840, 17238398, 4729455, -18074513, 9256800 }, 56 | { -25182317, -4174131, 32336398, 5036987, -21236817, 11360617, 22616405, 9761698, -19827198, 630305 }, 57 | { -13720693, 2639453, -24237460, -7406481, 9494427, -5774029, -6554551, -15960994, -2449256, -14291300 } 58 | }, 59 | { 60 | { -3151181, -5046075, 9282714, 6866145, -31907062, -863023, -18940575, 15033784, 25105118, -7894876 }, 61 | { -24326370, 15950226, -31801215, -14592823, -11662737, -5090925, 1573892, -2625887, 2198790, -15804619 }, 62 | { -3099351, 10324967, -2241613, 7453183, -5446979, -2735503, -13812022, -16236442, -32461234, -12290683 } 63 | } 64 | -------------------------------------------------------------------------------- /src/functions/file_functions/file_functions.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "file_functions.h" 5 | 6 | /* 7 | ----------------------------------------------------------------------------------------------------------- 8 | Functions 9 | ----------------------------------------------------------------------------------------------------------- 10 | */ 11 | 12 | /* 13 | ----------------------------------------------------------------------------------------------------------- 14 | Name: get_file_size 15 | Description: Gets the file size 16 | Parameters: 17 | file_name - The file name 18 | Return: 0 if an error has occured, otherwise the file length 19 | ----------------------------------------------------------------------------------------------------------- 20 | */ 21 | 22 | long get_file_size(const char* FILE_NAME) 23 | { 24 | // Variables 25 | FILE* file; 26 | long file_size = 0; 27 | 28 | // check if the file exist 29 | if ((file = fopen(FILE_NAME,"rb")) != NULL) 30 | { 31 | // the file exist, get the file size 32 | fseek(file, 0, SEEK_END); 33 | if ((file_size = ftell(file)) == -1) 34 | { 35 | file_size = 0; 36 | } 37 | fclose(file); 38 | } 39 | return file_size; 40 | } 41 | 42 | 43 | 44 | /* 45 | ----------------------------------------------------------------------------------------------------------- 46 | Name: read_file 47 | Description: Reads the file 48 | Parameters: 49 | result - The data read from the file 50 | file_name - The file name 51 | Return: 0 if an error has occured, otherwise the file length 52 | ----------------------------------------------------------------------------------------------------------- 53 | */ 54 | 55 | long read_file(unsigned char *result, const char* FILE_NAME) 56 | { 57 | // Variables 58 | FILE* file; 59 | long file_size; 60 | 61 | // check if the file exist 62 | if ((file = fopen(FILE_NAME,"rb")) != NULL) 63 | { 64 | // the file exist, read the data in the result 65 | fseek(file, 0, SEEK_END); 66 | if ((file_size = ftell(file)) == -1) 67 | { 68 | fclose(file); 69 | return 0; 70 | } 71 | fseek(file, 0, SEEK_SET); 72 | if (fread(result, sizeof(unsigned char), file_size, file) != (size_t)file_size) 73 | { 74 | fclose(file); 75 | return 0; 76 | } 77 | fclose(file); 78 | } 79 | else 80 | { 81 | return 0; 82 | } 83 | return file_size; 84 | } 85 | 86 | 87 | 88 | /* 89 | ----------------------------------------------------------------------------------------------------------- 90 | Name: write_file 91 | Description: Writes data to a file 92 | Parameters: 93 | DATA = The data to write to the file 94 | file_name - The file name 95 | Return: 0 if an error has occured, 1 if successfull 96 | ----------------------------------------------------------------------------------------------------------- 97 | */ 98 | 99 | int write_file(const char* DATA, const char* FILE_NAME) 100 | { 101 | // Variables 102 | FILE* file; 103 | int settings = 0; 104 | 105 | if ((file = fopen(FILE_NAME,"w")) != NULL) 106 | { 107 | fprintf(file,"%s",DATA); 108 | fclose(file); 109 | settings = 1; 110 | } 111 | return settings; 112 | } 113 | 114 | 115 | 116 | /* 117 | ----------------------------------------------------------------------------------------------------------- 118 | Name: append_file 119 | Description: Appends data to a file 120 | Parameters: 121 | DATA = The data to write to the file 122 | file_name - The file name 123 | Return: 0 if an error has occured, 1 if successfull 124 | ----------------------------------------------------------------------------------------------------------- 125 | */ 126 | 127 | int append_file(const char* DATA, const char* FILE_NAME) 128 | { 129 | // Variables 130 | FILE* file; 131 | int settings = 0; 132 | 133 | if ((file = fopen(FILE_NAME,"a")) != NULL) 134 | { 135 | fprintf(file,"%s",DATA); 136 | fclose(file); 137 | settings = 1; 138 | } 139 | return settings; 140 | } -------------------------------------------------------------------------------- /scripts/firewall/firewall_script_xcash_node.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # iptables script for server 3 | # if you changed any default ports change them in the firewall as well 4 | 5 | # ACCEPT all packets at the top so each packet runs through the firewall rules, then DROP all INPUT and FORWARD if they dont use any of the firewall settings 6 | iptables -P INPUT ACCEPT 7 | iptables -P FORWARD ACCEPT 8 | iptables -P OUTPUT ACCEPT 9 | # remove all existing IP tables 10 | iptables -t nat -F 11 | iptables -t mangle -F 12 | iptables -t mangle -X 13 | iptables -t mangle -F 14 | iptables -t raw -F 15 | iptables -t raw -X 16 | iptables -F 17 | iptables -X 18 | 19 | # ip table prerouting data (this is where you want to block ddos attacks) 20 | # Drop all invalid packets 21 | iptables -t mangle -A PREROUTING -m conntrack --ctstate INVALID -j DROP 22 | # Prevent syn flood 23 | iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP 24 | iptables -t mangle -A PREROUTING -p tcp -m conntrack --ctstate NEW -m tcpmss ! --mss 536:65535 -j DROP 25 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP 26 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN FIN,SYN -j DROP 27 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags SYN,RST SYN,RST -j DROP 28 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,RST FIN,RST -j DROP 29 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,ACK FIN -j DROP 30 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,URG URG -j DROP 31 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,FIN FIN -j DROP 32 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,PSH PSH -j DROP 33 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL ALL -j DROP 34 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL NONE -j DROP 35 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP 36 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,FIN,PSH,URG -j DROP 37 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP 38 | 39 | # filter data for INPUT, FORWARD, and OUTPUT 40 | # Accept any packets coming or going on localhost 41 | iptables -I INPUT -i lo -j ACCEPT 42 | # keep already established connections running 43 | iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 44 | 45 | # block ip spoofing. these are the ranges of local IP address. 46 | iptables -A INPUT -s 10.12.242.0/24 -j ACCEPT 47 | iptables -A INPUT -s 10.0.0.0/8 -j DROP 48 | iptables -A INPUT -s 169.254.0.0/16 -j DROP 49 | iptables -A INPUT -s 172.16.0.0/12 -j DROP 50 | iptables -A INPUT -s 127.0.0.0/8 -j DROP 51 | iptables -A INPUT -s 192.168.0.0/24 -j DROP 52 | iptables -A INPUT -s 224.0.0.0/4 -j DROP 53 | iptables -A INPUT -d 224.0.0.0/4 -j DROP 54 | iptables -A INPUT -s 240.0.0.0/5 -j DROP 55 | iptables -A INPUT -d 240.0.0.0/5 -j DROP 56 | iptables -A INPUT -s 0.0.0.0/8 -j DROP 57 | iptables -A INPUT -d 0.0.0.0/8 -j DROP 58 | iptables -A INPUT -d 239.255.255.0/24 -j DROP 59 | iptables -A INPUT -d 255.255.255.255 -j DROP 60 | 61 | # block all traffic from ip address (iptables -A INPUT -s ipaddress -j DROP) 62 | #unblock them using iptables -D INPUT -s ipaddress -j DROP 63 | 64 | # Block different attacks 65 | # block port scans 66 | # this will lock the IP out for 1 day 67 | iptables -A INPUT -m recent --name portscan --rcheck --seconds 86400 -j DROP 68 | iptables -A FORWARD -m recent --name portscan --rcheck --seconds 86400 -j DROP 69 | iptables -A INPUT -m recent --name portscan --remove 70 | iptables -A FORWARD -m recent --name portscan --remove 71 | iptables -A INPUT -p tcp -m tcp -m multiport --destination-ports 21,25,110,135,139,143,445,1433,3306,3389 -m recent --name portscan --set -j DROP 72 | iptables -A FORWARD -p tcp -m tcp -m multiport --destination-ports 21,25,110,135,139,143,445,1433,3306,3389 -m recent --name portscan --set -j DROP 73 | 74 | # Accept specific packets 75 | # Accept ICMP 76 | iptables -A INPUT -p icmp -j ACCEPT 77 | 78 | # Accept XCASH 79 | iptables -A INPUT -p tcp --dport 18280 -j ACCEPT 80 | iptables -A INPUT -p tcp --dport 18281 -j ACCEPT 81 | 82 | # Allow ssh (allow 100 login attempts in 1 hour from the same ip, if more than ban them for 1 hour) 83 | iptables -A INPUT -p tcp -m tcp --dport ${SSH_PORT_NUMBER} -m state --state NEW -m recent --set --name DEFAULT --rsource 84 | iptables -A INPUT -p tcp -m tcp --dport ${SSH_PORT_NUMBER} -m state --state NEW -m recent --update --seconds 3600 --hitcount 100 --name DEFAULT --rsource -j DROP 85 | iptables -A INPUT -p tcp -m tcp --dport ${SSH_PORT_NUMBER} -j ACCEPT 86 | 87 | # DROP all INPUT and FORWARD packets if they have reached this point 88 | iptables -A INPUT -j DROP 89 | iptables -A FORWARD -j DROP 90 | -------------------------------------------------------------------------------- /src/functions/VRF_functions/ed25519_ref10.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | #ifndef ed25519_ref10_H 25 | #define ed25519_ref10_H 26 | 27 | #include 28 | #include 29 | 30 | /* 31 | fe means field element. 32 | Here the field is \Z/(2^255-19). 33 | */ 34 | 35 | typedef int32_t fe25519[10]; 36 | 37 | 38 | void fe25519_invert(fe25519 out, const fe25519 z); 39 | void fe25519_frombytes(fe25519 h, const unsigned char *s); 40 | void fe25519_tobytes(unsigned char *s, const fe25519 h); 41 | 42 | 43 | # include "ed25519_ref10_fe_25_5.h" 44 | 45 | 46 | /* 47 | ge means group element. 48 | 49 | Here the group is the set of pairs (x,y) of field elements 50 | satisfying -x^2 + y^2 = 1 + d x^2y^2 51 | where d = -121665/121666. 52 | 53 | Representations: 54 | ge25519_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z 55 | ge25519_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT 56 | ge25519_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T 57 | ge25519_precomp (Duif): (y+x,y-x,2dxy) 58 | */ 59 | 60 | typedef struct { 61 | fe25519 X; 62 | fe25519 Y; 63 | fe25519 Z; 64 | } ge25519_p2; 65 | 66 | typedef struct { 67 | fe25519 X; 68 | fe25519 Y; 69 | fe25519 Z; 70 | fe25519 T; 71 | } ge25519_p3; 72 | 73 | typedef struct { 74 | fe25519 X; 75 | fe25519 Y; 76 | fe25519 Z; 77 | fe25519 T; 78 | } ge25519_p1p1; 79 | 80 | typedef struct { 81 | fe25519 yplusx; 82 | fe25519 yminusx; 83 | fe25519 xy2d; 84 | } ge25519_precomp; 85 | 86 | typedef struct { 87 | fe25519 YplusX; 88 | fe25519 YminusX; 89 | fe25519 Z; 90 | fe25519 T2d; 91 | } ge25519_cached; 92 | 93 | void ge25519_tobytes(unsigned char *s, const ge25519_p2 *h); 94 | 95 | void ge25519_p3_tobytes(unsigned char *s, const ge25519_p3 *h); 96 | 97 | int ge25519_frombytes(ge25519_p3 *h, const unsigned char *s); 98 | 99 | int ge25519_frombytes_negate_vartime(ge25519_p3 *h, const unsigned char *s); 100 | 101 | void ge25519_p3_to_cached(ge25519_cached *r, const ge25519_p3 *p); 102 | 103 | void ge25519_p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p); 104 | 105 | void ge25519_p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p); 106 | 107 | void ge25519_add(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q); 108 | 109 | void ge25519_sub(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q); 110 | 111 | void ge25519_scalarmult_base(ge25519_p3 *h, const unsigned char *a); 112 | 113 | void ge25519_double_scalarmult_vartime(ge25519_p2 *r, const unsigned char *a, 114 | const ge25519_p3 *A, 115 | const unsigned char *b); 116 | 117 | void ge25519_scalarmult(ge25519_p3 *h, const unsigned char *a, 118 | const ge25519_p3 *p); 119 | 120 | int ge25519_is_canonical(const unsigned char *s); 121 | 122 | int ge25519_is_on_curve(const ge25519_p3 *p); 123 | 124 | int ge25519_is_on_main_subgroup(const ge25519_p3 *p); 125 | 126 | int ge25519_has_small_order(const unsigned char s[32]); 127 | 128 | void ge25519_from_uniform(unsigned char s[32], const unsigned char r[32]); 129 | 130 | /* 131 | The set of scalars is \Z/l 132 | where l = 2^252 + 27742317777372353535851937790883648493. 133 | */ 134 | 135 | void sc25519_reduce(unsigned char *s); 136 | 137 | void sc25519_muladd(unsigned char *s, const unsigned char *a, 138 | const unsigned char *b, const unsigned char *c); 139 | 140 | int sc25519_is_canonical(const unsigned char *s); 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /src/tests/network_functions_test/network_daemon_functions_test/network_daemon_functions_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "define_macro_functions.h" 8 | #include "define_macros.h" 9 | #include "variables.h" 10 | #include "define_macros_test.h" 11 | 12 | #include "network_daemon_functions.h" 13 | #include "network_functions.h" 14 | #include "server_functions.h" 15 | #include "string_functions.h" 16 | #include "insert_database_functions.h" 17 | #include "delete_database_functions.h" 18 | #include "VRF_functions.h" 19 | 20 | #include "variables_test.h" 21 | #include "network_daemon_functions_test.h" 22 | 23 | /* 24 | ----------------------------------------------------------------------------------------------------------- 25 | Functions 26 | ----------------------------------------------------------------------------------------------------------- 27 | */ 28 | 29 | /* 30 | ----------------------------------------------------------------------------------------------------------- 31 | Name: network_daemon_functions_test 32 | Description: Test the network_daemon functions 33 | Return: The number of passed network_daemon functions test 34 | ----------------------------------------------------------------------------------------------------------- 35 | */ 36 | 37 | int network_daemon_functions_test(void) 38 | { 39 | // Variables 40 | char data[BUFFER_SIZE]; 41 | size_t count = 0; 42 | 43 | // reset the variables 44 | memset(data_test,0,sizeof(data_test)); 45 | count_test = 0; 46 | 47 | // write the start test message 48 | fprintf(stderr,"\033[1;34m%s\nnetwork daemon functions test - Total test: %d\n%s\n\n\033[0m",TEST_OUTLINE,NETWORK_DAEMON_FUNCTIONS_TEST,TEST_OUTLINE); 49 | 50 | // test the check_if_blockchain_is_fully_synced 51 | if (check_if_blockchain_is_fully_synced() == 1) 52 | { 53 | color_print("PASSED! Test for check_if_blockchain_is_fully_synced","green"); 54 | count_test++; 55 | } 56 | else 57 | { 58 | color_print("FAILED! Test for check_if_blockchain_is_fully_synced","red"); 59 | } 60 | 61 | // test the get_block_template function 62 | if (get_block_template(data_test) == 1) 63 | { 64 | color_print("PASSED! Test for get_block_template","green"); 65 | count_test++; 66 | } 67 | else 68 | { 69 | color_print("FAILED! Test for get_block_template","red"); 70 | } 71 | 72 | // test the submit_block_template function 73 | if (submit_block_template("XCASH_DPOPS") == 1) 74 | { 75 | color_print("PASSED! Test for submit_block_template","green"); 76 | count_test++; 77 | } 78 | else 79 | { 80 | color_print("FAILED! Test for submit_block_template","red"); 81 | } 82 | 83 | // test the get_current_block_height 84 | memset(data_test,0,sizeof(data_test)); 85 | if (get_current_block_height(data_test) == 1) 86 | { 87 | color_print("PASSED! Test for get_current_block_height","green"); 88 | count_test++; 89 | } 90 | else 91 | { 92 | color_print("FAILED! Test for get_current_block_height","red"); 93 | } 94 | 95 | // test get_block_reserve_byte_data_hash 96 | memset(result_test,0,sizeof(result_test)); 97 | sscanf(data_test,"%zu",&count); 98 | count--; 99 | memset(data_test,0,sizeof(data_test)); 100 | snprintf(data_test,sizeof(data_test)-1,"%zu",count); 101 | network_functions_test_error_settings = 0; 102 | get_block_reserve_byte_data_hash(result_test,data_test); 103 | network_functions_test_error_settings = 1; 104 | color_print("PASSED! Test for get_block_reserve_byte_data_hash","green"); 105 | count_test++; 106 | 107 | // test the get_previous_block_hash function 108 | memset(data_test,0,strnlen(data_test,BUFFER_SIZE)); 109 | if (get_previous_block_hash(data_test) == 1) 110 | { 111 | color_print("PASSED! Test for get_previous_block_hash","green"); 112 | count_test++; 113 | } 114 | else 115 | { 116 | color_print("FAILED! Test for get_previous_block_hash","red"); 117 | } 118 | 119 | // test the get_previous_block_information function 120 | memset(data_test,0,sizeof(data_test)); 121 | memset(result_test,0,sizeof(result_test)); 122 | memset(data,0,sizeof(data)); 123 | if (get_previous_block_information(result_test,data_test,data) == 1) 124 | { 125 | color_print("PASSED! Test for get_previous_block_information","green"); 126 | count_test++; 127 | } 128 | else 129 | { 130 | color_print("FAILED! Test for get_previous_block_information","red"); 131 | } 132 | 133 | // write the end test message 134 | fprintf(stderr,"\033[1;33m\n\n%s\nnetwork daemon functions test - Passed test: %d, Failed test: %d\n%s\n\n\n\033[0m",TEST_OUTLINE,count_test,NETWORK_DAEMON_FUNCTIONS_TEST-count_test,TEST_OUTLINE); 135 | return count_test; 136 | } -------------------------------------------------------------------------------- /src/functions/VRF_functions/convert.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 - 2019 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include "convert.h" 26 | #include "vrf.h" 27 | #include "sha512EL.h" 28 | #include "ed25519_ref10.h" 29 | 30 | static const unsigned char ONE = 0x01; 31 | static const unsigned char TWO = 0x02; 32 | 33 | /* Encode elliptic curve point into a 32-byte octet string per RFC8032 section 34 | * 5.1.2. 35 | */ 36 | void 37 | _vrf_ietfdraft03_point_to_string(unsigned char string[32], const ge25519_p3 *point) 38 | { 39 | ge25519_p3_tobytes(string, point); 40 | } 41 | 42 | /* Decode elliptic curve point from 32-byte octet string per RFC8032 section 43 | * 5.1.3. 44 | * 45 | * In particular we must reject non-canonical encodings (i.e., when the encoded 46 | * y coordinate is not reduced mod p). We do not check whether the point is on 47 | * the main subgroup or whether it is of low order. Returns 0 on success (and 48 | * stores decoded point in *point), nonzero if decoding fails. 49 | */ 50 | int 51 | _vrf_ietfdraft03_string_to_point(ge25519_p3 *point, const unsigned char string[32]) 52 | { 53 | if (ge25519_is_canonical(string) == 0 || 54 | ge25519_frombytes(point, string) != 0) { 55 | return -1; 56 | } 57 | return 0; 58 | } 59 | 60 | /* Hash a message to a curve point using Elligator2. 61 | * Specified in VRF draft spec section 5.4.1.2. 62 | * The actual elligator2 implementation is ge25519_from_uniform. 63 | * Runtime depends only on alphalen (the message length) 64 | */ 65 | void 66 | _vrf_ietfdraft03_hash_to_curve_elligator2_25519(unsigned char H_string[32], 67 | const ge25519_p3 *Y_point, 68 | const unsigned char *alpha, 69 | const unsigned long long alphalen) 70 | { 71 | crypto_hash_sha512_state hs; 72 | unsigned char Y_string[32]; 73 | unsigned char r_string[64]; 74 | 75 | _vrf_ietfdraft03_point_to_string(Y_string, Y_point); 76 | 77 | crypto_hash_sha512_init(&hs); 78 | crypto_hash_sha512_update(&hs, &SUITE, 1); 79 | crypto_hash_sha512_update(&hs, &ONE, 1); 80 | crypto_hash_sha512_update(&hs, Y_string, 32); 81 | crypto_hash_sha512_update(&hs, alpha, alphalen); 82 | crypto_hash_sha512_final(&hs, r_string); 83 | 84 | r_string[31] &= 0x7f; /* clear sign bit */ 85 | ge25519_from_uniform(H_string, r_string); /* elligator2 */ 86 | } 87 | 88 | /* Subroutine specified in draft spec section 5.4.3. 89 | * Hashes four points to a 16-byte string. 90 | * Constant time. */ 91 | void 92 | _vrf_ietfdraft03_hash_points(unsigned char c[16], const ge25519_p3 *P1, 93 | const ge25519_p3 *P2, const ge25519_p3 *P3, 94 | const ge25519_p3 *P4) 95 | { 96 | unsigned char str[2+32*4]; 97 | unsigned char c1[64]; 98 | 99 | str[0] = SUITE; 100 | str[1] = TWO; 101 | _vrf_ietfdraft03_point_to_string(str+2+32*0, P1); 102 | _vrf_ietfdraft03_point_to_string(str+2+32*1, P2); 103 | _vrf_ietfdraft03_point_to_string(str+2+32*2, P3); 104 | _vrf_ietfdraft03_point_to_string(str+2+32*3, P4); 105 | crypto_hash_sha512(c1, str, sizeof str); 106 | memmove(c, c1, 16); 107 | memset(c1, 0, 64); 108 | } 109 | 110 | /* Decode an 80-byte proof pi into a point gamma, a 16-byte scalar c, and a 111 | * 32-byte scalar s, as specified in IETF draft section 5.4.4. 112 | * Returns 0 on success, nonzero on failure. 113 | */ 114 | int 115 | _vrf_ietfdraft03_decode_proof(ge25519_p3 *Gamma, unsigned char c[16], 116 | unsigned char s[32], const unsigned char pi[80]) 117 | { 118 | /* gamma = decode_point(pi[0:32]) */ 119 | if (_vrf_ietfdraft03_string_to_point(Gamma, pi) != 0) { 120 | return -1; 121 | } 122 | memmove(c, pi+32, 16); /* c = pi[32:48] */ 123 | memmove(s, pi+48, 32); /* s = pi[48:80] */ 124 | return 0; 125 | } 126 | -------------------------------------------------------------------------------- /scripts/firewall/firewall_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # iptables script for server 3 | # if you changed any default ports change them in the firewall as well 4 | 5 | # ACCEPT all packets at the top so each packet runs through the firewall rules, then DROP all INPUT and FORWARD if they dont use any of the firewall settings 6 | iptables -P INPUT ACCEPT 7 | iptables -P FORWARD ACCEPT 8 | iptables -P OUTPUT ACCEPT 9 | # remove all existing IP tables 10 | iptables -t nat -F 11 | iptables -t mangle -F 12 | iptables -t mangle -X 13 | iptables -t mangle -F 14 | iptables -t raw -F 15 | iptables -t raw -X 16 | iptables -F 17 | iptables -X 18 | 19 | # ip table prerouting data (this is where you want to block ddos attacks) 20 | # Drop all invalid packets 21 | iptables -t mangle -A PREROUTING -m conntrack --ctstate INVALID -j DROP 22 | # Prevent syn flood 23 | iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP 24 | iptables -t mangle -A PREROUTING -p tcp -m conntrack --ctstate NEW -m tcpmss ! --mss 536:65535 -j DROP 25 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP 26 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN FIN,SYN -j DROP 27 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags SYN,RST SYN,RST -j DROP 28 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,RST FIN,RST -j DROP 29 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,ACK FIN -j DROP 30 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,URG URG -j DROP 31 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,FIN FIN -j DROP 32 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,PSH PSH -j DROP 33 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL ALL -j DROP 34 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL NONE -j DROP 35 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP 36 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,FIN,PSH,URG -j DROP 37 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP 38 | 39 | # filter data for INPUT, FORWARD, and OUTPUT 40 | # Accept any packets coming or going on localhost 41 | iptables -I INPUT -i lo -j ACCEPT 42 | # keep already established connections running 43 | iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 44 | 45 | # block ip spoofing. these are the ranges of local IP address. 46 | iptables -A INPUT -s 10.12.242.0/24 -j ACCEPT 47 | iptables -A INPUT -s 10.0.0.0/8 -j DROP 48 | iptables -A INPUT -s 169.254.0.0/16 -j DROP 49 | iptables -A INPUT -s 172.16.0.0/12 -j DROP 50 | iptables -A INPUT -s 127.0.0.0/8 -j DROP 51 | iptables -A INPUT -s 192.168.0.0/24 -j DROP 52 | iptables -A INPUT -s 224.0.0.0/4 -j DROP 53 | iptables -A INPUT -d 224.0.0.0/4 -j DROP 54 | iptables -A INPUT -s 240.0.0.0/5 -j DROP 55 | iptables -A INPUT -d 240.0.0.0/5 -j DROP 56 | iptables -A INPUT -s 0.0.0.0/8 -j DROP 57 | iptables -A INPUT -d 0.0.0.0/8 -j DROP 58 | iptables -A INPUT -d 239.255.255.0/24 -j DROP 59 | iptables -A INPUT -d 255.255.255.255 -j DROP 60 | 61 | # block all traffic from ip address (iptables -A INPUT -s ipaddress -j DROP) 62 | #unblock them using iptables -D INPUT -s ipaddress -j DROP 63 | 64 | # Block different attacks 65 | # block one computer from opening too many connections (100 simultaneous connections) if this gives trouble with post remove this or increase the limit 66 | # iptables -t filter -I INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 100 --connlimit-mask 32 -j DROP 67 | iptables -t filter -I INPUT -p tcp --syn --dport 18283 -m connlimit --connlimit-above 100 --connlimit-mask 32 -j DROP 68 | # block port scans 69 | # this will lock the IP out for 1 day 70 | iptables -A INPUT -m recent --name portscan --rcheck --seconds 86400 -j DROP 71 | iptables -A FORWARD -m recent --name portscan --rcheck --seconds 86400 -j DROP 72 | iptables -A INPUT -m recent --name portscan --remove 73 | iptables -A FORWARD -m recent --name portscan --remove 74 | iptables -A INPUT -p tcp -m tcp -m multiport --destination-ports 21,25,110,135,139,143,445,1433,3306,3389 -m recent --name portscan --set -j DROP 75 | iptables -A FORWARD -p tcp -m tcp -m multiport --destination-ports 21,25,110,135,139,143,445,1433,3306,3389 -m recent --name portscan --set -j DROP 76 | 77 | # Accept specific packets 78 | # Accept ICMP 79 | iptables -A INPUT -p icmp -j ACCEPT 80 | 81 | # Accept HTTP 82 | # iptables -A INPUT -p tcp --dport 80 -j ACCEPT 83 | 84 | 85 | # Accept XCASH 86 | iptables -A INPUT -p tcp --dport 18280 -j ACCEPT 87 | iptables -A INPUT -p tcp --dport 18281 -j ACCEPT 88 | iptables -A INPUT -p tcp --dport 18283 -j ACCEPT 89 | 90 | # Allow ssh (allow 100 login attempts in 1 hour from the same ip, if more than ban them for 1 hour) 91 | iptables -A INPUT -p tcp -m tcp --dport ${SSH_PORT_NUMBER} -m state --state NEW -m recent --set --name DEFAULT --rsource 92 | iptables -A INPUT -p tcp -m tcp --dport ${SSH_PORT_NUMBER} -m state --state NEW -m recent --update --seconds 3600 --hitcount 100 --name DEFAULT --rsource -j DROP 93 | iptables -A INPUT -p tcp -m tcp --dport ${SSH_PORT_NUMBER} -j ACCEPT 94 | 95 | # DROP all INPUT and FORWARD packets if they have reached this point 96 | iptables -A INPUT -j DROP 97 | iptables -A FORWARD -j DROP 98 | -------------------------------------------------------------------------------- /scripts/firewall/firewall_shared_delegates_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # iptables script for server 3 | # if you changed any default ports change them in the firewall as well 4 | 5 | # ACCEPT all packets at the top so each packet runs through the firewall rules, then DROP all INPUT and FORWARD if they dont use any of the firewall settings 6 | iptables -P INPUT ACCEPT 7 | iptables -P FORWARD ACCEPT 8 | iptables -P OUTPUT ACCEPT 9 | # remove all existing IP tables 10 | iptables -t nat -F 11 | iptables -t mangle -F 12 | iptables -t mangle -X 13 | iptables -t mangle -F 14 | iptables -t raw -F 15 | iptables -t raw -X 16 | iptables -F 17 | iptables -X 18 | 19 | # ip table prerouting data (this is where you want to block ddos attacks) 20 | # Drop all invalid packets 21 | iptables -t mangle -A PREROUTING -m conntrack --ctstate INVALID -j DROP 22 | # Prevent syn flood 23 | iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP 24 | iptables -t mangle -A PREROUTING -p tcp -m conntrack --ctstate NEW -m tcpmss ! --mss 536:65535 -j DROP 25 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN,RST,PSH,ACK,URG NONE -j DROP 26 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,SYN FIN,SYN -j DROP 27 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags SYN,RST SYN,RST -j DROP 28 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,RST FIN,RST -j DROP 29 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags FIN,ACK FIN -j DROP 30 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,URG URG -j DROP 31 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,FIN FIN -j DROP 32 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ACK,PSH PSH -j DROP 33 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL ALL -j DROP 34 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL NONE -j DROP 35 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP 36 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,FIN,PSH,URG -j DROP 37 | iptables -t mangle -A PREROUTING -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP 38 | 39 | # filter data for INPUT, FORWARD, and OUTPUT 40 | # Accept any packets coming or going on localhost 41 | iptables -I INPUT -i lo -j ACCEPT 42 | # keep already established connections running 43 | iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 44 | 45 | # block ip spoofing. these are the ranges of local IP address. 46 | iptables -A INPUT -s 10.12.242.0/24 -j ACCEPT 47 | iptables -A INPUT -s 10.0.0.0/8 -j DROP 48 | iptables -A INPUT -s 169.254.0.0/16 -j DROP 49 | iptables -A INPUT -s 172.16.0.0/12 -j DROP 50 | iptables -A INPUT -s 127.0.0.0/8 -j DROP 51 | iptables -A INPUT -s 192.168.0.0/24 -j DROP 52 | iptables -A INPUT -s 224.0.0.0/4 -j DROP 53 | iptables -A INPUT -d 224.0.0.0/4 -j DROP 54 | iptables -A INPUT -s 240.0.0.0/5 -j DROP 55 | iptables -A INPUT -d 240.0.0.0/5 -j DROP 56 | iptables -A INPUT -s 0.0.0.0/8 -j DROP 57 | iptables -A INPUT -d 0.0.0.0/8 -j DROP 58 | iptables -A INPUT -d 239.255.255.0/24 -j DROP 59 | iptables -A INPUT -d 255.255.255.255 -j DROP 60 | 61 | # block all traffic from ip address (iptables -A INPUT -s ipaddress -j DROP) 62 | #unblock them using iptables -D INPUT -s ipaddress -j DROP 63 | 64 | # Block different attacks 65 | # block one computer from opening too many connections (100 simultaneous connections) if this gives trouble with post remove this or increase the limit 66 | iptables -t filter -I INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 100 --connlimit-mask 32 -j DROP 67 | iptables -t filter -I INPUT -p tcp --syn --dport 18283 -m connlimit --connlimit-above 100 --connlimit-mask 32 -j DROP 68 | # block port scans 69 | # this will lock the IP out for 1 day 70 | iptables -A INPUT -m recent --name portscan --rcheck --seconds 86400 -j DROP 71 | iptables -A FORWARD -m recent --name portscan --rcheck --seconds 86400 -j DROP 72 | iptables -A INPUT -m recent --name portscan --remove 73 | iptables -A FORWARD -m recent --name portscan --remove 74 | iptables -A INPUT -p tcp -m tcp -m multiport --destination-ports 21,25,110,135,139,143,445,1433,3306,3389 -m recent --name portscan --set -j DROP 75 | iptables -A FORWARD -p tcp -m tcp -m multiport --destination-ports 21,25,110,135,139,143,445,1433,3306,3389 -m recent --name portscan --set -j DROP 76 | 77 | # Accept specific packets 78 | # Accept ICMP 79 | iptables -A INPUT -p icmp -j ACCEPT 80 | 81 | # Accept HTTP 82 | iptables -A INPUT -p tcp --dport 80 -j ACCEPT 83 | 84 | 85 | # Accept XCASH 86 | iptables -A INPUT -p tcp --dport 18280 -j ACCEPT 87 | iptables -A INPUT -p tcp --dport 18281 -j ACCEPT 88 | iptables -A INPUT -p tcp --dport 18283 -j ACCEPT 89 | 90 | # Allow ssh (allow 100 login attempts in 1 hour from the same ip, if more than ban them for 1 hour) 91 | iptables -A INPUT -p tcp -m tcp --dport ${SSH_PORT_NUMBER} -m state --state NEW -m recent --set --name DEFAULT --rsource 92 | iptables -A INPUT -p tcp -m tcp --dport ${SSH_PORT_NUMBER} -m state --state NEW -m recent --update --seconds 3600 --hitcount 100 --name DEFAULT --rsource -j DROP 93 | iptables -A INPUT -p tcp -m tcp --dport ${SSH_PORT_NUMBER} -j ACCEPT 94 | 95 | # Redirect HTTP to port 18283 96 | iptables -A PREROUTING -t nat -i ${DEFAULT_NETWORK_DEVICE} -p tcp --dport 80 -j REDIRECT --to-ports 18283 97 | 98 | # DROP all INPUT and FORWARD packets if they have reached this point 99 | iptables -A INPUT -j DROP 100 | iptables -A FORWARD -j DROP 101 | -------------------------------------------------------------------------------- /src/tests/file_functions_test/file_functions_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "define_macro_functions.h" 7 | #include "define_macros.h" 8 | #include "structures.h" 9 | #include "define_macros_test.h" 10 | 11 | #include "file_functions.h" 12 | #include "thread_functions.h" 13 | 14 | #include "variables_test.h" 15 | #include "file_functions_test.h" 16 | #include 17 | #include 18 | 19 | /* 20 | ----------------------------------------------------------------------------------------------------------- 21 | Functions 22 | ----------------------------------------------------------------------------------------------------------- 23 | */ 24 | 25 | /* 26 | ----------------------------------------------------------------------------------------------------------- 27 | Name: file_functions_test 28 | Description: Test the read_file and write_file functions 29 | Return: The number of passed file_functions test 30 | ----------------------------------------------------------------------------------------------------------- 31 | */ 32 | 33 | int file_functions_test(void) 34 | { 35 | // Variables 36 | pthread_t thread_id; 37 | 38 | // define macros 39 | #define NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY "nodes_public_address_list_copy.txt" 40 | #define MESSAGE "XCASH_PROOF_OF_STAKE_TEST_DATA" 41 | 42 | // reset the variables 43 | memset(data_test,0,strlen(data_test)); 44 | memset(result_test,0,strlen(result_test)); 45 | count_test = 0; 46 | 47 | // write the start test message 48 | fprintf(stderr,"\033[1;34m%s\nfile functions test - Total test: %d\n%s\n\n\033[0m",TEST_OUTLINE,FILE_FUNCTIONS_TOTAL_TEST,TEST_OUTLINE); 49 | 50 | // run the test 51 | 52 | // write the file 53 | memcpy(data_test,MESSAGE,sizeof(MESSAGE)-1); 54 | if (write_file(data_test,NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY) == 0) 55 | { 56 | color_print("FAILED! Test for writing the file","red"); 57 | } 58 | else 59 | { 60 | color_print("PASSED! Test for writing the file","green"); 61 | count_test++; 62 | } 63 | 64 | // get the file size 65 | if (get_file_size(NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY) == sizeof(MESSAGE)-1) 66 | { 67 | color_print("PASSED! Test for getting the file size","green"); 68 | count_test++; 69 | } 70 | else 71 | { 72 | color_print("FAILED! Test for getting the file size","red"); 73 | } 74 | 75 | // append and read the file 76 | if (append_file("|",NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY) == 0 || append_file(data_test,NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY) == 0 || read_file((unsigned char*)result_test,NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY) == 0 || strncmp(result_test,"XCASH_PROOF_OF_STAKE_TEST_DATA|XCASH_PROOF_OF_STAKE_TEST_DATA",61) != 0) 77 | { 78 | color_print("FAILED! Test for appending the file","red"); 79 | color_print("FAILED! Test for reading the file","red"); 80 | } 81 | else 82 | { 83 | color_print("PASSED! Test for appending the file","green"); 84 | color_print("PASSED! Test for reading the file","green"); 85 | count_test += 2; 86 | } 87 | remove(NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY); 88 | 89 | 90 | 91 | // write the file using a seperate thread 92 | // create a struct for the parameters 93 | struct write_file_thread_parameters write_file_thread_parameters = {MESSAGE,NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY}; 94 | pthread_create(&thread_id, NULL, &write_file_thread,(void *)&write_file_thread_parameters); 95 | if (thread_settings(thread_id) == 0) 96 | { 97 | color_print("FAILED! Test for writing the file on a seperate thread","red"); 98 | } 99 | else 100 | { 101 | color_print("PASSED! Test for writing the file on a seperate thread","green"); 102 | count_test++; 103 | } 104 | 105 | // append the file 106 | memset(result_test,0,strnlen(result_test,BUFFER_SIZE)); 107 | memset(data_test,0,strnlen(data_test,BUFFER_SIZE)); 108 | memcpy(data_test,"|XCASH_PROOF_OF_STAKE_TEST_DATA",31); 109 | struct append_file_thread_parameters append_file_thread_parameters = {data_test,NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY}; 110 | pthread_create(&thread_id, NULL, &append_file_thread,(void *)&append_file_thread_parameters); 111 | if (thread_settings(thread_id) == 0 || read_file((unsigned char*)result_test,NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY) == 0 || strncmp(result_test,"XCASH_PROOF_OF_STAKE_TEST_DATA|XCASH_PROOF_OF_STAKE_TEST_DATA",61) != 0) 112 | { 113 | color_print("FAILED! Test for appending the file on a seperate thread","red"); 114 | } 115 | else 116 | { 117 | color_print("PASSED! Test for appending the file on a seperate thread","green"); 118 | count_test++; 119 | } 120 | 121 | // read the file 122 | memset(data_test,0,strnlen(data_test,BUFFER_SIZE)); 123 | struct read_file_thread_parameters read_file_thread_parameters = {(unsigned char*)data_test,NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY}; 124 | pthread_create(&thread_id, NULL, &read_file_thread,(void *)&read_file_thread_parameters); 125 | if (thread_settings(thread_id) == 0) 126 | { 127 | color_print("FAILED! Test for reading the file on a seperate thread","red"); 128 | } 129 | else 130 | { 131 | color_print("PASSED! Test for reading the file on a seperate thread","green"); 132 | count_test++; 133 | } 134 | remove(NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY); 135 | 136 | 137 | 138 | // write the end test message 139 | fprintf(stderr,"\033[1;33m\n\n%s\nfile functions test - Passed test: %d, Failed test: %d\n%s\n\n\n\033[0m",TEST_OUTLINE,count_test,FILE_FUNCTIONS_TOTAL_TEST-count_test,TEST_OUTLINE); 140 | return count_test; 141 | 142 | #undef NODES_PUBLIC_ADDRESS_LIST_FILE_NAME_COPY 143 | #undef MESSAGE 144 | } -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Color print variables 2 | COLOR_PRINT_RED ?= "\033[1;31m" 3 | COLOR_PRINT_GREEN ?= "\033[1;32m" 4 | END_COLOR_PRINT ?= "\033[0m" 5 | 6 | # List the current file count and how many files total it is building 7 | ifndef PRINT_CURRENT_FILE 8 | TOTAL_FILES := $(shell $(MAKE) $(MAKECMDGOALS) --no-print-directory -nrRf $(firstword $(MAKEFILE_LIST)) PRINT_CURRENT_FILE="COUNTTHIS" | grep -c "COUNTTHIS") 9 | N := x 10 | CURRENT_FILE = $(words $N)$(eval N := x $N) 11 | PRINT_CURRENT_FILE = echo -ne $(COLOR_PRINT_GREEN)"\r Currently Building File" $(CURRENT_FILE) "Out Of" $(TOTAL_FILES)":"$(END_COLOR_PRINT) 12 | endif 13 | 14 | # The binary name 15 | TARGET_BINARY ?= xcash-dpops 16 | 17 | # The build directory, where the target binary will be stored 18 | BUILD_DIR ?= ./build 19 | 20 | # The source directory, where the 21 | SRC_DIRS ?= ./src 22 | 23 | # List all source files (check for every C++, C or assembly file) 24 | SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s) 25 | 26 | # Create an object file for every source file 27 | OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) 28 | 29 | # Create a dependency file for every object file 30 | DEPS := $(OBJS:.o=.d) 31 | 32 | # Dont include any of the dependency files into the main make file, since the main make file will create all object files 33 | -include $(DEPS) 34 | 35 | # List all directories that contain source files 36 | INC_DIRS := $(shell find $(SRC_DIRS) -type d) 37 | 38 | # Prefix all source directories with -I 39 | INC_FLAGS := $(addprefix -I,$(INC_DIRS)) 40 | 41 | # MongoDB include directories 42 | MongoDB_INC_DIRS := -I/usr/local/include/libbson-1.0 -I/usr/local/include/libmongoc-1.0 43 | 44 | # C flags 45 | CFLAGS ?= $(INC_FLAGS) $(MongoDB_INC_DIRS) -MMD -MP 46 | 47 | # Linker flags 48 | LDFLAGS ?= -lmongoc-1.0 -lbson-1.0 -lresolv -lpthread -lcrypto 49 | 50 | # Set the compiler flags 51 | COMPILERFLAGS ?= -Wall -Wextra -Wstrict-prototypes -Wcast-qual -Wfloat-equal -Wundef -Wshadow -Wcast-align -Wstrict-overflow -Wdouble-promotion -fexceptions -pie -fPIE -Wl,dynamicbase -Wl,nxcompat 52 | 53 | # Set the compiler and linker flags for the different options 54 | debug: COMPILERFLAGS += -g -fno-stack-protector 55 | release: COMPILERFLAGS += -O3 56 | optimized: COMPILERFLAGS += -march=native -O3 57 | analyze: COMPILERFLAGS += -g -Og -fsanitize=address -fno-omit-frame-pointer -fsanitize=leak -fsanitize=undefined -fsanitize=shift -fsanitize=bounds -fsanitize=shift-base -fsanitize=integer-divide-by-zero -fsanitize=unreachable -fsanitize=vla-bound -fsanitize=null -fsanitize=return -fsanitize=signed-integer-overflow -fsanitize=bounds -fsanitize=bounds-strict -fsanitize=alignment -fsanitize=object-size -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fsanitize=nonnull-attribute -fsanitize=returns-nonnull-attribute -fsanitize=bool -fsanitize=enum -fsanitize=vptr 58 | analyze: LDFLAGS += -fsanitize=address -fno-omit-frame-pointer -fsanitize=leak -fsanitize=undefined -fsanitize=shift -fsanitize=bounds -fsanitize=shift-base -fsanitize=integer-divide-by-zero -fsanitize=unreachable -fsanitize=vla-bound -fsanitize=null -fsanitize=return -fsanitize=signed-integer-overflow -fsanitize=bounds -fsanitize=bounds-strict -fsanitize=alignment -fsanitize=object-size -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fsanitize=nonnull-attribute -fsanitize=returns-nonnull-attribute -fsanitize=bool -fsanitize=enum -fsanitize=vptr 59 | analyzethreads: COMPILERFLAGS += -g -fsanitize=thread -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=shift -fsanitize=bounds -fsanitize=shift-base -fsanitize=integer-divide-by-zero -fsanitize=unreachable -fsanitize=vla-bound -fsanitize=null -fsanitize=return -fsanitize=signed-integer-overflow -fsanitize=bounds -fsanitize=bounds-strict -fsanitize=alignment -fsanitize=object-size -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fsanitize=nonnull-attribute -fsanitize=returns-nonnull-attribute -fsanitize=bool -fsanitize=enum -fsanitize=vptr 60 | analyzethreads: LDFLAGS += -fsanitize=thread -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=shift -fsanitize=bounds -fsanitize=shift-base -fsanitize=integer-divide-by-zero -fsanitize=unreachable -fsanitize=vla-bound -fsanitize=null -fsanitize=return -fsanitize=signed-integer-overflow -fsanitize=bounds -fsanitize=bounds-strict -fsanitize=alignment -fsanitize=object-size -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fsanitize=nonnull-attribute -fsanitize=returns-nonnull-attribute -fsanitize=bool -fsanitize=enum -fsanitize=vptr 61 | 62 | # Build all of the assembly objects files 63 | $(BUILD_DIR)/%.s.o: %.s 64 | mkdir -p $(dir $@) 65 | @$(PRINT_CURRENT_FILE) $@ 66 | $(AS) $(ASFLAGS) -c $< -o $@ 67 | 68 | # Build all of the C objects files 69 | $(BUILD_DIR)/%.c.o: %.c 70 | @mkdir -p $(dir $@) 71 | @$(PRINT_CURRENT_FILE) $@ 72 | @$(CC) $(COMPILERFLAGS) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ 73 | 74 | # Build all of the C++ objects files 75 | $(BUILD_DIR)/%.cpp.o: %.cpp 76 | mkdir -p $(dir $@) 77 | @$(PRINT_CURRENT_FILE) $@ 78 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ 79 | 80 | # Set the debug and release rules to phony, since they just change the compiler flags variable and dont create any files. Set the clean rule to phony since we want it to run the command everytime we run it 81 | .PHONY: debug release clean 82 | 83 | # Set the options to do the same thing, since the only difference is the compiler flags 84 | debug: $(BUILD_DIR)/$(TARGET_BINARY) 85 | release: $(BUILD_DIR)/$(TARGET_BINARY) 86 | optimized: $(BUILD_DIR)/$(TARGET_BINARY) 87 | analyze: $(BUILD_DIR)/$(TARGET_BINARY) 88 | analyzethreads: $(BUILD_DIR)/$(TARGET_BINARY) 89 | 90 | # Link all of the objects files 91 | $(BUILD_DIR)/$(TARGET_BINARY): $(OBJS) 92 | @$(CC) $(OBJS) -o $@ $(LDFLAGS) 93 | @echo "\n" $(COLOR_PRINT_GREEN)$(TARGET_BINARY) "Has Been Built Successfully"$(END_COLOR_PRINT) 94 | 95 | # Remove the build directory 96 | clean: 97 | @$(RM) -r $(BUILD_DIR) 98 | @echo $(COLOR_PRINT_RED) "Removed" $(BUILD_DIR)$(END_COLOR_PRINT) 99 | -------------------------------------------------------------------------------- /src/functions/database_functions/count_database_functions/count_database_functions.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "define_macro_functions.h" 7 | #include "define_macros.h" 8 | #include "structures.h" 9 | #include "variables.h" 10 | 11 | #include "count_database_functions.h" 12 | #include "database_functions.h" 13 | #include "network_functions.h" 14 | #include "string_functions.h" 15 | #include "vrf.h" 16 | #include "crypto_vrf.h" 17 | #include "VRF_functions.h" 18 | #include "sha512EL.h" 19 | 20 | /* 21 | ----------------------------------------------------------------------------------------------------------- 22 | Functions 23 | ----------------------------------------------------------------------------------------------------------- 24 | */ 25 | 26 | /* 27 | ----------------------------------------------------------------------------------------------------------- 28 | Name: count_documents_in_collection 29 | Description: Counts the documents in the collection that match a specific field name and field 30 | Parameters: 31 | DATABASE - The database name 32 | COLLECTION - The collection name 33 | DATA - The json data to use to search the collection for 34 | Return: -1 if an error has occured, otherwise the amount of documents that match a specific field name and field in the collection 35 | ----------------------------------------------------------------------------------------------------------- 36 | */ 37 | 38 | int count_documents_in_collection(const char* DATABASE, const char* COLLECTION, const char* DATA) 39 | { 40 | // Variables 41 | mongoc_client_t* database_client_thread = NULL; 42 | mongoc_collection_t* collection; 43 | bson_error_t error; 44 | bson_t* document = NULL; 45 | 46 | // define macros 47 | #define database_reset_all \ 48 | bson_destroy(document); \ 49 | mongoc_collection_destroy(collection); \ 50 | mongoc_client_pool_push(database_client_thread_pool, database_client_thread); 51 | 52 | #define COUNT_DOCUMENTS_IN_COLLECTION_ERROR(settings) \ 53 | if ((strncmp(settings,"The database collection does not exist",BUFFER_SIZE) == 0 && test_settings == 1) || (strncmp(settings,"The database collection does not exist",BUFFER_SIZE) != 0)) \ 54 | { \ 55 | memcpy(error_message.function[error_message.total],"count_documents_in_collection",29); \ 56 | memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \ 57 | error_message.total++; \ 58 | } \ 59 | database_reset_all; \ 60 | return -1; 61 | 62 | // get a temporary connection 63 | if (!(database_client_thread = mongoc_client_pool_pop(database_client_thread_pool))) 64 | { 65 | return -1; 66 | } 67 | 68 | // set the collection 69 | collection = mongoc_client_get_collection(database_client_thread, DATABASE, COLLECTION); 70 | 71 | // check if the database collection exist 72 | if (check_if_database_collection_exist(DATABASE,COLLECTION) == 0) 73 | { 74 | COUNT_DOCUMENTS_IN_COLLECTION_ERROR("The database collection does not exist"); 75 | } 76 | 77 | if (!(document = bson_new_from_json((const uint8_t *)DATA, -1, &error))) 78 | { 79 | COUNT_DOCUMENTS_IN_COLLECTION_ERROR("Could not convert the data into a database document"); 80 | } 81 | 82 | const int COUNT = (int)mongoc_collection_count_documents(collection, document, NULL, NULL, NULL, &error); 83 | database_reset_all; 84 | return COUNT; 85 | 86 | #undef database_reset_all 87 | #undef COUNT_DOCUMENTS_IN_COLLECTION_ERROR 88 | } 89 | 90 | 91 | 92 | /* 93 | ----------------------------------------------------------------------------------------------------------- 94 | Name: count_all_documents_in_collection 95 | Description: Counts all the documents in the collection 96 | Parameters: 97 | DATABASE - The database name 98 | COLLECTION - The collection name 99 | Return: -1 if an error has occured, otherwise the amount of documents in the collection 100 | ----------------------------------------------------------------------------------------------------------- 101 | */ 102 | 103 | int count_all_documents_in_collection(const char* DATABASE, const char* COLLECTION) 104 | { 105 | // Variables 106 | mongoc_client_t* database_client_thread = NULL; 107 | mongoc_collection_t* collection; 108 | bson_error_t error; 109 | bson_t* document = NULL; 110 | 111 | // define macros 112 | #define database_reset_all \ 113 | bson_destroy(document); \ 114 | mongoc_collection_destroy(collection); \ 115 | mongoc_client_pool_push(database_client_thread_pool, database_client_thread); 116 | 117 | #define COUNT_ALL_DOCUMENTS_IN_COLLECTION_ERROR(settings) \ 118 | if ((strncmp(settings,"The database collection does not exist",BUFFER_SIZE) == 0 && test_settings == 1) || (strncmp(settings,"The database collection does not exist",BUFFER_SIZE) != 0)) \ 119 | { \ 120 | memcpy(error_message.function[error_message.total],"count_all_documents_in_collection",33); \ 121 | memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \ 122 | error_message.total++; \ 123 | } \ 124 | database_reset_all; \ 125 | return -1; 126 | 127 | // get a temporary connection 128 | if (!(database_client_thread = mongoc_client_pool_pop(database_client_thread_pool))) 129 | { 130 | return -1; 131 | } 132 | 133 | // set the collection 134 | collection = mongoc_client_get_collection(database_client_thread, DATABASE, COLLECTION); 135 | 136 | // check if the database collection exist 137 | if (check_if_database_collection_exist(DATABASE,COLLECTION) == 0) 138 | { 139 | COUNT_ALL_DOCUMENTS_IN_COLLECTION_ERROR("The database collection does not exist"); 140 | } 141 | 142 | if (!(document = bson_new())) 143 | { 144 | COUNT_ALL_DOCUMENTS_IN_COLLECTION_ERROR("Could not convert the data into a database document"); 145 | } 146 | 147 | const int COUNT = (int)mongoc_collection_count_documents(collection, document, NULL, NULL, NULL, &error); 148 | database_reset_all; 149 | return COUNT; 150 | 151 | #undef database_reset_all 152 | #undef COUNT_ALL_DOCUMENTS_IN_COLLECTION_ERROR 153 | } -------------------------------------------------------------------------------- /src/tests/database_functions_test/count_database_functions_test/count_database_functions_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "define_macro_functions.h" 6 | #include "define_macros_test.h" 7 | 8 | #include "insert_database_functions.h" 9 | #include "count_database_functions.h" 10 | #include "delete_database_functions.h" 11 | #include "thread_functions.h" 12 | 13 | #include "variables_test.h" 14 | #include "count_database_functions_test.h" 15 | 16 | /* 17 | ----------------------------------------------------------------------------------------------------------- 18 | Functions 19 | ----------------------------------------------------------------------------------------------------------- 20 | */ 21 | 22 | /* 23 | ----------------------------------------------------------------------------------------------------------- 24 | Name: count_database_functions_test 25 | Description: Test the count database functions 26 | Return: The number of passed count database functions test 27 | ----------------------------------------------------------------------------------------------------------- 28 | */ 29 | 30 | int count_database_functions_test(void) 31 | { 32 | // Variables 33 | pthread_t thread_id; 34 | 35 | // define macros 36 | #define MESSAGE "{\"message_settings\": \"XCASH_DPOPS_TEST_DATA\"}" 37 | 38 | delete_collection_from_database(database_name,DATABASE_COLLECTION_TEST); 39 | insert_document_into_collection_json(database_name,DATABASE_COLLECTION_TEST,MESSAGE); 40 | 41 | // reset the variables 42 | count_test = 0; 43 | 44 | // write the start test message 45 | fprintf(stderr,"\033[1;34m%s\ncount database functions test - Total test: %d\n%s\n\n\033[0m",TEST_OUTLINE,COUNT_DATABASE_FUNCTIONS_TEST,TEST_OUTLINE); 46 | 47 | // count how many documents have "message_settings":"XCASH_DPOPS_TEST_DATA" in the collection 48 | int count1 = count_documents_in_collection(database_name,DATABASE_COLLECTION_TEST,MESSAGE); 49 | int count2 = count_all_documents_in_collection(database_name,DATABASE_COLLECTION_TEST); 50 | if ((count1 == count2) && (count1 != -1 || count2 != -1)) 51 | { 52 | color_print("PASSED! Test for count_documents_in_collection","green"); 53 | color_print("PASSED! Test for count_all_documents_in_collection","green"); 54 | count_test+= 2; 55 | } 56 | else 57 | { 58 | color_print("FAILED! Test for count_documents_in_collection","red"); 59 | color_print("FAILED! Test for count_all_documents_in_collection","red"); 60 | } 61 | 62 | // count how many documents have "message_settings":"XCASH_DPOPS_TEST_DATA" in the collection on a separate thread 63 | struct count_documents_in_collection_thread_parameters count_documents_in_collection_thread_parameters = {database_name,DATABASE_COLLECTION_TEST,MESSAGE}; 64 | pthread_create(&thread_id, NULL, &count_documents_in_collection_thread,(void *)&count_documents_in_collection_thread_parameters); 65 | count1 = thread_settings(thread_id); 66 | struct count_all_documents_in_collection_thread_parameters count_all_documents_in_collection_thread_parameters = {database_name,DATABASE_COLLECTION_TEST}; 67 | pthread_create(&thread_id, NULL, &count_all_documents_in_collection_thread,(void *)&count_all_documents_in_collection_thread_parameters); 68 | count2 = thread_settings(thread_id); 69 | if ((count1 == count2) && (count1 != -1 || count2 != -1)) 70 | { 71 | color_print("PASSED! Test for count_documents_in_collection_thread","green"); 72 | color_print("PASSED! Test for count_all_documents_in_collection_thread","green"); 73 | count_test+= 2; 74 | } 75 | else 76 | { 77 | color_print("FAILED! Test for count_documents_in_collection_thread","red"); 78 | color_print("FAILED! Test for count_all_documents_in_collection_thread","red"); 79 | } 80 | 81 | 82 | 83 | // check all errors for each test 84 | delete_collection_from_database(database_name,DATABASE_COLLECTION_TEST); 85 | RESET_ERROR_MESSAGES; 86 | 87 | // count_documents_in_collection 88 | if (count_documents_in_collection(database_name,DATABASE_COLLECTION_TEST,MESSAGE) == -1 && strncmp(error_message.data[0],"The database collection does not exist",BUFFER_SIZE) == 0) 89 | { 90 | color_print("PASSED! Test for count_documents_in_collection checking for The database collection does not exist","green"); 91 | count_test++; 92 | } 93 | else 94 | { 95 | color_print("FAILED! Test for count_documents_in_collection checking for The database collection does not exist","red"); 96 | } 97 | insert_document_into_collection_json(database_name,DATABASE_COLLECTION_TEST,MESSAGE); 98 | RESET_ERROR_MESSAGES; 99 | 100 | if (count_documents_in_collection(database_name,DATABASE_COLLECTION_TEST,"data") == -1 && strncmp(error_message.data[0],"Could not convert the data into a database document",BUFFER_SIZE) == 0) 101 | { 102 | color_print("PASSED! Test for count_documents_in_collection checking for Could not convert the data into a database document","green"); 103 | count_test++; 104 | } 105 | else 106 | { 107 | color_print("FAILED! Test for count_documents_in_collection checking for Could not convert the data into a database document","red"); 108 | } 109 | delete_collection_from_database(database_name,DATABASE_COLLECTION_TEST); 110 | RESET_ERROR_MESSAGES; 111 | 112 | // count_all_documents_in_collection 113 | if (count_all_documents_in_collection(database_name,DATABASE_COLLECTION_TEST) == -1 && strncmp(error_message.data[0],"The database collection does not exist",BUFFER_SIZE) == 0) 114 | { 115 | color_print("PASSED! Test for count_all_documents_in_collection checking for The database collection does not exist","green"); 116 | count_test++; 117 | } 118 | else 119 | { 120 | color_print("FAILED! Test for count_all_documents_in_collection checking for The database collection does not exist","red"); 121 | } 122 | RESET_ERROR_MESSAGES; 123 | 124 | // write the end test message 125 | fprintf(stderr,"\033[1;33m\n\n%s\ncount database functions test - Passed test: %d, Failed test: %d\n%s\n\n\n\033[0m",TEST_OUTLINE,count_test,COUNT_DATABASE_FUNCTIONS_TEST-count_test,TEST_OUTLINE); 126 | return count_test; 127 | 128 | #undef MESSAGE 129 | } -------------------------------------------------------------------------------- /src/tests/block_verifiers_functions_test/block_verifiers_server_functions_test/block_verifiers_server_functions_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "define_macro_functions.h" 6 | #include "define_macros.h" 7 | #include "structures.h" 8 | #include "define_macros_test.h" 9 | 10 | #include "delete_database_functions.h" 11 | #include "read_database_functions.h" 12 | #include "count_database_functions.h" 13 | #include "network_functions.h" 14 | #include "network_security_functions.h" 15 | #include "variables_test.h" 16 | #include "string_functions.h" 17 | #include "block_verifiers_server_functions_test.h" 18 | 19 | /* 20 | ----------------------------------------------------------------------------------------------------------- 21 | Functions 22 | ----------------------------------------------------------------------------------------------------------- 23 | */ 24 | 25 | /* 26 | ----------------------------------------------------------------------------------------------------------- 27 | Name: block_verifiers_server_functions_test 28 | Description: Test the block_verifiers_server functions 29 | Return: The number of passed block_verifiers_server_functions test 30 | ----------------------------------------------------------------------------------------------------------- 31 | */ 32 | 33 | int block_verifiers_server_functions_test(void) 34 | { 35 | // define macros 36 | #define RESET_INVALID_RESERVE_PROOFS_DATA \ 37 | for (count = 0; count < invalid_reserve_proofs.count; count++) \ 38 | { \ 39 | pointer_reset(invalid_reserve_proofs.block_verifier_public_address[count]); \ 40 | pointer_reset(invalid_reserve_proofs.public_address_created_reserve_proof[count]); \ 41 | pointer_reset(invalid_reserve_proofs.public_address_voted_for[count]); \ 42 | pointer_reset(invalid_reserve_proofs.reserve_proof[count]); \ 43 | } \ 44 | invalid_reserve_proofs.count = 0; 45 | 46 | // reset the variables 47 | memset(result_test,0,sizeof(result_test)); 48 | memset(data_test,0,sizeof(data_test)); 49 | count_test = 0; 50 | network_functions_test_error_settings = 2; 51 | RESET_ERROR_MESSAGES; 52 | 53 | // write the start test message 54 | fprintf(stderr,"\033[1;34m%s\nblock verifiers server functions test - Total test: %d\n%s\n\n\033[0m",TEST_OUTLINE,BLOCK_VERIFIERS_SERVER_FUNCTIONS_TOTAL_TEST,TEST_OUTLINE); 55 | 56 | // run the test 57 | main_network_data_node_create_block = 1; 58 | memset(result_test,0,sizeof(result_test)); 59 | memset(data_test,0,sizeof(data_test)); 60 | delete_database(database_name); 61 | memcpy(data_test,SERVER_RECEIVE_DATA_SOCKET_MAIN_NETWORK_DATA_NODE_TO_BLOCK_VERIFIER_START_BLOCK_TEST_DATA,sizeof(SERVER_RECEIVE_DATA_SOCKET_MAIN_NETWORK_DATA_NODE_TO_BLOCK_VERIFIER_START_BLOCK_TEST_DATA)-1); 62 | sign_data(data_test); 63 | send_data_socket(XCASH_DPOPS_delegates_IP_address,SEND_DATA_PORT,data_test,SEND_OR_RECEIVE_SOCKET_DATA_TIMEOUT_SETTINGS); 64 | sleep(5); 65 | if (count_documents_in_collection(database_name,"reserve_bytes_1","{\"block_height\":\"" XCASH_PROOF_OF_STAKE_BLOCK_HEIGHT_TEST "\"}") == 1) 66 | { 67 | color_print("PASSED! Test for server_receive_data_socket_main_network_data_node_to_block_verifier_start_block","green"); 68 | count_test++; 69 | } 70 | else 71 | { 72 | color_print("FAILED! Test for server_receive_data_socket_main_network_data_node_to_block_verifier_start_block","red"); 73 | } 74 | RESET_ERROR_MESSAGES; 75 | delete_database(database_name); 76 | main_network_data_node_create_block = 0; 77 | 78 | // set the current_round_part and current_round_part_backup_node 79 | memset(current_round_part_backup_node,0,sizeof(current_round_part_backup_node)); 80 | memcpy(current_round_part_backup_node,"1",sizeof(char)); 81 | main_network_data_node_create_block = 1; 82 | memset(network_data_nodes_list.network_data_nodes_public_address[0],0,sizeof(network_data_nodes_list.network_data_nodes_public_address[0])); 83 | memcpy(network_data_nodes_list.network_data_nodes_public_address[0],xcash_wallet_public_address,XCASH_WALLET_LENGTH); 84 | network_functions_test_error_settings = 0; 85 | CHECK_SERVER_FUNCTIONS("server_receive_data_socket_main_network_data_node_to_block_verifier_create_new_block",SERVER_RECEIVE_DATA_SOCKET_MAIN_NETWORK_DATA_NODE_TO_BLOCK_VERIFIER_CREATE_NEW_BLOCK_TEST_DATA); 86 | network_functions_test_error_settings = 1; 87 | CHECK_SERVER_FUNCTIONS("server_receive_data_socket_block_verifier_to_main_network_data_node_create_new_block",SERVER_RECEIVE_DATA_SOCKET_BLOCK_VERIFIER_TO_MAIN_NETWORK_DATA_NODE_CREATE_NEW_BLOCK_TEST_DATA); 88 | network_functions_test_error_settings = 2; 89 | 90 | memset(data_test,0,sizeof(data_test)); 91 | RESET_ERROR_MESSAGES; 92 | memcpy(data_test,SERVER_RECEIVE_DATA_SOCKET_MAIN_NODE_TO_NODE_MESSAGE_PART_4_TEST_DATA,sizeof(SERVER_RECEIVE_DATA_SOCKET_MAIN_NODE_TO_NODE_MESSAGE_PART_4_TEST_DATA)-1); 93 | if (sign_data(data_test) == 1 && send_data_socket(XCASH_DPOPS_delegates_IP_address,SEND_DATA_PORT,data_test,SEND_OR_RECEIVE_SOCKET_DATA_TIMEOUT_SETTINGS) == 1 && sleep(5) == 0 && strncmp(VRF_data.block_blob,NETWORK_BLOCK,sizeof(NETWORK_BLOCK)) == 0) 94 | { 95 | color_print("PASSED! Test for server_receive_data_socket_main_node_to_node_message_part_4","green"); 96 | count_test++; 97 | } 98 | else 99 | { 100 | color_print("FAILED! Test for server_receive_data_socket_main_node_to_node_message_part_4","red"); 101 | } 102 | RESET_ERROR_MESSAGES; 103 | 104 | CHECK_SERVER_FUNCTIONS("server_receive_data_socket_node_to_node",SERVER_RECEIVE_DATA_SOCKET_NODE_TO_NODE_TEST_DATA); 105 | CHECK_SERVER_FUNCTIONS("server_receive_data_socket_block_verifiers_to_block_verifiers_vrf_data",SERVER_RECEIVE_DATA_SOCKET_BLOCK_VERIFIERS_TO_BLOCK_VERIFIERS_VRF_DATA_TEST_DATA); 106 | CHECK_SERVER_FUNCTIONS("server_receive_data_socket_block_verifiers_to_block_verifiers_block_blob_signature",SERVER_RECEIVE_DATA_SOCKET_BLOCK_VERIFIERS_TO_BLOCK_VERIFIERS_BLOCK_BLOB_SIGNATURE_TEST_DATA); 107 | 108 | // write the end test message 109 | fprintf(stderr,"\033[1;33m\n\n%s\nblock verifiers server functions test - Passed test: %d, Failed test: %d\n%s\n\n\n\033[0m",TEST_OUTLINE,count_test,BLOCK_VERIFIERS_SERVER_FUNCTIONS_TOTAL_TEST-count_test,TEST_OUTLINE); 110 | return count_test; 111 | 112 | #undef RESET_INVALID_RESERVE_PROOFS_DATA 113 | } 114 | -------------------------------------------------------------------------------- /src/functions/database_functions/delete_database_functions/delete_database_functions.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "define_macro_functions.h" 7 | #include "define_macros.h" 8 | #include "structures.h" 9 | #include "variables.h" 10 | 11 | #include "delete_database_functions.h" 12 | #include "database_functions.h" 13 | #include "network_functions.h" 14 | #include "string_functions.h" 15 | #include "vrf.h" 16 | #include "crypto_vrf.h" 17 | #include "VRF_functions.h" 18 | #include "sha512EL.h" 19 | #include "cached_hashes.h" 20 | 21 | /* 22 | ----------------------------------------------------------------------------------------------------------- 23 | Functions 24 | ----------------------------------------------------------------------------------------------------------- 25 | */ 26 | 27 | /* 28 | ----------------------------------------------------------------------------------------------------------- 29 | Name: delete_document_from_collection 30 | Description: Deletes a document from the collection 31 | Parameters: 32 | DATABASE - The database name 33 | COLLECTION - The collection name 34 | DATA - The json data to use to delete the document 35 | Return: 0 if an error has occured, 1 if successfull 36 | ----------------------------------------------------------------------------------------------------------- 37 | */ 38 | 39 | int delete_document_from_collection(const char* DATABASE, const char* COLLECTION, const char* DATA) 40 | { 41 | // Variables 42 | mongoc_client_t* database_client_thread = NULL; 43 | mongoc_collection_t* collection; 44 | bson_error_t error; 45 | bson_t* document = NULL; 46 | 47 | // define macros 48 | #define database_reset_all \ 49 | bson_destroy(document); \ 50 | mongoc_collection_destroy(collection); \ 51 | mongoc_client_pool_push(database_client_thread_pool, database_client_thread); 52 | 53 | #define DELETE_DOCUMENT_FROM_COLLECTION_ERROR(settings) \ 54 | memcpy(error_message.function[error_message.total],"delete_document_from_collection",31); \ 55 | memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \ 56 | error_message.total++; \ 57 | database_reset_all; \ 58 | return 0; 59 | 60 | // get a temporary connection 61 | if (!(database_client_thread = mongoc_client_pool_pop(database_client_thread_pool))) 62 | { 63 | return 0; 64 | } 65 | 66 | // we need to rehash this db next time 67 | del_hash(database_client_thread, COLLECTION); 68 | 69 | // set the collection 70 | collection = mongoc_client_get_collection(database_client_thread, DATABASE, COLLECTION); 71 | 72 | if (!(document = bson_new_from_json((const uint8_t *)DATA, -1, &error))) 73 | { 74 | DELETE_DOCUMENT_FROM_COLLECTION_ERROR("Could not convert the data into a database document"); 75 | } 76 | 77 | mongoc_collection_delete_one(collection, document, NULL, NULL, &error); 78 | 79 | 80 | database_reset_all; 81 | return 1; 82 | 83 | #undef database_reset_all 84 | #undef DELETE_DOCUMENT_FROM_COLLECTION_ERROR 85 | } 86 | 87 | 88 | 89 | /* 90 | ----------------------------------------------------------------------------------------------------------- 91 | Name: delete_collection_from_database 92 | Description: Deletes a collection from the database 93 | Parameters: 94 | DATABASE - The database name 95 | COLLECTION - The collection name 96 | Return: 0 if an error has occured, 1 if successfull 97 | ----------------------------------------------------------------------------------------------------------- 98 | */ 99 | 100 | int delete_collection_from_database(const char* DATABASE, const char* COLLECTION) 101 | { 102 | // Variables 103 | mongoc_client_t* database_client_thread = NULL; 104 | mongoc_collection_t* collection; 105 | bson_error_t error; 106 | 107 | // define macros 108 | #define database_reset_all \ 109 | mongoc_collection_destroy(collection); \ 110 | mongoc_client_pool_push(database_client_thread_pool, database_client_thread); 111 | 112 | #define DELETE_COLLECTION_FROM_DATABASE_ERROR(settings) \ 113 | memcpy(error_message.function[error_message.total],"delete_collection_from_database",31); \ 114 | memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \ 115 | error_message.total++; \ 116 | database_reset_all; \ 117 | return 0; 118 | 119 | // get a temporary connection 120 | if (!(database_client_thread = mongoc_client_pool_pop(database_client_thread_pool))) 121 | { 122 | return 0; 123 | } 124 | 125 | // set the collection 126 | collection = mongoc_client_get_collection(database_client_thread, DATABASE, COLLECTION); 127 | 128 | if (!mongoc_collection_drop(collection, &error)) 129 | { 130 | DELETE_COLLECTION_FROM_DATABASE_ERROR("Could not delete the database collection from the database"); 131 | } 132 | 133 | // we need to rehash this db next time 134 | del_hash(database_client_thread, COLLECTION); 135 | 136 | database_reset_all; 137 | return 1; 138 | 139 | #undef database_reset_all 140 | #undef DELETE_COLLECTION_FROM_DATABASE_ERROR 141 | } 142 | 143 | 144 | 145 | /* 146 | ----------------------------------------------------------------------------------------------------------- 147 | Name: delete_database 148 | Description: Deletes a database 149 | Parameters: 150 | DATABASE - The database name 151 | Return: 0 if an error has occured, 1 if successfull 152 | ----------------------------------------------------------------------------------------------------------- 153 | */ 154 | 155 | int delete_database(const char* DATABASE) 156 | { 157 | // Variables 158 | mongoc_client_t* database_client_thread = NULL; 159 | mongoc_database_t* database; 160 | bson_error_t error; 161 | 162 | // define macros 163 | #define database_reset_all \ 164 | mongoc_database_destroy(database); \ 165 | mongoc_client_pool_push(database_client_thread_pool, database_client_thread); 166 | 167 | #define DELETE_DATABASE_ERROR(settings) \ 168 | memcpy(error_message.function[error_message.total],"delete_database",15); \ 169 | memcpy(error_message.data[error_message.total],settings,sizeof(settings)-1); \ 170 | error_message.total++; \ 171 | database_reset_all; \ 172 | return 0; 173 | 174 | // get a temporary connection 175 | if (!(database_client_thread = mongoc_client_pool_pop(database_client_thread_pool))) 176 | { 177 | return 0; 178 | } 179 | database = mongoc_client_get_database(database_client_thread, DATABASE); 180 | 181 | mongoc_database_drop(database, &error); 182 | 183 | // clear hashes db 184 | drop_all_hashes(database_client_thread); 185 | 186 | database_reset_all; 187 | return 1; 188 | 189 | #undef database_reset_all 190 | #undef DELETE_DATABASE_ERROR 191 | } -------------------------------------------------------------------------------- /src/tests/block_verifiers_functions_test/block_verifiers_synchronize_functions_test/block_verifiers_synchronize_functions_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "define_macro_functions.h" 10 | #include "define_macros.h" 11 | #include "structures.h" 12 | #include "variables.h" 13 | 14 | #include "insert_database_functions.h" 15 | #include "delete_database_functions.h" 16 | #include "block_verifiers_synchronize_functions.h" 17 | #include "define_macros_test.h" 18 | 19 | #include "variables_test.h" 20 | #include "block_verifiers_synchronize_functions_test.h" 21 | 22 | /* 23 | ----------------------------------------------------------------------------------------------------------- 24 | Functions 25 | ----------------------------------------------------------------------------------------------------------- 26 | */ 27 | 28 | /* 29 | ----------------------------------------------------------------------------------------------------------- 30 | Name: block_verifiers_synchronize_functions_test 31 | Description: Test the block_verifiers_synchronize functions 32 | Return: The number of passed block_verifiers_synchronize_functions test 33 | ----------------------------------------------------------------------------------------------------------- 34 | */ 35 | 36 | int block_verifiers_synchronize_functions_test(void) 37 | { 38 | // Variables 39 | int count; 40 | 41 | // reset the variables 42 | memset(result_test,0,sizeof(result_test)); 43 | memset(data_test,0,sizeof(data_test)); 44 | count_test = 0; 45 | network_functions_test_error_settings = 2; 46 | delete_database(database_name); 47 | RESET_ERROR_MESSAGES; 48 | 49 | // write the start test message 50 | fprintf(stderr,"\033[1;34m%s\nblock verifiers synchronize functions test - Total test: %d\n%s\n\n\033[0m",TEST_OUTLINE,BLOCK_VERIFIERS_SYNCHRONIZE_FUNCTIONS_TOTAL_TEST,TEST_OUTLINE); 51 | 52 | // run the test 53 | // sync_reserve_proofs_database 54 | insert_document_into_collection_json(database_name,"reserve_proofs_1",RESERVE_PROOFS_TEST_DATA); 55 | RESET_ERROR_MESSAGES; 56 | if (sync_reserve_proofs_database(0,XCASH_DPOPS_delegates_IP_address) == 1) 57 | { 58 | color_print("PASSED! Test for sync_reserve_proofs_database","green"); 59 | count_test++; 60 | } 61 | else 62 | { 63 | color_print("FAILED! Test for sync_reserve_proofs_database","red"); 64 | } 65 | 66 | // sync_reserve_bytes_database 67 | insert_document_into_collection_json(database_name,"reserve_bytes_1",RESERVE_BYTES_TEST_DATA); 68 | RESET_ERROR_MESSAGES; 69 | if (sync_reserve_bytes_database(0,1,XCASH_DPOPS_delegates_IP_address) == 1) 70 | { 71 | color_print("PASSED! Test for sync_reserve_bytes_database","green"); 72 | count_test++; 73 | } 74 | else 75 | { 76 | color_print("FAILED! Test for sync_reserve_bytes_database","red"); 77 | } 78 | 79 | // sync_delegates_database 80 | insert_document_into_collection_json(database_name,"delegates",DELEGATES_TEST_DATA); 81 | RESET_ERROR_MESSAGES; 82 | if (sync_delegates_database(0,XCASH_DPOPS_delegates_IP_address) == 1) 83 | { 84 | color_print("PASSED! Test for sync_delegates_database","green"); 85 | count_test++; 86 | } 87 | else 88 | { 89 | color_print("FAILED! Test for sync_delegates_database","red"); 90 | } 91 | 92 | // sync_statistics_database 93 | insert_document_into_collection_json(database_name,"statistics",DATABASE_COLLECTION_STATISTICS_DATA); 94 | RESET_ERROR_MESSAGES; 95 | if (sync_statistics_database(0,XCASH_DPOPS_delegates_IP_address) == 1) 96 | { 97 | color_print("PASSED! Test for sync_statistics_database","green"); 98 | count_test++; 99 | } 100 | else 101 | { 102 | color_print("FAILED! Test for sync_statistics_database","red"); 103 | } 104 | 105 | // sync_all_block_verifiers_list 106 | network_data_node_settings = 0; 107 | INITIALIZE_NETWORK_DATA_NODES_TEST 108 | 109 | if (sync_all_block_verifiers_list(1,1) == 1) 110 | { 111 | color_print("PASSED! Test for sync_all_block_verifiers_list for block verifiers","green"); 112 | count_test++; 113 | } 114 | else 115 | { 116 | color_print("FAILED! Test for sync_all_block_verifiers_list for block verifiers","red"); 117 | } 118 | 119 | network_data_node_settings = 1; 120 | if (sync_all_block_verifiers_list(1,1) == 1) 121 | { 122 | color_print("PASSED! Test for sync_all_block_verifiers_list for network data nodes","green"); 123 | count_test++; 124 | } 125 | else 126 | { 127 | color_print("FAILED! Test for sync_all_block_verifiers_list for network data nodes","red"); 128 | } 129 | 130 | // get_synced_block_verifiers 131 | INITIALIZE_PREVIOUS_CURRENT_NEXT_BLOCK_VERIFIERS_TEST 132 | network_data_node_settings = 0; 133 | if (get_synced_block_verifiers() == 1) 134 | { 135 | color_print("PASSED! Test for get_synced_block_verifiers","green"); 136 | count_test++; 137 | } 138 | else 139 | { 140 | color_print("FAILED! Test for get_synced_block_verifiers","red"); 141 | } 142 | 143 | 144 | 145 | // check all errors for each test 146 | delete_database(database_name); 147 | RESET_ERROR_MESSAGES; 148 | 149 | network_data_node_settings = 1; 150 | if (sync_all_block_verifiers_list(1,1) == 0) 151 | { 152 | for (count = 0; count < error_message.total; count++) 153 | { 154 | if (strncmp(error_message.data[count],"Could not organize the delegates",BUFFER_SIZE) == 0) 155 | { 156 | break; 157 | } 158 | } 159 | if (count != error_message.total) 160 | { 161 | color_print("PASSED! Test for sync_all_block_verifiers_list for network data nodes checking for Could not organize the delegates","green"); 162 | count_test++; 163 | } 164 | else 165 | { 166 | color_print("FAILED! Test for sync_all_block_verifiers_list for network data nodes checking for Could not organize the delegates","red"); 167 | } 168 | } 169 | else 170 | { 171 | color_print("FAILED! Test for sync_all_block_verifiers_list for network data nodes checking for Could not organize the delegates","red"); 172 | } 173 | 174 | for (count = 0; count < NETWORK_DATA_NODES_AMOUNT; count++) 175 | { 176 | memset(network_data_nodes_list.network_data_nodes_public_address[count],0,sizeof(network_data_nodes_list.network_data_nodes_public_address[count])); 177 | memset(network_data_nodes_list.network_data_nodes_IP_address[count],0,sizeof(network_data_nodes_list.network_data_nodes_IP_address[count])); 178 | } 179 | INITIALIZE_NETWORK_DATA_NODES 180 | 181 | // write the end test message 182 | fprintf(stderr,"\033[1;33m\n\n%s\nblock verifiers synchronize functions test - Passed test: %d, Failed test: %d\n%s\n\n\n\033[0m",TEST_OUTLINE,count_test,BLOCK_VERIFIERS_SYNCHRONIZE_FUNCTIONS_TOTAL_TEST-count_test,TEST_OUTLINE); 183 | return count_test; 184 | } -------------------------------------------------------------------------------- /scripts/build/build_script_static.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Configuration settings 4 | INSTALLATION_DIRECTORY="$HOME/xcash-official/" 5 | PROGRAMS_INSTALLATION_DIRECTORY="${INSTALLATION_DIRECTORY}Installed-Programs/" 6 | 7 | # Latest versions 8 | XCASH_URL="https://github.com/X-CASH-official/xcash-core.git" 9 | BOOST_URL="https://dl.bintray.com/boostorg/release/1.71.0/source/boost_1_71_0.tar.gz" 10 | OPENSSL_URL="https://www.openssl.org/source/openssl-1.1.1d.tar.gz" 11 | PCSC_LITE_URL="https://pcsclite.apdu.fr/files/pcsc-lite-1.8.25.tar.bz2" 12 | ZEROMQ_URL="https://github.com/zeromq/libzmq/releases/download/v4.3.2/zeromq-4.3.2.tar.gz" 13 | 14 | # Settings 15 | XCASH_DIRECTORY="${PROGRAMS_INSTALLATION_DIRECTORY}xcash-core/" 16 | BOOST_DIRECTORY="${PROGRAMS_INSTALLATION_DIRECTORY}boost_build/" 17 | OPENSSL_DIRECTORY="${PROGRAMS_INSTALLATION_DIRECTORY}openssl_build/" 18 | PCSC_LITE_DIRECTORY="${PROGRAMS_INSTALLATION_DIRECTORY}pcsc_lite_build/" 19 | 20 | # Log Files 21 | LOGFILE_DIRECTORY="${INSTALLATION_DIRECTORY}build/" 22 | LOGFILE="${LOGFILE_DIRECTORY}STEP_10_XCASH_BUILD_STATIC.txt" 23 | 24 | # System settings 25 | CPU_THREADS=$(nproc) 26 | 27 | # Functions 28 | function reset_directories() 29 | { 30 | rm -r "${PROGRAMS_INSTALLATION_DIRECTORY}" 31 | rm -r "${LOGFILE_DIRECTORY}" 32 | mkdir "${PROGRAMS_INSTALLATION_DIRECTORY}" || return 1 33 | mkdir "${LOGFILE_DIRECTORY}" || return 1 34 | } 35 | 36 | 37 | 38 | function update_packages_list() 39 | { 40 | i=0 41 | while fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock >/dev/null 2>&1; do 42 | case $((i % 4)) in 43 | 0 ) j="-" ;; 44 | 1 ) j="\\" ;; 45 | 2 ) j="|" ;; 46 | 3 ) j="/" ;; 47 | esac 48 | sleep 0.25 49 | ((i=i+1)) 50 | done 51 | echo -e "Updating Packages List\n" &>"${LOGFILE}" || return 1 52 | sudo apt update -y &>"${LOGFILE}" || return 1 53 | echo -e "\n" &>"${LOGFILE}" || return 1 54 | } 55 | 56 | 57 | 58 | function update_packages() 59 | { 60 | i=0 61 | while fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock >/dev/null 2>&1; do 62 | case $((i % 4)) in 63 | 0 ) j="-" ;; 64 | 1 ) j="\\" ;; 65 | 2 ) j="|" ;; 66 | 3 ) j="/" ;; 67 | esac 68 | sleep 0.25 69 | ((i=i+1)) 70 | done 71 | echo -e "Updating Packages\n" &>"${LOGFILE}" || return 1 72 | sudo apt dist-upgrade -y &>"${LOGFILE}" || return 1 73 | echo -e "\n" &>"${LOGFILE}" || return 1 74 | } 75 | 76 | 77 | 78 | function build_boost() 79 | { 80 | echo -e "Building Boost\n" &>"${LOGFILE}" || return 1 81 | cd "${PROGRAMS_INSTALLATION_DIRECTORY}" || return 1 82 | wget -q ${BOOST_URL} &>"${LOGFILE}" || return 1 83 | tar -xf boost*.tar.gz &>"${LOGFILE}" || return 1 84 | rm boost*.tar.gz || return 1 85 | cd boost* || return 1 86 | mkdir "${BOOST_DIRECTORY}" || return 1 87 | ./bootstrap.sh --prefix="${BOOST_DIRECTORY}" &>"${LOGFILE}" || return 1 88 | sudo ./b2 cxxflags=-fPIC cflags=-fPIC -a install -j "${CPU_THREADS}" &>"${LOGFILE}" 89 | echo -e "\n" &>"${LOGFILE}" || return 1 90 | } 91 | 92 | 93 | 94 | function build_openssl() 95 | { 96 | echo -e "Building OpenSSL\n" &>"${LOGFILE}" || return 1 97 | cd "${PROGRAMS_INSTALLATION_DIRECTORY}" || return 1 98 | wget -q ${OPENSSL_URL} &>"${LOGFILE}" || return 1 99 | tar -xf openssl*.tar.gz &>"${LOGFILE}" || return 1 100 | rm openssl*.tar.gz || return 1 101 | cd openssl* || return 1 102 | mkdir "${OPENSSL_DIRECTORY}" || return 1 103 | ./config -fPIC --prefix="${OPENSSL_DIRECTORY}" --openssldir="${OPENSSL_DIRECTORY}" &>"${LOGFILE}" || return 1 104 | make depend &>"${LOGFILE}" || return 1 105 | make -j "${CPU_THREADS}" &>"${LOGFILE}" || return 1 106 | sudo make install &>"${LOGFILE}" || return 1 107 | echo -e "\n" &>"${LOGFILE}" || return 1 108 | } 109 | 110 | 111 | 112 | function build_pcsc_lite() 113 | { 114 | echo -e "Building PCSC Lite\n" &>"${LOGFILE}" || return 1 115 | cd "${PROGRAMS_INSTALLATION_DIRECTORY}" || return 1 116 | wget -q ${PCSC_LITE_URL} &>"${LOGFILE}" || return 1 117 | tar -xf pcsc*.tar.bz2 &>"${LOGFILE}" || return 1 118 | rm pcsc*.tar.bz2 || return 1 119 | cd pcsc* || return 1 120 | mkdir "${PCSC_LITE_DIRECTORY}" || return 1 121 | ./configure CPPFLAGS=-DPIC CFLAGS=-fPIC CXXFLAGS=-fPIC LDFLAGS=-fPIC --enable-static --prefix="${PCSC_LITE_DIRECTORY}" &>"${LOGFILE}" || return 1 122 | make -j "${CPU_THREADS}" &>"${LOGFILE}" || return 1 123 | sudo make install &>"${LOGFILE}" || return 1 124 | echo -e "\n" &>"${LOGFILE}" || return 1 125 | } 126 | 127 | 128 | 129 | function build_zeromq() 130 | { 131 | echo -e "Building ZeroMQ\n" &>"${LOGFILE}" || return 1 132 | cd "${PROGRAMS_INSTALLATION_DIRECTORY}" || return 1 133 | wget -q ${ZEROMQ_URL} &>"${LOGFILE}" || return 1 134 | tar -xf zeromq*.tar.gz &>"${LOGFILE}" || return 1 135 | rm zeromq*.tar.gz || return 1 136 | cd zeromq* || return 1 137 | ./autogen.sh &>"${LOGFILE}" || return 1 138 | ./configure CPPFLAGS=-DPIC CFLAGS=-fPIC CXXFLAGS=-fPIC LDFLAGS=-fPIC &>"${LOGFILE}" || return 1 139 | make -j "${CPU_THREADS}" &>"${LOGFILE}" || return 1 140 | sudo make install &>"${LOGFILE}" || return 1 141 | sudo ldconfig 142 | cd /usr/local/include/ || return 1 143 | rm zmq.hpp 144 | wget -q https://raw.githubusercontent.com/zeromq/cppzmq/master/zmq.hpp &>"${LOGFILE}" || return 1 145 | echo -e "\n" &>"${LOGFILE}" || return 1 146 | } 147 | 148 | 149 | 150 | function build_programs() 151 | { 152 | build_boost || return 1 153 | build_openssl || return 1 154 | build_pcsc_lite || return 1 155 | build_zeromq || return 1 156 | } 157 | 158 | 159 | 160 | function build_xcash() 161 | { 162 | echo -e "Building X-CASH\n" &>"${LOGFILE}" || return 1 163 | cd "${PROGRAMS_INSTALLATION_DIRECTORY}" || return 1 164 | git clone ${XCASH_URL} &>"${LOGFILE}" || return 1 165 | cd "${XCASH_DIRECTORY}" || return 1 166 | rm -r build 167 | mkdir -p build/release || return 1 168 | cd build/release || return 1 169 | cmake -D STATIC=ON -D ARCH="x86-64" -D BUILD_64=ON -D BUILD_TESTS=ON -D BOOST_ROOT="${BOOST_DIRECTORY}" -D OPENSSL_ROOT_DIR="${OPENSSL_DIRECTORY}" -D USE_READLINE=OFF -D CMAKE_BUILD_TYPE=release ../.. &>"${LOGFILE}" || return 1 170 | cd ../../ 171 | make -I"${BOOST_DIRECTORY}"include -I"${OPENSSL_DIRECTORY}"include -I"${PCSC_LITE_DIRECTORY}"include LDFLAGS="-L${BOOST_DIRECTORY}lib -L${OPENSSL_DIRECTORY}lib -L${PCSC_LITE_DIRECTORY}lib" -j "${CPU_THREADS}" &>"${LOGFILE}" || return 1 172 | echo -e "\n" &>"${LOGFILE}" || return 1 173 | } 174 | 175 | 176 | 177 | function main() 178 | { 179 | # Reset the directories 180 | reset_directories || return 1 181 | 182 | # Update the packages list 183 | update_packages_list || return 1 184 | 185 | # Update the packages 186 | update_packages || return 1 187 | 188 | # Build programs 189 | build_programs || return 1 190 | 191 | # Build XCASH 192 | build_xcash || return 1 193 | } 194 | 195 | 196 | 197 | main || echo "STEP_10_XCASH_BUILD_STATIC_ERROR" &>"${LOGFILE}" -------------------------------------------------------------------------------- /src/functions/VRF_functions/prove.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2018 Amir Hossein Alikhah Mishamandani 3 | Copyright (c) 2018 Algorand LLC 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | #include 25 | 26 | #include "sha512EL.h" 27 | #include "vrf.h" 28 | #include "ed25519_ref10.h" 29 | #include "convert.h" 30 | 31 | /* Utility function to convert a "secret key" (32-byte seed || 32-byte PK) 32 | * into the public point Y, the private saclar x, and truncated hash of the 33 | * seed to be used later in nonce generation. 34 | * Return 0 on success, -1 on failure decoding the public point Y. 35 | */ 36 | static int 37 | vrf_expand_sk(ge25519_p3 *Y_point, unsigned char x_scalar[32], 38 | unsigned char truncated_hashed_sk_string[32], const unsigned char skpk[64]) 39 | { 40 | unsigned char h[64]; 41 | 42 | crypto_hash_sha512(h, skpk, 32); 43 | h[0] &= 248; 44 | h[31] &= 127; 45 | h[31] |= 64; 46 | memmove(x_scalar, h, 32); 47 | memmove(truncated_hashed_sk_string, h + 32, 32); 48 | memset(h, 0, 64); 49 | 50 | return _vrf_ietfdraft03_string_to_point(Y_point, skpk+32); 51 | } 52 | 53 | 54 | /* Deterministically generate a (secret) nonce to be used in a proof. 55 | * Specified in draft spec section 5.4.2.2. 56 | * Note: In the spec, this subroutine computes truncated_hashed_sk_string 57 | * Here we instead takes it as an argument, and we compute it in vrf_expand_sk 58 | */ 59 | static void 60 | vrf_nonce_generation(unsigned char k_scalar[32], 61 | const unsigned char truncated_hashed_sk_string[32], 62 | const unsigned char h_string[32]) 63 | { 64 | crypto_hash_sha512_state hs; 65 | unsigned char k_string[64]; 66 | 67 | /* k_string = SHA512(truncated_hashed_sk_string || h_string) */ 68 | crypto_hash_sha512_init(&hs); 69 | crypto_hash_sha512_update(&hs, truncated_hashed_sk_string, 32); 70 | crypto_hash_sha512_update(&hs, h_string, 32); 71 | crypto_hash_sha512_final(&hs, k_string); 72 | 73 | sc25519_reduce(k_string); /* k_string[0:32] = string_to_int(k_string) mod q */ 74 | memmove(k_scalar, k_string, 32); 75 | 76 | memset(k_string, 0, sizeof k_string); 77 | } 78 | 79 | /* Construct a proof for a message alpha per draft spec section 5.1. 80 | * Takes in a secret scalar x, a public point Y, and a secret string 81 | * truncated_hashed_sk that is used in nonce generation. 82 | * These are computed from the secret key using the expand_sk function. 83 | * Constant time in everything except alphalen (the length of the message) 84 | */ 85 | static void 86 | vrf_prove(unsigned char pi[80], const ge25519_p3 *Y_point, 87 | const unsigned char x_scalar[32], 88 | const unsigned char truncated_hashed_sk_string[32], 89 | const unsigned char *alpha, unsigned long long alphalen) 90 | { 91 | /* c fits in 16 bytes, but we store it in a 32-byte array because 92 | * sc25519_muladd expects a 32-byte scalar */ 93 | unsigned char h_string[32]; 94 | unsigned char k_scalar[32]; 95 | unsigned char c_scalar[32]; 96 | ge25519_p3 H_point; 97 | ge25519_p3 Gamma_point; 98 | ge25519_p3 kB_point; 99 | ge25519_p3 kH_point; 100 | 101 | _vrf_ietfdraft03_hash_to_curve_elligator2_25519(h_string, Y_point, alpha, alphalen); 102 | ge25519_frombytes(&H_point, h_string); 103 | 104 | ge25519_scalarmult(&Gamma_point, x_scalar, &H_point); /* Gamma = x*H */ 105 | vrf_nonce_generation(k_scalar, truncated_hashed_sk_string, h_string); 106 | ge25519_scalarmult_base(&kB_point, k_scalar); /* compute k*B */ 107 | ge25519_scalarmult(&kH_point, k_scalar, &H_point); /* compute k*H */ 108 | 109 | /* c = ECVRF_hash_points(h, gamma, k*B, k*H) 110 | * (writes only to the first 16 bytes of c_scalar */ 111 | _vrf_ietfdraft03_hash_points(c_scalar, &H_point, &Gamma_point, &kB_point, &kH_point); 112 | memset(c_scalar+16, 0, 16); /* zero the remaining 16 bytes of c_scalar */ 113 | 114 | /* output pi */ 115 | _vrf_ietfdraft03_point_to_string(pi, &Gamma_point); /* pi[0:32] = point_to_string(Gamma) */ 116 | memmove(pi+32, c_scalar, 16); /* pi[32:48] = c (16 bytes) */ 117 | sc25519_muladd(pi+48, c_scalar, x_scalar, k_scalar); /* pi[48:80] = s = c*x + k (mod q) */ 118 | 119 | memset(k_scalar, 0, sizeof k_scalar); /* k must remain secret */ 120 | /* erase other non-sensitive intermediate state for good measure */ 121 | memset(h_string, 0, sizeof h_string); 122 | memset(c_scalar, 0, sizeof c_scalar); 123 | memset(&H_point, 0, sizeof H_point); 124 | memset(&Gamma_point, 0, sizeof Gamma_point); 125 | memset(&kB_point, 0, sizeof kB_point); 126 | memset(&kH_point, 0, sizeof kH_point); 127 | } 128 | 129 | /* Construct a VRF proof given a secret key and a message. 130 | * 131 | * The "secret key" is 64 bytes long -- 32 byte secret seed concatenated 132 | * with 32 byte precomputed public key. Our keygen functions return secret keys 133 | * of this form. 134 | * 135 | * Returns 0 on success, nonzero on failure decoding the public key. 136 | * 137 | * Constant time in everything except msglen, unless decoding the public key 138 | * fails. 139 | */ 140 | int 141 | crypto_vrf_ietfdraft03_prove(unsigned char proof[crypto_vrf_ietfdraft03_PROOFBYTES], 142 | const unsigned char skpk[crypto_vrf_ietfdraft03_SECRETKEYBYTES], 143 | const unsigned char *msg, 144 | unsigned long long msglen) 145 | { 146 | ge25519_p3 Y_point; 147 | unsigned char x_scalar[32]; 148 | unsigned char truncated_hashed_sk_string[32]; 149 | 150 | if (vrf_expand_sk(&Y_point, x_scalar, truncated_hashed_sk_string, skpk) != 0) { 151 | memset(x_scalar, 0, 32); 152 | memset(truncated_hashed_sk_string, 0, 32); 153 | memset(&Y_point, 0, sizeof Y_point); /* for good measure */ 154 | return -1; 155 | } 156 | vrf_prove(proof, &Y_point, x_scalar, truncated_hashed_sk_string, msg, msglen); 157 | memset(x_scalar, 0, 32); 158 | memset(truncated_hashed_sk_string, 0, 32); 159 | memset(&Y_point, 0, sizeof Y_point); /* for good measure */ 160 | return 0; 161 | } 162 | -------------------------------------------------------------------------------- /src/tests/database_functions_test/delete_database_functions_test/delete_database_functions_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "define_macro_functions.h" 6 | #include "define_macros_test.h" 7 | 8 | #include "insert_database_functions.h" 9 | #include "delete_database_functions.h" 10 | #include "thread_functions.h" 11 | 12 | #include "variables_test.h" 13 | #include "delete_database_functions_test.h" 14 | 15 | /* 16 | ----------------------------------------------------------------------------------------------------------- 17 | Functions 18 | ----------------------------------------------------------------------------------------------------------- 19 | */ 20 | 21 | /* 22 | ----------------------------------------------------------------------------------------------------------- 23 | Name: delete_database_functions_test 24 | Description: Test the delete database functions 25 | Return: The number of passed delete database functions test 26 | ----------------------------------------------------------------------------------------------------------- 27 | */ 28 | 29 | int delete_database_functions_test(void) 30 | { 31 | // Variables 32 | pthread_t thread_id; 33 | 34 | // define macros 35 | #define MESSAGE "{\"message_settings\": \"XCASH_DPOPS_TEST_DATA\"}" 36 | 37 | delete_collection_from_database(database_name,DATABASE_COLLECTION_TEST); 38 | 39 | // write the start test message 40 | fprintf(stderr,"\033[1;34m%s\ndelete database functions test - Total test: %d\n%s\n\n\033[0m",TEST_OUTLINE,DELETE_DATABASE_FUNCTIONS_TEST,TEST_OUTLINE); 41 | 42 | // reset the variables 43 | memset(data_test,0,sizeof(data_test)); 44 | count_test = 0; 45 | 46 | // delete a document from the collection 47 | insert_document_into_collection_json(database_name,DATABASE_COLLECTION_TEST,MESSAGE); 48 | if (delete_document_from_collection(database_name,DATABASE_COLLECTION_TEST,MESSAGE) == 0) 49 | { 50 | color_print("FAILED! Test for delete_document_from_collection","red"); 51 | } 52 | else 53 | { 54 | color_print("PASSED! Test for delete_document_from_collection","green"); 55 | count_test++; 56 | } 57 | 58 | // delete a document from the collection on a separate thread 59 | if (insert_document_into_collection_json(database_name,DATABASE_COLLECTION_TEST,MESSAGE) == 0) 60 | { 61 | color_print("FAILED! Test for delete_document_from_collection_thread","red"); 62 | } 63 | else 64 | { 65 | struct delete_document_from_collection_thread_parameters delete_document_from_collection_thread_parameters = {database_name,DATABASE_COLLECTION_TEST,MESSAGE}; 66 | pthread_create(&thread_id, NULL, &delete_document_from_collection_thread,(void *)&delete_document_from_collection_thread_parameters); 67 | if (thread_settings(thread_id) == 0) 68 | { 69 | color_print("FAILED! Test for delete_document_from_collection_thread","red"); 70 | } 71 | else 72 | { 73 | color_print("PASSED! Test for delete_document_from_collection_thread","green"); 74 | count_test++; 75 | } 76 | } 77 | 78 | // delete a collection from the database 79 | insert_document_into_collection_json(database_name,DATABASE_COLLECTION_TEST,MESSAGE); 80 | if (delete_collection_from_database(database_name,DATABASE_COLLECTION_TEST) == 0) 81 | { 82 | color_print("FAILED! Test for delete_collection_from_database","red"); 83 | } 84 | else 85 | { 86 | color_print("PASSED! Test for delete_collection_from_database","green"); 87 | count_test++; 88 | } 89 | 90 | // delete a collection from the database on a separate thread 91 | if (insert_document_into_collection_json(database_name,DATABASE_COLLECTION_TEST,MESSAGE) == 0) 92 | { 93 | color_print("FAILED! Test for delete_collection_from_database_thread","red"); 94 | } 95 | else 96 | { 97 | struct delete_collection_from_database_thread_parameters delete_collection_from_database_thread_parameters = {database_name,DATABASE_COLLECTION_TEST}; 98 | pthread_create(&thread_id, NULL, &delete_collection_from_database_thread,(void *)&delete_collection_from_database_thread_parameters); 99 | if (thread_settings(thread_id) == 0) 100 | { 101 | color_print("FAILED! Test for delete_collection_from_database_thread","red"); 102 | } 103 | else 104 | { 105 | color_print("PASSED! Test for delete_collection_from_database_thread","green"); 106 | count_test++; 107 | } 108 | } 109 | 110 | // delete a database 111 | insert_document_into_collection_json(DATABASE_NAME_TEST,DATABASE_COLLECTION_TEST,MESSAGE); 112 | if (delete_database(DATABASE_NAME_TEST) == 0) 113 | { 114 | color_print("FAILED! Test for delete_database","red"); 115 | } 116 | else 117 | { 118 | color_print("PASSED! Test for delete_database","green"); 119 | count_test++; 120 | } 121 | 122 | // delete a database on a separate thread 123 | insert_document_into_collection_json(DATABASE_NAME_TEST,DATABASE_COLLECTION_TEST,MESSAGE); 124 | struct delete_database_thread_parameters delete_database_thread_parameters = {DATABASE_NAME_TEST}; 125 | pthread_create(&thread_id, NULL, &delete_database_thread,(void *)&delete_database_thread_parameters); 126 | if (thread_settings(thread_id) == 0) 127 | { 128 | color_print("FAILED! Test for delete_database_thread","red"); 129 | } 130 | else 131 | { 132 | color_print("PASSED! Test for delete_database_thread","green"); 133 | count_test++; 134 | } 135 | 136 | 137 | 138 | // check all errors for each test 139 | delete_database(DATABASE_NAME_TEST); 140 | RESET_ERROR_MESSAGES; 141 | 142 | // delete_document_from_collection 143 | if (delete_document_from_collection(database_name,DATABASE_COLLECTION_TEST,"data") == 0 && strncmp(error_message.data[0],"Could not convert the data into a database document",BUFFER_SIZE) == 0) 144 | { 145 | color_print("PASSED! Test for delete_document_from_collection checking for Could not convert the data into a database document","green"); 146 | count_test++; 147 | } 148 | else 149 | { 150 | color_print("FAILED! Test for delete_document_from_collection checking for Could not convert the data into a database document","red"); 151 | } 152 | RESET_ERROR_MESSAGES; 153 | 154 | // delete_collection_from_database 155 | if (delete_collection_from_database(database_name,DATABASE_COLLECTION_TEST) == 0 && strncmp(error_message.data[0],"Could not delete the database collection from the database",BUFFER_SIZE) == 0) 156 | { 157 | color_print("PASSED! Test for delete_collection_from_database checking for Could not delete the database collection from the database","green"); 158 | count_test++; 159 | } 160 | else 161 | { 162 | color_print("FAILED! Test for delete_collection_from_database checking for Could not delete the database collection from the database","red"); 163 | } 164 | RESET_ERROR_MESSAGES; 165 | 166 | // write the end test message 167 | fprintf(stderr,"\033[1;33m\n\n%s\ndelete database functions test - Passed test: %d, Failed test: %d\n%s\n\n\n\033[0m",TEST_OUTLINE,count_test,DELETE_DATABASE_FUNCTIONS_TEST-count_test,TEST_OUTLINE); 168 | return count_test; 169 | 170 | #undef MESSAGE 171 | } -------------------------------------------------------------------------------- /src/tests/database_functions_test/insert_database_functions_test/insert_database_functions_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "define_macro_functions.h" 6 | #include "define_macros_test.h" 7 | 8 | #include "insert_database_functions.h" 9 | #include "delete_database_functions.h" 10 | #include "thread_functions.h" 11 | 12 | #include "variables_test.h" 13 | #include "insert_database_functions_test.h" 14 | 15 | /* 16 | ----------------------------------------------------------------------------------------------------------- 17 | Functions 18 | ----------------------------------------------------------------------------------------------------------- 19 | */ 20 | 21 | /* 22 | ----------------------------------------------------------------------------------------------------------- 23 | Name: insert_database_functions_test 24 | Description: Test the insert database functions 25 | Return: The number of passed insert database functions test 26 | ----------------------------------------------------------------------------------------------------------- 27 | */ 28 | 29 | int insert_database_functions_test(void) 30 | { 31 | // Variables 32 | pthread_t thread_id; 33 | 34 | // define macros 35 | #define DATA_COUNT 5 36 | #define MESSAGE "{\"message_settings\": \"XCASH_DPOPS_TEST_DATA\"}" 37 | #define MESSAGE_SETTINGS "{\"message_settings\": \"XCASH_DPOPS_DATA\"}" 38 | 39 | // reset the variables 40 | memset(data_test,0,sizeof(data_test)); 41 | count_test = 0; 42 | 43 | delete_collection_from_database(database_name,DATABASE_COLLECTION_TEST); 44 | 45 | // write the start test message 46 | fprintf(stderr,"\033[1;34m%s\ninsert database functions test - Total test: %d\n%s\n\n\033[0m",TEST_OUTLINE,INSERT_DATABASE_FUNCTIONS_TEST,TEST_OUTLINE); 47 | 48 | // insert a document into the collection using json data 49 | if (insert_document_into_collection_json(database_name,DATABASE_COLLECTION_TEST,MESSAGE) == 0) 50 | { 51 | color_print("FAILED! Test for insert_document_into_collection_json","red"); 52 | } 53 | else 54 | { 55 | color_print("PASSED! Test for insert_document_into_collection_json","green"); 56 | count_test++; 57 | } 58 | delete_database(database_name); 59 | 60 | // insert a document into the collection using json data on a separate thread 61 | struct insert_document_into_collection_json_thread_parameters insert_document_into_collection_json_thread_parameters = {database_name,DATABASE_COLLECTION_TEST,MESSAGE}; 62 | pthread_create(&thread_id, NULL, &insert_document_into_collection_json_thread,(void *)&insert_document_into_collection_json_thread_parameters); 63 | if (thread_settings(thread_id) == 0) 64 | { 65 | color_print("FAILED! Test for insert_document_into_collection_json_thread","red"); 66 | } 67 | else 68 | { 69 | color_print("PASSED! Test for insert_document_into_collection_json_thread","green"); 70 | count_test++; 71 | } 72 | 73 | // insert multiple documents into the collection using json data 74 | memset(data_test,0,strnlen(data_test,BUFFER_SIZE)); 75 | memcpy(data_test,DATABASE_COLLECTION_STATISTICS_TEST_DATA,strnlen(DATABASE_COLLECTION_STATISTICS_TEST_DATA,BUFFER_SIZE)); 76 | memcpy(data_test+strlen(data_test),",{\"username\":\"XCASH\",\"most_total_rounds_delegate_name\":\"DELEGATE_NAME\",\"most_total_rounds\":\"5\",\"best_block_verifier_online_percentage_delegate_name\":\"DELEGATE_NAME\",\"best_block_verifier_online_percentage\":\"10\",\"most_block_producer_total_rounds_delegate_name\":\"DELEGATE_NAME\",\"most_block_producer_total_rounds\":\"10\"}",315); 77 | if (insert_multiple_documents_into_collection_json(database_name,DATABASE_COLLECTION_TEST,data_test,sizeof(data_test)) == 1) 78 | { 79 | color_print("PASSED! Test for insert_multiple_documents_into_collection_json","green"); 80 | count_test++; 81 | } 82 | else 83 | { 84 | color_print("FAILED! Test for insert_multiple_documents_into_collection_json","red"); 85 | } 86 | delete_database(database_name); 87 | 88 | // insert multiple documents into the collection using json data on a separate thread 89 | memset(data_test,0,strnlen(data_test,BUFFER_SIZE)); 90 | memcpy(data_test,DATABASE_COLLECTION_STATISTICS_TEST_DATA,strnlen(DATABASE_COLLECTION_STATISTICS_TEST_DATA,BUFFER_SIZE)); 91 | memcpy(data_test+strlen(data_test),",{\"username\":\"XCASH\",\"most_total_rounds_delegate_name\":\"DELEGATE_NAME\",\"most_total_rounds\":\"5\",\"best_block_verifier_online_percentage_delegate_name\":\"DELEGATE_NAME\",\"best_block_verifier_online_percentage\":\"10\",\"most_block_producer_total_rounds_delegate_name\":\"DELEGATE_NAME\",\"most_block_producer_total_rounds\":\"10\"}",315); 92 | struct insert_multiple_documents_into_collection_json_thread_parameters insert_multiple_documents_into_collection_json_thread_parameters = {database_name,DATABASE_COLLECTION_TEST,data_test,BUFFER_SIZE}; 93 | pthread_create(&thread_id, NULL, &insert_multiple_documents_into_collection_json_thread,(void *)&insert_multiple_documents_into_collection_json_thread_parameters); 94 | if (thread_settings(thread_id) == 1) 95 | { 96 | color_print("PASSED! Test for insert_multiple_documents_into_collection_json_thread","green"); 97 | count_test++; 98 | } 99 | else 100 | { 101 | color_print("FAILED! Test for insert_multiple_documents_into_collection_json_thread","red"); 102 | } 103 | 104 | 105 | 106 | // check all errors for each test 107 | delete_collection_from_database(database_name,DATABASE_COLLECTION_TEST); 108 | RESET_ERROR_MESSAGES; 109 | 110 | // insert_document_into_collection_json 111 | if (insert_document_into_collection_json(database_name,DATABASE_COLLECTION_TEST,"data") == 0 && strncmp(error_message.data[0],"Could not convert the data into a database document",BUFFER_SIZE) == 0) 112 | { 113 | color_print("PASSED! Test for insert_document_into_collection_json checking for Could not convert the data into a database document","green"); 114 | count_test++; 115 | } 116 | else 117 | { 118 | color_print("FAILED! Test for insert_document_into_collection_json checking for Could not convert the data into a database document","red"); 119 | } 120 | RESET_ERROR_MESSAGES; 121 | 122 | // insert_multiple_documents_into_collection_json 123 | if (insert_multiple_documents_into_collection_json(database_name,DATABASE_COLLECTION_TEST,"data",5) == 0 && strncmp(error_message.data[0],"Could not convert the data into a database document",BUFFER_SIZE) == 0) 124 | { 125 | color_print("PASSED! Test for insert_multiple_documents_into_collection_json checking for Could not convert the data into a database document","green"); 126 | count_test++; 127 | } 128 | else 129 | { 130 | color_print("FAILED! Test for insert_multiple_documents_into_collection_json checking for Could not convert the data into a database document","red"); 131 | } 132 | RESET_ERROR_MESSAGES; 133 | 134 | // write the end test message 135 | fprintf(stderr,"\033[1;33m\n\n%s\ninsert database functions test - Passed test: %d, Failed test: %d\n%s\n\n\n\033[0m",TEST_OUTLINE,count_test,INSERT_DATABASE_FUNCTIONS_TEST-count_test,TEST_OUTLINE); 136 | return count_test; 137 | 138 | #undef DATA_COUNT 139 | #undef MESSAGE 140 | #undef MESSAGE_SETTINGS 141 | } -------------------------------------------------------------------------------- /src/tests/block_verifiers_functions_test/block_verifiers_synchronize_functions_test/block_verifiers_synchronize_check_functions_test/block_verifiers_synchronize_check_functions_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "define_macro_functions.h" 10 | #include "define_macros.h" 11 | #include "structures.h" 12 | #include "variables.h" 13 | 14 | #include "insert_database_functions.h" 15 | #include "delete_database_functions.h" 16 | #include "block_verifiers_synchronize_check_functions.h" 17 | #include "define_macros_test.h" 18 | 19 | #include "variables_test.h" 20 | #include "block_verifiers_synchronize_check_functions_test.h" 21 | 22 | /* 23 | ----------------------------------------------------------------------------------------------------------- 24 | Functions 25 | ----------------------------------------------------------------------------------------------------------- 26 | */ 27 | 28 | /* 29 | ----------------------------------------------------------------------------------------------------------- 30 | Name: block_verifiers_synchronize_check_functions_test 31 | Description: Test the block_verifiers_synchronize_check functions 32 | Return: The number of passed block_verifiers_synchronize_check_functions test 33 | ----------------------------------------------------------------------------------------------------------- 34 | */ 35 | 36 | int block_verifiers_synchronize_check_functions_test(void) 37 | { 38 | // Variables 39 | int count; 40 | 41 | // reset the variables 42 | memset(result_test,0,sizeof(result_test)); 43 | memset(data_test,0,sizeof(data_test)); 44 | count_test = 0; 45 | network_functions_test_error_settings = 2; 46 | delete_database(database_name); 47 | RESET_ERROR_MESSAGES; 48 | 49 | // write the start test message 50 | fprintf(stderr,"\033[1;34m%s\nblock verifiers synchronize check functions test - Total test: %d\n%s\n\n\033[0m",TEST_OUTLINE,BLOCK_VERIFIERS_SYNCHRONIZE_CHECK_FUNCTIONS_TOTAL_TEST,TEST_OUTLINE); 51 | 52 | // run the test 53 | // sync_reserve_proofs_database 54 | insert_document_into_collection_json(database_name,"reserve_proofs_1",RESERVE_PROOFS_TEST_DATA); 55 | insert_document_into_collection_json(database_name,"reserve_bytes_1",RESERVE_BYTES_TEST_DATA); 56 | insert_document_into_collection_json(database_name,"delegates",DELEGATES_TEST_DATA); 57 | insert_document_into_collection_json(database_name,"statistics",DATABASE_COLLECTION_STATISTICS_DATA); 58 | INITIALIZE_NETWORK_DATA_NODES_TEST 59 | 60 | 61 | if (sync_check_reserve_proofs_database(1) == 1) 62 | { 63 | color_print("PASSED! Test for sync_check_reserve_proofs_database from a random block verifier","green"); 64 | count_test++; 65 | } 66 | else 67 | { 68 | color_print("FAILED! Test for sync_check_reserve_proofs_database from a random block verifier","red"); 69 | } 70 | 71 | if (sync_check_reserve_bytes_database(1,0) == 1) 72 | { 73 | color_print("PASSED! Test for sync_check_reserve_bytes_database from a random block verifier","green"); 74 | count_test++; 75 | } 76 | else 77 | { 78 | color_print("FAILED! Test for sync_check_reserve_bytes_database from a random block verifier","red"); 79 | } 80 | 81 | if (sync_check_delegates_database(1) == 1) 82 | { 83 | color_print("PASSED! Test for sync_check_delegates_database from a random block verifier","green"); 84 | count_test++; 85 | } 86 | else 87 | { 88 | color_print("FAILED! Test for sync_check_delegates_database from a random block verifier","red"); 89 | } 90 | 91 | if (sync_check_statistics_database(1) == 1) 92 | { 93 | color_print("PASSED! Test for sync_check_statistics_database from a random block verifier","green"); 94 | count_test++; 95 | } 96 | else 97 | { 98 | color_print("FAILED! Test for sync_check_statistics_database from a random block verifier","red"); 99 | } 100 | 101 | if (sync_check_reserve_proofs_database(3) == 1) 102 | { 103 | color_print("PASSED! Test for sync_check_reserve_proofs_database from a random network data node","green"); 104 | count_test++; 105 | } 106 | else 107 | { 108 | color_print("FAILED! Test for sync_check_reserve_proofs_database from a random network data node","red"); 109 | } 110 | 111 | if (sync_check_reserve_bytes_database(3,0) == 1) 112 | { 113 | color_print("PASSED! Test for sync_check_reserve_bytes_database from a random network data node","green"); 114 | count_test++; 115 | } 116 | else 117 | { 118 | color_print("FAILED! Test for sync_check_reserve_bytes_database from a random network data node","red"); 119 | } 120 | 121 | if (sync_check_delegates_database(3) == 1) 122 | { 123 | color_print("PASSED! Test for sync_check_delegates_database from a random network data node","green"); 124 | count_test++; 125 | } 126 | else 127 | { 128 | color_print("FAILED! Test for sync_check_delegates_database from a random network data node","red"); 129 | } 130 | 131 | if (sync_check_statistics_database(3) == 1) 132 | { 133 | color_print("PASSED! Test for sync_check_statistics_database from a random network data node","green"); 134 | count_test++; 135 | } 136 | else 137 | { 138 | color_print("FAILED! Test for sync_check_statistics_database from a random network data node","red"); 139 | } 140 | 141 | if (sync_check_majority_reserve_proofs_database() == 1) 142 | { 143 | color_print("PASSED! Test for sync_check_majority_reserve_proofs_database","green"); 144 | count_test++; 145 | } 146 | else 147 | { 148 | color_print("FAILED! Test for sync_check_majority_reserve_proofs_database","red"); 149 | } 150 | 151 | if (sync_check_majority_reserve_bytes_database(1) == 1) 152 | { 153 | color_print("PASSED! Test for sync_check_majority_reserve_bytes_database","green"); 154 | count_test++; 155 | } 156 | else 157 | { 158 | color_print("FAILED! Test for sync_check_majority_reserve_bytes_database","red"); 159 | } 160 | 161 | if (sync_check_majority_delegates_database() == 1) 162 | { 163 | color_print("PASSED! Test for sync_check_majority_delegates_database","green"); 164 | count_test++; 165 | } 166 | else 167 | { 168 | color_print("FAILED! Test for sync_check_majority_delegates_database","red"); 169 | } 170 | 171 | if (sync_check_majority_statistics_database() == 1) 172 | { 173 | color_print("PASSED! Test for sync_check_majority_statistics_database","green"); 174 | count_test++; 175 | } 176 | else 177 | { 178 | color_print("FAILED! Test for sync_check_majority_statistics_database","red"); 179 | } 180 | 181 | for (count = 0; count < NETWORK_DATA_NODES_AMOUNT; count++) 182 | { 183 | memset(network_data_nodes_list.network_data_nodes_public_address[count],0,sizeof(network_data_nodes_list.network_data_nodes_public_address[count])); 184 | memset(network_data_nodes_list.network_data_nodes_IP_address[count],0,sizeof(network_data_nodes_list.network_data_nodes_IP_address[count])); 185 | } 186 | INITIALIZE_NETWORK_DATA_NODES 187 | 188 | // write the end test message 189 | fprintf(stderr,"\033[1;33m\n\n%s\nblock verifiers synchronize check functions test - Passed test: %d, Failed test: %d\n%s\n\n\n\033[0m",TEST_OUTLINE,count_test,BLOCK_VERIFIERS_SYNCHRONIZE_CHECK_FUNCTIONS_TOTAL_TEST-count_test,TEST_OUTLINE); 190 | return count_test; 191 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | X-Cash Delegated Proof of Private Stake 4 | 5 | [![chat](https://img.shields.io/discord/470575102203920395?logo=discord)](https://discordapp.com/invite/4CAahnd) 6 | [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?style=flat)](https://opensource.org/licenses/MIT) 7 | 8 |
9 | 10 | # X-Cash Delegated Proof of Private Stake 11 | 12 | 🗳️ The **X-Cash Delegated Proof of Private Stake** (`xcash-dpops`) is a custom variation of a DPoS with DBFT consensus made with privacy coin from the CryptoNote legacy in mind. 13 | The **[X-Cash](https://github.com/X-Cash-Official/xcash-core)** Public Network is governed by delegates elected by XCASH holders to secure and forge new blocks. 14 | 15 | ## Table of Content 16 | 17 | - [Table of Content](#table-of-content) 18 | - [Features](#features) 19 | - [License](#license) 20 | - [Contributing](#contributing) 21 | - [Documentation](#documentation) 22 | - [Security](#security) 23 | - [Installation](#installation) 24 | - [Maintenance](#maintenance) 25 | 26 | ## Features 27 | 28 | Implementing a **Delegated Proof of Stake** and **Delegated Byzantine Fault Tolerance** consensus in a privacy-based cryptocurrency presents a challenge. Taking inspiration from successful blockchain governance systems, **X-Cash Delegated Proof of Private Stake** proposes a unique solution to bring DPOS and DBFT based consensus to the privacy coin space. 29 | 30 | ### **Staking** 31 | The **X-Cash Public Network** is secured by delegates, elected in their position by XCASH holders. By providing your **vote through a stake in XCASH**, you are electing a representative to secure the network and forge new blocks, which will in return **split the block reward with you**. 32 | 33 | ### **DBFT** 34 | The unique implementation of **DBFT** into the consensus process enables the X-Cash blockchain to become **immune to forks**, henceforth instantly validating new transactions. 35 | 36 | ### **Randomized Block Producer Selection** 37 | The selection of the next delegate in charge of forging a block is **completely randomized** through the use of **Verifiable Random Functions (VRF)**, increasing the security of the delegates by preventing attacks to the next block producer. 38 | 39 | ### **Stake Delegation with Reserve Proofs** 40 | Instead of sending your stake to another wallet to vote toward a delegate, you are providing a **cryptographic reserve proof** of your funds to your delegate, meaning that **you keep complete control of your stake at all times**. 41 | 42 | 43 | > *Have a look at our* 📜 *[Delegated Proof-of-Private-Stake](https://x-network.io/whitepaper/XCASH_Yellowpaper_DPoPS.pdf) yellow paper to learn more about the technical challenge of integrating this consensus on a Monero-based privacy coin.* 44 | 45 | 46 | ## License 47 | 48 | **X-Cash is an open-source project managed by the X-Cash Foundation**. 49 | We are operating under the [MIT License](LICENSE). 50 | 51 | ## Contributing 52 | 53 | **Thank you for thinking of contributing! 😃** 54 | If you want to help out, fork the repository, check [CONTRIBUTING](https://github.com/X-CASH-official/.github/blob/master/CONTRIBUTING.md) for a set of guidelines, and check our [opened issues](https://github.com/X-CASH-official/xcash-core/issues). 55 | 56 | ## Documentation 57 | 58 | We are hosting our documentation on **GitBook** 👉 [**docs.xcash.foundation**](https://docs.xcash.foundation/) 59 | 60 | > You can contribute directly on our [`gitbook-docs`](https://github.com/X-CASH-official/gitbook-docs) repository. 61 | 62 | ## Security 63 | 64 | If you discover a security vulnerability, please send an e-mail to [security@xcash.foundation](mailto:security@xcash.foundation). 65 | All security vulnerabilities concerning the X-Cash blockchain will be promply addressed. 66 | 67 | ## Installation 68 | 69 | > Every steps of the installation and build instructions are described in our [detailed guide](https://docs.xcash.foundation/dpops/get-started). 70 | 71 | ### System Requirements 72 | 73 | > In the first beta version, `xcash-dpops` will only run on a **Linux/Unix OS**. We recommend installing it on a Ubuntu VPS/dedicated server (18.04) for best compatibility. 74 | 75 | The **recommended** system requirement is designed to be ***future-development proof***, meaning that an hardware update should never be needed and still comfortably handle the `xcash-dpops` program. 76 | 77 | | | Minimum | Recommended | 78 | |--------------------|----------------------------------------|---------------------------------------| 79 | | **OS** | Ubuntu 18.04 | Ubuntu 18.04 | 80 | | **CPU** | 4 threads, 2.0 GHz or more per thread | 4 threads, 2.0 GHz or more per thread | 81 | | **RAM** | 6GB | 32GB | 82 | | **Hard Drive** | 50GB | 2TB | 83 | | **Bandwidth Transfer** | 100GB per month | 500GB per month | 84 | | **Bandwidth Speed** | 100 Mbps | 500 Mbps | 85 | 86 | ### Dependencies 87 | 88 | The following table summarizes the tools and libraries required to run X-Cash's DPoPS program. 89 | 90 | | Dependencies | Min. version | Ubuntu package | 91 | | :--- | :--- | :--- | 92 | | **GCC** | 4.7.3 | `build-essential` | 93 | | **CMake** | 3.0.0 | `cmake` | 94 | | **pkg**-**config** | any | `pkg-config` | 95 | | **OpenSSL** | any | `libssl-dev` | 96 | | **Git** | any | `git` | 97 | | **MongoDB** | 4.0.3 | Install from [binaries](https://www.mongodb.com/download-center/community) | 98 | | **MongoDB C Driver** \(includes BSON libary\) | 1.13.1 | Build from [source](https://github.com/mongodb/mongo-c-driver/releases/) | 99 | | **`xcash-core`** | Latest version | [download the latest release](https://github.com/X-CASH-official/X-CASH/releases) or [build from source](https://github.com/X-CASH-official/X-CASH#compiling-x-cash-from-source) | 100 | 101 | ### Installation 102 | 103 | To install the `xcash-dpops` program and the related services to set up a delegate node, have a look first at our [server setup guide](https://docs.xcash.foundation/dpops/server-setup). 104 | 105 | Then, run the `autoinstaller.sh` script and follow [our guide](https://docs.xcash.foundation/dpops/installation-process#installer-script). 106 | ```shell 107 | source <(curl -sSL https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/master/scripts/autoinstaller/autoinstaller.sh) 108 | ``` 109 | 110 | > To build everything from source, follow our **[manual installation](https://docs.xcash.foundation/dpops/installation-process#manual-installation-process)** guide. 111 | 112 | ### Maintenance 113 | 114 | All delegates will be able to use the [maintenance script](https://github.com/X-CASH-official/xcash-dpops/blob/master/scripts/management/xcash-maintenance) to easily view there statistics and to check there system. 115 | 116 | ```shell 117 | bash -c "$(curl -sSL https://raw.githubusercontent.com/X-CASH-official/xcash-dpops/master/scripts/management/xcash-maintenance)" 118 | ``` 119 | 120 | If you choose to setup the delegate as a shared delegate, you will be able to view additional statistics by using the IP of the delegate in any web browser, as the [Delegates Pool Website](https://github.com/X-CASH-official/delegates-pool-website) is automatically installed. 121 | 122 | If you choose to setup the delegate as a solo delegate, you have the option of installing the [Delegates Supervisor](https://github.com/X-CASH-official/delegates-supervisor) --------------------------------------------------------------------------------