EOSIO / eos

An open source smart contract platform
https://developers.eos.io/manuals/eos
MIT License
11.27k stars 3.6k forks source link

All cryptographic hash api functions should accept immutable data pointer #5152

Closed smlu closed 6 years ago

smlu commented 6 years ago

https://github.com/EOSIO/eos/blob/75635168e743c3e65bb6345a1eaedd905581e6b0/contracts/eosiolib/crypto.h#L137

Example above shows sha256 trapdoor function which accepts char pointer for the inputted data but instead the type should be pointer to the const char eg.: sha256( const char* data, ...). Is there any particular reason why it shouldn't be const? The problem is that you always have to const_cast the const references or pointers to constant. This adds unnecessary overhead for the programmer.

The type of data param of crypto_api::encode<T> which I assume is the function called from hash api functions should be also updated to the const char*. No reason to have char pointer there at least I don't see one.

https://github.com/EOSIO/eos/blob/75635168e743c3e65bb6345a1eaedd905581e6b0/libraries/chain/wasm_interface.cpp#L730

taokayan commented 6 years ago

This is exported as "C" API but "C" doesn't support "const"

tbfleming commented 6 years ago

C89 and later has const.

taokayan commented 6 years ago

i see. @tbfleming thanks for correct me.

banshee commented 6 years ago

Looks like the sha256 function was fixed by 1e06d3987328946944afd150f95ac6798176c02d