126

Ethereum uses KECCAK-256. It should be noted that it does not follow the FIPS-202 based standard (a.k.a SHA-3), which was finalized in August 2015. According to this, NIST changed the padding to SHA3-256(M) = KECCAK [512] (M || 01, 256). This was different from the padding proposed by the Keccak team in The Keccak SHA-3 submission version 3 (final, winning ...


26

Jehan's answer is great, but we need to explain one more thing: Why does sha3(1) in solidity produce b10e2d...fa0cf6? This is because solidity's sha3 function hashes its inputs based on the argument types. Thus the value 1 will generate a different hash if it is stored as bytes8, bytes16, bytes32, etc. Since sha3(1) is being passed 1 as a number literal, it ...


21

keccak256 (new alias for sha3) is cheapest. Source: Yellow Paper Appendix G mentions the gas cost of sha3 is: 30 gas + 6 gas for each word (rounded up) for input data to a SHA3 Keccak-256 operation. Appendix E has the costs for the others. sha256 (SHA2-256) costs: 60 gas + 12 gas for each word (rounded up) for input data to a SHA2-256 operation. ...


15

To make it clearer that Ethereum uses KECCAK-256 instead of the NIST standardized SHA-3 hash function, Solidity 0.4.3 has introduced keccak256. (It is an alias to sha3, meaning that keccak256 produces identical results to sha3, but with the intent to avoid confusion, especially for developers new to Ethereum.) It's recommended that new code use keccak256 ...


14

According to Vitalik Buterin on r/ethereum, the difficulty bomb was slowed down with homestead a bit. As it turns out, with the change in the difficulty adjustment algorithm brought about in the last hardfork, the ice age will come very slowly indeed. Originally, the maximum amount by which the difficulty could adjust was 1/2048x, and so given a natural ...


12

Ethereum uses Modified Merkle Patricia Tries for transactions (as well as for state and transaction receipts). The key for a transaction in the trie is its RLP encoded index in the transaction list of a block. See a good explanation of how Patricia Tries are constructed ELI5 How does a Merkle-Patricia-trie tree work? Here is an example of how the state trie ...


10

The block header is the hash returned from generating a Merkle tree that is below the current difficulty target for the blocks data. What's a hash? In order to understand what the block header is you need to understand what a hashing function is. A hashing function is a one way(non invertible function) that maps a set of inputs to a set of outputs hash(s) -...


10

Solidity docs say that sha256 (and sha3, ripemd160) arguments are tightly packed: “tightly packed” means that the arguments are concatenated without padding. This means that the following are all identical: sha3("ab", "c") sha3("abc") sha3(0x616263) sha3(6382179) sha3(97, 98, 99) Using the question's example of a = sha256(uint ...


9

The changes to the code were made in August in this commit, with the meaty parts of the maths being found in core/chain_util.go. The constant increase in difficulty is due to an additional exponentiation step in the algorithm. A quick back-of-the-envelope calculation can be found here, and would suggest that after 22 months (from August 2015) the average ...


9

Solidity use HEX values internally. > web3.sha3(web3.toHex(1)) "5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2"


8

Solidity's sha3 function hashes the byte representation of a uint. That is, the number in hex (base 16), padded to 32 bytes. 32 empty bytes in hex representation is 64 zeros. To do this in JS, we can utilize the infamous left-pad package: const jsHashWeb3 = web3.sha3(leftPad((1).toString(16), 64, 0), { encoding: 'hex' }) // ...


7

from an answer to What are the key differences between the draft SHA-3 standard and the Keccak submission?: No they did not, the internals and security levels have not been changed from the draft Keccak submission, only the padding rule has changed. The padding change is the only difference, this allows future tree hashing modes as well as the ...


5

keccak256 is available in Solidity 0.4.3 and later. If you're using browser-solidity, Solidity 0.4.4 and later is needed: keccak256 Error Undeclared identifier in browser-solidity


5

The return value of sha256 is bytes32. So use bytes32 a = sha256(...) and do the same for b. This will fix the compiler errors and a == b will work. But currently you cannot pass a struct to hashing functions like sha256, keccak256: https://github.com/ethereum/solidity/issues/980. So generally the members of the structs have to be compared against each ...


5

With a recent (>=1.0) version of pysha3 you can recreate the method ID with: from sha3 import keccak_256 sha3_hash = keccak_256("baz(uint32,bool)").hexdigest() method_id = "0x"+sha3_hash[:8] print method_id If your pysha3 is old (eg pinned atpysha3==0.3) you need: from sha3 import sha3_256 sha3_hash = sha3_256("baz(uint32,bool)").hexdigest() method_id = "...


5

Block number is not unique you can have two or more blocks with the same number. The chain will eventually sentle on one of them, but for a period of time any of them can be valid, ie some nodes on the network will see one of them to be valid and others nodes can see a different block. Usually the period of time is brief, ie less than five blocks, but in ...


5

Below are the steps to calculate blockHash, given a blockNumber: Step1. eth.getBlock(400000) Output:{ difficulty: '6022643743806', extraData: '0xd583010202844765746885676f312e35856c696e7578', gasLimit: 3141592, gasUsed: 0, hash: '0x5d15649e25d8f3e2c0374946078539d200710afc977cdfc6a977bd23f20fa8e8', logsBloom: '...


4

Ethash vs Equihash memory hardness isn't a constant - it changes with time - but I'll try to provide a (very basic and generalised) method that you could use to work out what it is at any point in time. Ethereum uses a generated DAG file which increases in size every 30,000 blocks (called an epoch). As of writing the current Ethereum epoch is #151 and the ...


4

A pure Solidity version of SHA1 can be found in this repository. (See sha1.sol to jump to the code.) From the README: Pure-solidity implementation of the SHA1 hash function, heavily optimised using inline-assembly. Gas consumption is approximately 56k per 512 bit block.


4

From what I can tell, no. AsicBoost works by... "...speeding up Bitcoin mining in general (for ASICs and CPUs alike) by reducing the frequency of computing one part of the SHA-256 calculation." So AsicBoost is keyed specifically for SHA-256 calculations, with SHA-256 itself being a member of the SHA-2 family of crytographic hash functions. Ethereum ...


4

SHA3 is just a name and the underlying cryptographic algorithms are elected by an international commitee. There is no reason why Ethereum should change such a fundamental thing like the basic hash function. This puts the network consensus in danger and would mean a huge effort in upgrading all software and broadcasting the information to all members of the ...


3

Saw the following from a recent paper published on February 19 2016. We have uncovered a worrying lack of defense-in-depth in Bitcoin. In most cases, the failure of a single property in one cryptographic primitive is as bad as multiple failures in several primitives at once. For future versions of Bitcoin, we recommend including various ...


3

For browser-solidity, keccak256 is fixed in version 0.4.4 and later. keccak256 is recommended to use, it's identical to sha3, and is less confusing because Ethereum does not use the final SHA-3 standard, but the original winning algorithm named Keccak. More contracts using keccak256 will prevent confusion such as Why aren't Solidity sha3 hashes not ...


3

the keccak256() is an alias for the sha3 function to avoid any confusion with the sha-3 standard (The opcode is still called SHA3.) this alias was adopted this month so the old compiler don't recognize it. so use sha3 instead. The available hashing functions are sha3, sha256, ripemd160: pragma solidity ^0.4.0; contract C { function hashingsha3 (...


3

4371658 (7837 block confirmations) This means that your transaction was mined in block 4371658. That block was at Oct-16-2017 03:00:36 PM +UTC, about 21 hours before your question was posted. The 7837 block confirmations means that the transaction is irrevocably part of the network. Usually 30 or so confirmations are regarded as enough, which is 7-8 ...


3

FNV = Fowler–Noll–Vo hash function. From the main Ethash page (which contains a link to Wikipedia): We use an algorithm inspired by the FNV hash in some cases as a non-associative substitute for XOR. At the risk of defining what perhaps you already know... Associativity: Within an expression containing two or more occurrences in a row of the ...


3

Like any hash, it has an infinite input space. This enables one to "make a hash" of a super large file. The hash should entirely change if a single bit of data in the source is different - unlike say a CRC32, or a checksum. It means your password could be a million chars long maybe. It's stored on disk as a hash, much smaller in size. Regarding Keccak, it ...


3

The results are for hashing different numbers of zero bytes: keccak256('') is the hash of 0 zero bytes. keccak256(address(0)) is the hash of 20 zero bytes keccak256(uint(0)) is the hash of 32 zero bytes (same for bytes32 type) The way keccak pads the input accounts for the different outputs.


3

Found this article, maybe is interesting for you! https://hackernoon.com/are-ethereum-contracts-vulnerable-to-hash-table-poisoning-attacks-a4d9241e16c4


3

First you need to know that sha256 and keccak256 functions are not the same. Check the docs to see available functions. sha256 (with pyhton): >>> sha256("Hello World!").hexdigest() '7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069' keccak256 (with web3): web3.utils.keccak256("Hello World!") '...


Only top voted, non community-wiki answers of a minimum length are eligible