Stack Exchange Network

Stack Exchange network consists of 175 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

4
votes
1answer
18 views

Is pre 0.5.0 keccak256(a,b) equivalent to post 0.5.0 keccak256(abi.encodePacked(a,b))?

In pre 0.5.0 Solidity if you wanted to hash a some set of data you would do keccak(a, b, c). Post 0.5.0 keccak only takes 1 arg and it is suggested to use keccak(abi.encodePacked(a,b,c)) instead But ...
2
votes
1answer
36 views

Where is string stored in solidity storage?

I'm trying to check where is stored a string in storage in Solidity. For testing this I'm using this code: pragma solidity 0.5.4; contract AssemblyString { string s; // slot 0 function set(...
1
vote
1answer
32 views

block hash from block-header rlp [duplicate]

Given the RLP of a block header, how do i get the block hash? https://github.com/ethereum/go-ethereum/blob/master/core/types/block.go#L99 The above link says: Hash returns the block hash of the ...
0
votes
1answer
37 views

How to compare two bytes32?

I was using strings before I read that using bytes is gas cheaper. Now I changed my strings to bytes32 but I don't know how to compare them. I need to check if two bytes32 are equal in the require ...
0
votes
1answer
49 views

keccak256 string comparison failure

When trying to compare a string from storage to a string being passed into a function (memory), I am getting the following error when attempting to convert the memory string using keccak256(). What am ...
0
votes
1answer
30 views

Safe for random number?

My thought is that we come up with a random number in one block and make it private so no one can see it. The timer will allow a few blocks to be mined and then the revealNumber function allows the ...
0
votes
0answers
40 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
143 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
91 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
71 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
282 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
vote
2answers
232 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
26 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
176 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
56 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
46 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
64 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
123 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
86 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
265 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
318 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
204 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
394 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
115 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
362 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
140 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
234 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
1k 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
47 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: ...
6
votes
1answer
516 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
178 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
442 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
196 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
274 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
166 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
439 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
168 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
58 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
85 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
388 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 ...
-1
votes
2answers
296 views

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

Is it possible to do sha512 within a smart contract? Or, not?
1
vote
2answers
130 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
639 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
416 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
444 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
1k 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
175 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
214 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 = ...