1. The following are some commonly used mathematical functions, using them is safer and more reliable
addmod(uint x, uint y, uint k) returns (uint): Calculates x + y modulo k.
mulmod(uint x, uint y, uint k) returns (uint): Calculates x * y modulo k.
2. Hash function related API
Hash function is also called hash function: input of arbitrary length is transformed into output of fixed length through hash algorithm (MD4, MD5, ripemd-160, SHA "Secure Hash Algorithm" cryptographic hash function family).
SHA Family:
SHA1: 160-bit value, currently proven not to be particularly secure, it is possible that different input values will get the same hash value
SHA2: SHA-224, SHA-256, SHA-384 and SHA-512. The different numbers behind represent the length of the calculated hash value.
SHA3: Keccak algorithm
What hash functions does solidity provide?
keccak256(...) returns (bytes32): Computes the hash value of an indefinite-length input based on the Keccak-256 hash algorithm.
sha256(...) returns (bytes32): Computes the hash value of an input of variable length based on the SHA-256 hash algorithm.
ripemd160(...) returns (bytes20): Computes the hash value of an indefinite-length input based on the RIPEMD-160 hash algorithm.
sha3(...) returns (bytes32): This is actually an alias for the keccak256 function, which is no longer recommended in Solidity 0.4.16 and later versions.
The hash value of the function selector in Solidity is calculated using the Keccak256 hash algorithm, and the first 4 bytes of the hash value are used as the identifier of the function selector.
3. ecrecover function
We can recover the address associated with the public key through elliptic curve signature, ecrecover(bytes32 hash,uint8 v,bytes32 r,bytes32 s) returns(address)
The four parameters are:
hash: hash value of the signed data, r, s, and v come from the signature result string respectively.
r = signature[0:64]
s = signature[64:128]
v = signature[128:130]+27