Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [keccak]

keccak is a cryptographic family which is used in ethereum and nowerdays provides the standards for sha-3

0
votes
0answers
34 views

Can I use an address value in such a hash function

I have a method which updates 3 mappings in my contract. To save data I use some items properties and message sender address, which allows easily to get users data. mapping(bytes32 => uint256) ...
1
vote
5answers
100 views

Can I easily generate a public address which has no private key?

I might be wrong in some of the facts that I state here, so please correct me if necessary. My understanding: Private key - 256 bits Public key - 256 bits Public address - the last 160 bits of a ...
0
votes
1answer
40 views

What is the gas cost of keccak256(“abc”)?

According to this answer, the gas cost of keccak256 is: 30 gas + 6 gas for each word (rounded up) for input data to a SHA3 Keccak-256 operation I'm assuming that the size of a word is 256 bits and ...
0
votes
2answers
47 views

Keccak256 check Key

So I need a function that checks if a key fits the hash of that said key. This is what I have: function checkKey(bytes32 hash, bytes32 privateKey) public returns (bool success) { require(...
1
vote
1answer
175 views

Is it safe to use abi.encodePacked in production solidity code?

In my solidity game project, I am using this: if (king == keccak256(abi.encodePacked(player)){ //continue as king } else{ // not king } Where player data type is bytes and king is a player ...
-1
votes
0answers
16 views

Why does ENS's public resolver have a setPubkey function?

The contract at 0x1da022710df5002339274aadee8d58218e9d6ab5 has a setPubkey function, which I assume takes the x and y-coordinates of an ellptic curve (secp256k1 public key). Most guides tell the user ...
1
vote
2answers
134 views

C# how to compute Keccak256 to match Solidity?

I have a simple Solidity function as below: function testKeccak(uint8[] buffer) public pure returns (bytes32) { return keccak256(abi.encodePacked(buffer)); } Testing the keccak256 hash using ...
1
vote
1answer
24 views

How to get two points (x, y) from an encoded pubkey?

this gives a valid address from two points; address(uint256(keccak256(abi.encodePacked(point[0], point[1]))) & 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); but does that mean that if you are ...
4
votes
2answers
130 views

How is the keccak256(a, b) function implemented?

I need to understand how keccak256(a, b) is implemented and how it differs from keccak256(a || b). Is the content padded? I need this because I do not want to allow for vulnerabilities where a user ...
1
vote
2answers
44 views

Common use cases for hashing functions? [closed]

I'm developing my first dapp with solidity and I was wondering in which cases should I use hashing functions like keccak. I know how they work but it is not clear to me when should I use them and to ...
1
vote
0answers
38 views

are all bits of a keccak256 'uniformly distributed'? [closed]

If I have a truly random data source, and generate keccak256 hashes of the numbers of this source: N1 = keccak256(rnd1) N2 = keccak256(rnd2) N3 = keccak256(rnd3) ... are all 256 bits of the ...
0
votes
0answers
51 views

How to hash a value with a address?

The transaction fails on the keccak256 command. How to hash an incoming number together with the address of the sender? Anything else is wrong? Pls tell me, I'm new to this stuff. Failed tx: ...
0
votes
1answer
105 views

Keccak256 collision in function’s prototype

I was reading the github version of the upcoming book Mastering Ethereum, where the author defines the function selector as The first 4 bytes of the Keccak256 hash of the function’s prototype. This ...
0
votes
1answer
77 views

How to get EVENT name from event signature hash?

I fount that some developers can get event_signature_hash for a event's name MyEvent(uint256) by using bellow code: event_signature_hash = w3.sha3(text='MyEvent(uint256)').hex() But vice versa, I ...
1
vote
1answer
180 views

bytes4(keccak256(“function(uint256)”)) vs. (abi.encodeWithSignature(“buyItem(uint256)”)

What is the (a) technical difference between and (b) practical difference between these, i.e., when do you use one or the other: bool result = address(contract).call.value(10)(bytes4(keccak256("...
0
votes
1answer
205 views

How to typecast keccak256 function with multiple arguments to uint256?

solidity ^0.4.19 (works) uint256 randNonce++; return uint256(keccak256(msg.sender, randNonce, now)) solidity ^0.4.24 (throws) uint256 randNonce++; return uint256(keccak256(abi.encodePacked(msg....
-2
votes
1answer
180 views

Why does keccak256() return bytes32 instead of uint256 in Solidity?

A hashing function outputs an integer that is 256 bits long... so why not store it as such?
1
vote
1answer
287 views

From golang sha3 to solidity sha3

Trying to match "golang.org/x/crypto/sha3" lib with solidity sha3() is giving me a hard time. Its been discussed in here, but I somehow cant apply it in go. How do I handle a big.Int type s.t i get ...
2
votes
2answers
109 views

Why public keys are not used directly as account addresses? [duplicate]

I understand that addresses are hashes of the public keys. But why? What is the rationale behind this design decision? And why 160 bits? Why not just use the hash directly? Is 160-bit guaranteed ...
0
votes
0answers
19 views

How to use bytes to get the same hashed output [duplicate]

I previously asked a question here: link to previous question. Found out the answer is to use string instead of bytes here: pragma solidity ^0.4.18; contract C { bytes32 public temp; ...
0
votes
2answers
262 views

solidity ..which hashing algorithm to use?

I have tried using many hashing algorithms but there output in solidity doesn't match with the one given in online converters. Here is my program:- pragma solidity ^0.4.18; contract C { bytes32 ...
0
votes
1answer
116 views

Keccak256 of msg.sender and timestamp: what's the likelihood of an output coincidence?

Let's think about this code: function publishEtherBox (bytes32 _label, string _ownerUrl, uint _lifespan) external onlyWhenRunning() payable { require(ownerToEtherBoxes[msg.sender].length < ...
0
votes
1answer
208 views

Compare byte32 Keccak256 to the same Keccak256 stored in a byte32 array

I want my function to be able to accept an array of Hashed secrets as a parameter and since solidity doesn't allow for strings, I had to use a byte32[]. The string parameter is an intake for the user'...
3
votes
1answer
920 views

SOLIDITY: How to get a bytes32 keccak256 hash of an address and 2 uint256 variables

I would like to know how to get a bytes32 keccak256 hash of an address and 2 uint256 variables. I want something that will look like this. But from the remix IDE errors, I need to make the the 3 ...
0
votes
1answer
42 views

Incorrect result for hash calculation

According to this link, [https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md][1]. The "signing data" becomes: ...
5
votes
1answer
404 views

Compare structs and arrays with keccak256 in order to save gas

Just working on a solidity code last day, I figured out that apart of comparing bytes, strings etc... The Keccak256 will be the perfect solution for comparing large arrays or big structs. Because as ...
1
vote
1answer
149 views

How to derive the storage key of mapping to an account?

I am trying to derive changes of account storage by mapping accounts (here, the accounts represent the key address in the ERC20 balances mapping mapping(address => uint256)) to their corresponding ...
1
vote
2answers
285 views

does keccak256 and sha3 reproduce the same hash ?

I have this solidity method: function hashData(bytes32 data) public constant returns (bytes32) { var hash = keccak256(data, msg.sender); return hash; } for a data = "0x707974686f6e62" and ...
1
vote
2answers
164 views

Solidity: How to verify Keccak-256 value?

I want to pass a Keccak-256 hashed value from the front-end, say a string "experiment". I store the value in Solidity, and, when passing the same value for the second time, a Solidity function needs ...
0
votes
1answer
235 views

how to hash an array of address?

I want to hash a given array of address (using keccak256) into a single variable byte32. for example: function hashOfArray( address [] list) public constant returns (byte32) { var hash = ... ...
0
votes
1answer
154 views

how can I return a hash value using keccak256?

I have this solidity function below. It is supposed to return the hash of a given data, but instead I get this: 0x function hashData (bytes32 data) public constant returns (bytes32) { var hash ...
2
votes
1answer
382 views

Ethereum address genеration and keccаk256

I'm trying to generate eth address on PHP. Having issue with keccak256. I'm using this class: https://github.com/kornrunner/php-keccak It works good, I checked many times on https://emn178.github.io/...
0
votes
1answer
151 views

Elliptic Key Crytography(ECC) for generating Private & Public Key

I want to generate Public-Private Key pair using ECC and then import them to Ethereum for creating an account through Geth. I am working on a Windows machine. What are the steps I should follow for ...
0
votes
1answer
45 views

Handling keccak collisions in decoupled storage pattern

The decoupled storage pattern (https://blog.colony.io/writing-upgradeable-contracts-in-solidity-6743f0eecc88) uses a hash function (keccak) to turn arbitrary length values into 32 byte keys for the ...
2
votes
1answer
78 views

Understanding Low-Level Interface to Logs

This question is about Low-Level Interface to Logs, Solidity Documentation. In given examples we are able to emit event normally: pragma solidity ^0.4.0; contract ClientReceipt { event Deposit( ...
10
votes
1answer
126 views

Is it dangerous to name my function ccccvKygDv?

For those keeping track at home, the function hash of a function named ccccvKygDv() is 0xffffffff, the same as a null address. pragma solidity ^0.4.0; contract NullFunction { function ccccvKygDv()...
0
votes
2answers
336 views

Web3js and keccak different values

In solidity there is the keccak256 function which hashes its arguments. I use the keccak256 to compute and use the result to check if some entries exist in my array. I want to compute the same value ...
0
votes
0answers
68 views

not able to retrive inserted attributes with keccak256 hash in geth (works with remix)

contract: pragma solidity ^0.4.6; contract UserCrud { struct UserStruct { bytes32 userEmail; uint userAge; uint index; bytes32 hash1; } mapping(bytes32 => UserStruct) ...
-1
votes
2answers
261 views

sha512 in Solidity or assembly, does it exist? [duplicate]

Is it possible to do sha512 within a smart contract? Or, not?
0
votes
2answers
114 views

What is insecure about generating a random number with keccak256?

Just read that generating random a random number via keccak256 is insecure. What is insecure about it and what are the implications of insecurity?
6
votes
1answer
598 views

Why doesn't my private key's public key generate the correct public address?

Private Key: 9ccbcabf23e271183dbed503b43277f4c6eee9ac918cd6cda75ebb73ceb35c7d Corresponding Public Address: 0xa73Fb234B1773ed7b115D18A1f0a15579bA2C1e1 (check for yourself on MyCrypto, for example) ...
1
vote
2answers
387 views

Why doesn't my verification of a signed message signature work in PHP?

I am attempting to verify a signed message in PHP. To be clear, I am not looking to interface with JSON-RPC or any external service, which I both a) know works and b) successfully verifies the ...
0
votes
1answer
399 views

Problem with sha3.keccak_256() update method in Python

I made a simple SHA3 Python script to generate Ethereum addresses and priv/pub keys. After that I sent some ETH to those addresses but then found out that priv keys do not correspond to the addresses ...
0
votes
1answer
973 views

How to generate keccak256(STRING,INTEGER) from Javascript?

In my solidity code I use bytes32 generated by keccak256("STRING_VALUE',INTEGER) to store values in the map. One of the sample values that get generated is ...
0
votes
1answer
169 views

Solidity keccak256(“contract.storage.initialised”)

Hi I was searching on upgradeable/upgradable contracts, then I found this Rocket Pool by David Rugendyke https://gist.github.com/darcius/6e8fa4faa6d9139f3950b6f1d9e96038 /// @dev Only allow access ...
0
votes
1answer
176 views

Keccak hash of null values, result in different hashes for different types

I was testing the hash value of null values for different types and I'm curious how it generates different results for different types. Here are the results. String = ...
1
vote
0answers
280 views

keccak256 returns 0x000000000000000

I am using the keccak256 hashing algo to retrieve a message for a signature however I am getting the return value above. Here is the code: function adminAuthorizedSwap(string price, string quantity, ...
1
vote
2answers
397 views

Which sha3 output is the correct one?

Im trying to rewrite the all ethereum address creation and Tx creation in PHP and Im almost there. I have implemented a sha3 but now Im confused on if its giving me the correct output because it ...
0
votes
0answers
230 views

Solidity ecrecover using web3j not working

I am using below solidity file to recover Address from a hash. function recoverAddress(bytes32 operationHash, uint8 v, bytes32 r, bytes32 s) public pure returns (address) { bytes memory prefix = ...
1
vote
1answer
159 views

Correctly address Smart Contract storage address using web3js 1.0.0 library functions

A short while ago, I found a fantastic Medium article explaining Smart Contract storage. The examples in this article have helped me to understand how to read a Smart Contract's storage values from ...