Questions tagged [keccak]
keccak is a cryptographic family which is used in ethereum and nowerdays provides the standards for sha-3
119
questions
1
vote
0answers
15 views
eip-1967 address calculation
I have read EIP-1967 and i have study how work proxy contracts.
There is something i do not understand in EIP-1967.
Here is what i have understood:
Logic contract's storage variables are stored in ...
1
vote
0answers
40 views
Constructing a Merkle tree of objects
I can keccak strings to construct the leaves of a Merkle tree, for example, ['a', 'b', 'c']. But what's the recommended approach to constructing objects instead of merely 'a'? Let's say:
{
address:...
0
votes
0answers
10 views
How can I generate hash of string received from function argument
I want to generate hash of string received through function argument. Sha256 require bytes in argument. How can I convert and then save hash in _hash variable.
struct ORGANIZATION{
bytes32 hash;
...
0
votes
1answer
22 views
How do I Encrypt Transaction Input Data Encode ABI
I'm buying erc20 token how can I encrypt my transaction input data . I using Javascript WEB3.JS method Can you help me with this?
like this when try on check etherscan. Warning: Unable to decode input ...
1
vote
1answer
122 views
How to sign and verify data with ethereumjs-utils?
In my contract I'm verifying if some data was correctly signed by the owner. It looks like this:
require(
owner() ==
ecrecover(keccak256(abi.encodePacked(this, aCustomId)), v, r, s),
...
1
vote
1answer
35 views
How to get the non-packed solidityKeccak hash in Python Web3
For
Web3.solidityKeccak(['bool'], [True])
, Python Web3 yields: 0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2
This matches the output of keccak256(abi.encodePacked(true)) in ...
0
votes
1answer
45 views
How to implement owner check in Solidity
Is there any EIP that specifies how to implement function in contract, that let's you call any other function as contract owner, with provided signature?
I don't want to reinvent wheel.
For example:
I ...
3
votes
0answers
292 views
What is the computing power of the Ethereum network in FLOPS?
The aproximate computing power of current Bitcoin network in terms of FLOPS (FP32) has been estimated at about ~80,000 exaFLOPS and being aware of the limits of the analogy because of the widespread ...
1
vote
0answers
75 views
How to call the super contract function where msg.sender should be same in solidity?
I am trying to call contract A.fun_A() via Contract C
contract A{
function fun_A(address tenant, uint itemId){
//Here the msg.sender should be msg.sender in C
require(msg.sender == ...
0
votes
1answer
94 views
How to get data location for string > 31 length
The documentation says:
bytes and string are encoded identically. For byte arrays that store
data which is 32 or more bytes long, the main slot stores length * 2 +
1 and the data is stored as usual ...
0
votes
0answers
24 views
Passing a hash value to function
I'm trying to authenticate users by comparing the hashes created by backend server and contract. Seems like "byte32" values cannot be coerced into strings. So, instead I'm converting it into ...
1
vote
1answer
181 views
How to Keccak 256 hash in front end JavaScript before passing it to my smart contract
I would like to build a simple JavaScript (JS) front end that checks if a field submitted is the pre-image of a keccak256 hash I already know in my smart contract. I currently use the following:
...
2
votes
1answer
117 views
Why is there a SHA256 pre-compiled contract when SHA256 is also an opcode?
The question is in the title :). Trying to understand why there is both an opcode and pre-compiled contract for SHA256. To execute the computation, would people canonically "CALL" into the pre-...
1
vote
1answer
83 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
40 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
94 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;...
2
votes
1answer
174 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
99 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
46 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
328 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
190 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
127 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
127 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
394 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
1answer
130 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
71 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
491 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
57 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
1answer
105 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
116 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
45 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
160 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
143 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
247 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
404 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
2k 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
552 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
92 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
103 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
542 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 ...
1
vote
1answer
830 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
342 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(...
2
votes
1answer
2k 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
3answers
962 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
49 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
945 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
172 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
78 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
343 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
240 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 ...