Questions tagged [keccak]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
11 views

keccak256 output is different on ruby vs javascript…?

Ruby ethereum libraries use: https://github.com/phusion/digest-sha3-ruby require 'digest/sha3' '0x' + Digest::SHA3.new(256).hexdigest('0x0') => "...
1
vote
1answer
19 views

Is it cheaper overall to store a keccak hash or to store a ripemd(keccak) hash?

As titled. I'm learning to build a DApp and I'm wondering if it's worth it to add the extra RIPEMD layer over keccak for a shorter hash to reduce storage costs.
1
vote
1answer
25 views

converting keccak from old version: pragma solidity 0.4.19; [duplicate]

I am trying to compile following code: pragma solidity 0.5.9; contract test{ //https://github.com/ethereum/solidity/issues/3469 address payable owner; mapping (address => bool) pd; uint public sS;...
1
vote
1answer
25 views

Running Solidity's keccak256 in python

I want to run Soliditykeccak256(abi.encodePacked(challenge_number, msg.sender, nonce)) where nonce is uint256, challenge_digest is bytes32, challenge_number bytes32, testTarget is uint. What's the ...
0
votes
1answer
26 views

Solidity keccak behavior

I have a weird issue. I'm trying to keccak256 packed encoded arguments in Rust [which should mimic Soldity's behavior to be checked on chain later]. I've failed for now. To figure out the issue I've ...
0
votes
1answer
38 views

Unable to store hash in blockchain [closed]

I have a major problem/ I've got a simple smart contract that stores data (a text in blockchain and it works well, but when I pass keccak256, it stores only the string passed in as an argument but not ...
2
votes
1answer
71 views

Is any 40 character hex string a valid ethereum address?

I know an ethereum address is generated by getting the last 20 bytes of the keccak-256 hash of the public key, which is 40 hex digits. I also know, an address does not need to have transactions ...
0
votes
1answer
55 views

Solidity. Concatenate and hash two strings

Hi all I need tho sha256 two strings. I am new to solidity. This is what I've got: function addressToString(address _addr) public pure returns(string memory) { bytes32 value = bytes32(uint256(...
0
votes
1answer
35 views

Generating an address from a public key in C++

Example: Input key = 0x025f37d20e5b18909361e0ead7ed17c69b417bee70746c9e9c2bcb1394d921d4ae Output address = 0xd09D3103CcABfb769eDc3e9B01500Ca7241D470A I have been using an algorithm from keccak-tiny....
1
vote
1answer
42 views

How can i `ecrecover` in solidity to verify the digest produced by `web3.utils.soliditySha3` in JS side?

Javascript side: id = 128 uri = "xxx://xxx" hash = web3.utils.soliditySha3(id,uri) sign = web3.eth.accounts.sign(hash1, privateKey) Solidity side: function(uint256 id, string memory uri,bytes v, ...
2
votes
1answer
97 views

Different outputs for Keccak256(), which one is right?

To get a value from contract storage I used this geth code succesfully: var contractAddress = '0x88e726de6cbadc47159c6ccd4f7868ae7a037730' var index = '...
1
vote
0answers
49 views

Cross-posted from Stack-Overflow: Using Google Cloud Key Management Service to sign an Ethereum transaction

Cross-posted from question I've been working on writing a signer service for an Ethereum transaction manager and I need to sign Ethereum transactions using Google KMS Golang APIs. I'll try and ...
2
votes
1answer
43 views

How are we able to send 512 bit hash as a bytes32 variable?

I have a code that is working: solidity function checkSignature(bytes32 h, uint8 v, bytes32 r, bytes32 s) public pure returns (address signer) { bytes memory prefix = "\x19Ethereum Signed ...
0
votes
3answers
203 views

How to generate the full list of function selectors for a contract?

A contract has many functions and how to automatically generate the full selector list, including inherited functions, for the whole contract? Preferred solution shouldn’t require more than a web ...
3
votes
1answer
46 views

Why solidity's keccak returns different value from online generators?

I try to implement my own little modifited commit&reveal voting. I have problem with revael phase. Reveal metod signature look like: function reveal(bytes32[] memory _reveals, bytes32[] memory ...
0
votes
0answers
54 views

Problems trying to implement Nexus (NXS) Skein-Keccak (SK1024) in Golang

) I know this might not be the perfect place to ask, but as ETH is also a Blockchain Tech and also uses Go within their stack, I couldn't find a forum that seems more appropriate. My Problem: I'm ...
0
votes
1answer
37 views

What is the best way to store a hexadecimal value in an array in Solidity?

I am attempting to store a hash (web3.sha3) into an array in a smart contract. What is the best way to do that?
1
vote
1answer
53 views

Is there a way to obtain the same Hash using Keccak256 from Web3 and ZoKrates hash function such as sha256packed?

I am trying to use the hash obtained from keccak256 (applied to a number or input) and using it into sha256packet from ZoKrates (or other function) for comparing it with the Hash obtained in Zokrates ...
0
votes
0answers
39 views

Need to help in adding bigendian support for Keccak256.cpp

Need help in making the keccakf function based on endiness in https://github.com/ethereum/solidity/blob/develop/libdevcore/Keccak256.cpp. I have gone through similar functionality at https://github....
1
vote
0answers
89 views

exploiting keccak for random number generation?

Whenever a ticket will be purchased, a random number will be generated function _mightWin() internal { address _player = msg.sender; // players address uint256 ...
4
votes
1answer
105 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 ...
3
votes
1answer
154 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
231 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 ...
1
vote
2answers
885 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
362 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
78 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
82 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
430 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
442 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
226 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
1k 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
666 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 ...
2
votes
1answer
35 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
746 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
136 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
74 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 ...
1
vote
1answer
243 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
176 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 ...
2
votes
1answer
767 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
753 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
346 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
773 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
138 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
819 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
234 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
359 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
2k 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 ...
1
vote
1answer
78 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
895 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 ...