171
votes
Accepted
How are ethereum addresses generated?
Recently this article came to my attention that is way more in depth and technical than my more accessible version below. It also walks you through how to generate one on your own. I highly recommend ...
161
votes
Accepted
Which cryptographic hash function does Ethereum use?
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 ...
63
votes
Accepted
Get public key of any ethereum account
You can if and only if a transaction has been sent from the account. When you send a tx, you sign the transaction and it includes these v r and s values. You parse these from the signed tx and then ...
56
votes
Accepted
ecrecover from Geth and web3.eth.sign
I was stuck on this issue as well for a very long time.
So the solution is: Add this prefix string to your Solidity smart contract.
function verify(bytes32 hash, uint8 v, bytes32 r, bytes32 s) ...
44
votes
Accepted
How to encrypt a message with the public-key of an Ethereum address
thx @Edmunx Edgar, i tried to use ECIES, but it failed to install because of a subdepencency.
I now used the bitcore-lib together with bitcore-ecies. This works like expected.
EDIT: I created a npm-...
42
votes
Accepted
What does v, r, s in eth_getTransactionByHash mean?
v, r, s are the values for the transaction's signature. They can be used as in Get public key of any ethereum account
A little more information, r and s are outputs of an ECDSA signature, and v is ...
eth♦
- 78.7k
36
votes
What's a precompiled contract and how are they different from native opcodes?
Even though I do not know the real reason, I will try to guess. There would be the following considerations:
Size of the namespace. There are not so many possible opcodes, so these need to be ...
31
votes
Accepted
How can I verify a cryptographic signature that was produced by an Ethereum address key pair
Solidity and Serpent have ecrecover for this purpose.
ecrecover(bytes32 data, uint8 v, bytes32 r, bytes32 s) returns
(address)
The function arguments are:
data is what was signed. Since it is ...
eth♦
- 78.7k
31
votes
Accepted
When can BLOCKHASH be safely used for a random number? When would it be unsafe?
Just to clarify, the "trivial solution" referred to is about how to produce a series of random numbers from a single random seed.
As a general rule, BLOCKHASH can only be safely used for a random ...
26
votes
Accepted
How does Oraclize handle the TLSnotary secret?
Oraclize stores the TLSnotary secret in an Amazon Web Services (AWS) Virtual Machine.
Using the techniques described here, they are able to provide some additional guarantees regarding the software ...
25
votes
Accepted
Why aren't Solidity sha3 hashes not matching what other sha3 libraries produce?
Ethereum uses Keccak-256, instead of the SHA-3 FIPS 202 standard. In the sha3 libraries you are using, try looking for the option to specify using Keccak-256.
For Python see Getting Method ID "...
eth♦
- 78.7k
22
votes
Accepted
How can I get a mnemonic phrase from a private key?
No, a mnemonic is generated using an hd wallet - a hierarchical deterministic wallet. Private keys are "children" of this mnemonic and there can be millions of them, but there's no way to go back to ...
21
votes
Accepted
Is Ethereum secure against an attack by quantum computers?
Currently, Ethereum uses elliptic curve cryptography, which is not quantum resistant.
In the upcoming Serenity upgrade, however, accounts will be able to specify their own scheme for validating ...
21
votes
Which cryptographic hash function does Ethereum use?
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 ...
eth♦
- 78.7k
18
votes
Account uniqueness guaranteed?
Ethereum addresses are 160 bit hashes, meaning there are 2^160 possible hashes. Per the birthday problem, the chance of a collision rises to 50% when there are about 2^80 accounts created.
To give ...
16
votes
How can I sign a piece of data with the private key of an Ethereum address?
First, you'll need the private key for your account. To generate a brand new key, I use elliptic.js:
import {ec as EC} from 'elliptic';
const ec = new EC('secp256k1');
const keypair = ec.genKeyPair()...
16
votes
Why aren't Solidity sha3 hashes not matching what other sha3 libraries produce?
Extending on this answer:
Ethereum uses Keccak hashing, which was submitted to the NIST competition for SHA3. It was subsequently selected as a winner in 2012, but the final standard was only ...
16
votes
Accepted
Is it safe to reuse Ether addresses?
Currently, Ethereum uses elliptic curve cryptography (ECDSA), the same as Bitcoin. So whatever "unsafe" concerns there are with how Bitcoin transactions are signed, would be the same with Ethereum ...
eth♦
- 78.7k
16
votes
Accepted
How to set private key for Ethers Signer
You could simply replace the 2nd line in your code above and instead define the signer as follows:
const signer = new ethers.Wallet(your_private_key_string, provider);
You could also define a signer ...
15
votes
Accepted
How can I verify a signature with the web3 javascript API?
web3 does not support this feature yet, but it might be coming with web3 1.0.
In the meantime you can use ethereumjs-utils ecrecover feature.
Note that this function expects v to be in {27, 28}, and ...
15
votes
ecrecover from Geth and web3.eth.sign
According to issue #3731:
Geth prepends the string \x19Ethereum Signed Message:\n<length of message> to all data before signing it (https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign). ...
14
votes
What's a precompiled contract and how are they different from native opcodes?
Not an authority, but I know of someone who is...
From Vitalik's article, A Prehistory of the Ethereum Protocol
The second was the idea of “precompiles”, solving the problem of
allowing complex ...
14
votes
Accepted
How can I sign a piece of data with the private key of an Ethereum address?
There's a functionality from the JSON RPC API not yet ported to web3 to sign data directly with one RPC function call, without messing with keys and crypto. If you don't need to sign messages ...
13
votes
Get public key of any ethereum account
I don't think this is possible, since you lose information when going from public key to address:
Start with the public key (64 bytes)
Take the Keccak-256 hash of the public key. You should ...
12
votes
How to encrypt a message with the public-key of an Ethereum address
Assuming you have the public key of the person you want to send a message to (if they've already signed a transaction you can recover it from the signature) it should be possible to encrypt and ...
12
votes
Accepted
Getting an address from ethereumjs-utils ecrecover
ecrecover returns public key, you need to convert it to address with pubToAddress.
pub = ethJsUtil.ecrecover(msg, v, r, s);
addrBuf = ethJsUtil.pubToAddress(pub);
addr = ethJsUtil.bufferToHex(...
12
votes
Accepted
Getting the wrong address back from ecrecover
Geth adds prefix to the message before siginig it in web3.eth.sign (see JSON-PRC spec).
Without this it can be possible to trick user to sign transaction (more here).
So, the correct code to sign ...
12
votes
Get public key of any ethereum account
It is now possible to recover public key from Ethereum transaction without any coding:
Open the transaction in Etherscan.io
Click on vertical ellipsis in the top-right corner
Click on "Get Row ...
11
votes
Accepted
What are effective and secure ways of shuffling a deck of cards in a contract?
Shuffling a deck
Commutative encryption:
Alice and Bob want to shuffle a deck of cards, such that neither knows what the other's hand contains, but the hands are disjoint (i.e. only one may have a ...
11
votes
Accepted
arguments of the sha256 function in Solidity
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 ...
eth♦
- 78.7k
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
cryptography × 211solidity × 39
signature × 38
security × 24
encryption × 19
blockchain × 18
private-key × 18
go-ethereum × 17
addresses × 17
web3js × 14
public-key × 13
ecrecover × 13
ethereumjs × 11
keccak × 11
hash × 10
ecdsa × 10
ether × 9
wallets × 9
accounts × 9
contract-development × 8
contract-design × 8
transactions × 7
tokens × 7
metamask × 7
ethereum-wallet-dapp × 7