From 0200572b4f27e5046f76d5077bf2dc42bacefe0f Mon Sep 17 00:00:00 2001 From: Simon Jentzsch Date: Mon, 30 Dec 2019 20:20:50 +0100 Subject: [PATCH] add cmake option to reduce size --- CMakeLists.txt | 6 ++++++ docs/1_install.md | 7 +++++++ include/in3/bytes.h | 12 ++++++------ include/in3/data.h | 6 +++--- include/in3/utils.h | 4 ++-- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6f269635..5e63c0fa3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,13 @@ OPTION(ETH_NANO "build minimal eth verification.(eth_getTransactionReceipt)" ON) OPTION(ETH_BASIC "build basic eth verification.(all rpc-calls except eth_call)" ON) OPTION(ETH_FULL "build full eth verification.(including eth_call)" ON) OPTION(IN3API "build the USN-API which offer better interfaces and additional functions on top of the pure verification" ON) +OPTION(USE_PRECOMPUTED_EC "if true the secp256k1 curve uses precompiled tables to boost performance. turning this off makes ecrecover slower, but saves about 37kb." ON) +if (USE_PRECOMPUTED_EC) + ADD_DEFINITIONS(-DUSE_PRECOMPUTED_CP=1) +else() + ADD_DEFINITIONS(-DUSE_PRECOMPUTED_CP=0) +endif() if(ETH_FULL) ADD_DEFINITIONS(-DETH_FULL) set(IN3_VERIFIER eth_full) diff --git a/docs/1_install.md b/docs/1_install.md index 294d2d3de..164e5078e 100644 --- a/docs/1_install.md +++ b/docs/1_install.md @@ -161,6 +161,13 @@ Default-Value: `-DTRANSPORTS=ON` Default-Value: `-DUSE_CURL=ON` +#### USE_PRECOMPUTED_EC + + if true the secp256k1 curve uses precompiled tables to boost performance. turning this off makes ecrecover slower, but saves about 37kb. + +Default-Value: `-DUSE_PRECOMPUTED_EC=ON` + + #### USE_SCRYPT if scrypt is installed, it will link dynamicly to the shared scrypt lib. diff --git a/include/in3/bytes.h b/include/in3/bytes.h index 64cab312b..570608cf7 100644 --- a/include/in3/bytes.h +++ b/include/in3/bytes.h @@ -73,13 +73,13 @@ typedef struct { bytes_t b; /**< the bytes struct */ } bytes_builder_t; -bytes_t* b_new(char* data, int len); /**< allocates a new byte array with 0 filled */ -void b_print(bytes_t* a); /**< prints a the bytes as hex to stdout */ -void ba_print(uint8_t* a, size_t l); /**< prints a the bytes as hex to stdout */ -int b_cmp(bytes_t* a, bytes_t* b); /**< compares 2 byte arrays and returns 1 for equal and 0 for not equal*/ -int bytes_cmp(bytes_t a, bytes_t b); /**< compares 2 byte arrays and returns 1 for equal and 0 for not equal*/ +bytes_t* b_new(const char* data, int len); /**< allocates a new byte array with 0 filled */ +void b_print(const bytes_t* a); /**< prints a the bytes as hex to stdout */ +void ba_print(const uint8_t* a, size_t l); /**< prints a the bytes as hex to stdout */ +int b_cmp(const bytes_t* a, const bytes_t* b); /**< compares 2 byte arrays and returns 1 for equal and 0 for not equal*/ +int bytes_cmp(const bytes_t a, const bytes_t b); /**< compares 2 byte arrays and returns 1 for equal and 0 for not equal*/ void b_free(bytes_t* a); /**< frees the data */ -bytes_t* b_dup(bytes_t* a); /**< clones a byte array*/ +bytes_t* b_dup(const bytes_t* a); /**< clones a byte array*/ uint8_t b_read_byte(bytes_t* b, size_t* pos); /**< reads a byte on the current position and updates the pos afterwards. */ uint32_t b_read_int(bytes_t* b, size_t* pos); /**< reads a integer on the current position and updates the pos afterwards. */ uint64_t b_read_long(bytes_t* b, size_t* pos); /**< reads a long on the current position and updates the pos afterwards. */ diff --git a/include/in3/data.h b/include/in3/data.h index 7026ca0b2..0f660c8f5 100644 --- a/include/in3/data.h +++ b/include/in3/data.h @@ -124,11 +124,11 @@ d_token_t* d_get_at(d_token_t* item, const uint32_t index); d_token_t* d_next(d_token_t* item); /**< returns the next sibling of an array or object */ void d_serialize_binary(bytes_builder_t* bb, d_token_t* t); /**< write the token as binary data into the builder */ -json_ctx_t* parse_binary(bytes_t* data); /**< parses the data and returns the context with the token, which needs to be freed after usage! */ -json_ctx_t* parse_binary_str(char* data, int len); /**< parses the data and returns the context with the token, which needs to be freed after usage! */ +json_ctx_t* parse_binary(const bytes_t* data); /**< parses the data and returns the context with the token, which needs to be freed after usage! */ +json_ctx_t* parse_binary_str(const char* data, int len); /**< parses the data and returns the context with the token, which needs to be freed after usage! */ json_ctx_t* parse_json(char* js); /**< parses json-data, which needs to be freed after usage! */ void json_free(json_ctx_t* parser_ctx); /**< frees the parse-context after usage */ -str_range_t d_to_json(d_token_t* item); /**< returns the string for a object or array. This only works for json as string. For binary it will not work! */ +str_range_t d_to_json(const d_token_t* item); /**< returns the string for a object or array. This only works for json as string. For binary it will not work! */ char* d_create_json(d_token_t* item); /**< creates a json-string. It does not work for objects if the parsed data were binary!*/ json_ctx_t* json_create(); diff --git a/include/in3/utils.h b/include/in3/utils.h index 66357d907..04a7ee3c1 100644 --- a/include/in3/utils.h +++ b/include/in3/utils.h @@ -104,7 +104,7 @@ bytes_t* hex_to_new_bytes(const char* buf, int len); int bytes_to_hex(const uint8_t* buffer, int len, char* out); /** hashes the bytes and creates a new bytes_t */ -bytes_t* sha3(bytes_t* data); +bytes_t* sha3(const bytes_t* data); /** writes 32 bytes to the pointer. */ int sha3_to(bytes_t* data, void* dst); @@ -116,7 +116,7 @@ void long_to_bytes(uint64_t val, uint8_t* dst); void int_to_bytes(uint32_t val, uint8_t* dst); /** duplicate the string */ -char* _strdupn(char* src, int len); +char* _strdupn(const char* src, int len); /** calculate the min number of byte to represents the len */ int min_bytes_len(uint64_t val);