RE: RE: Solidity开发指南
You are viewing a single comment's thread from:

RE: Solidity开发指南

Words
34
Reading
1 min
Listen
Play
4M

哈希函数(散列函数):任意⻓度的输⼊,通过散列算法,变换成固定⻓度的输出

addmod(uint x, uint y, uint k) returns (uint):
 (x + y) % k使 2**256  0.5.0  k != 0 assert

mulmod(uint x, uint y, uint k) returns (uint):
 (x * y) % k使 2**256  0.5.0  k != 0 assert

MD4  MD5ripemd-160
SHASecure Hask Algorithm

SHA:
SHA-1
SHA-2 : SHA-224SHA-256SHA-384SHA-512
SHA-3 : Keccak 

keccak256() returns (bytes32)  keccak256 computes the Keccak-256 hash of the input.
sha3(...) returns (bytes32)

Solidity provides two methods for encoding data:
    abi.encode:
        Encodes data into bytes with padding
        Preserves all data information
        Safer when dealing with dynamic types
        Produces a longer output due to padding
    abi.encodePacked:
        Performs packed encoding (compressed)
        Produces a shorter output than abi.encode
        More gas efficient
        Risk of hash collisions with dynamic types (collision function)
eg: 
bytes32 s = keccak256(abi.encodePacked(_text, _num, _addr));
//encodePacked一种压缩打包模式,encode则会补零。


sha256(...) returns (bytes32)
ripemd160(...) returns (bytes20) 

ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)
线

hash: rsv
r = signature[0:64]
s = signature[64:128]
v = signature[128:130] + 27 


%  
return 561 % 10;  //1
return 56189 % 100; //89
return 56 % 2; //0
@lemooljiang: | Ecency