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
23 views

Is the primary reason keccak256(a, b, c) was changed to keccak256(abi.encodePacked(a, b, c)) because of the forgery attack vector?

I am/have been a noob developer attempting to develop dApp. When keccak256(a, b, c) was suddenly deprecated years ago, it seemed to me like it just added unnecessary complexity. In hindsight, I have ...
1
vote
2answers
96 views

Which of abi.encodePacked and abi.encode was standard in Solidity compiler before Solidity 0.5?

Before Solidity v0.5, keccak256() took multiple arguments, and after v0.5 it requires a single bytes argument. Which of the two encoding types, encode/encodePacked, did the compiler use?
1
vote
0answers
34 views

Equivalent of CREATE2 address generation in JS

I have this solidity code from PancakeSwap's library, want to generate the same result in JS using ethers or Web3. How can I achieve that ? address(uint(keccak256(abi.encodePacked( hex'ff'...
1
vote
1answer
50 views

Keccak 256 Error

I encountered keccal256 error in binance smart chain based coin. This error occurred in a token generated with cointool.app. I came across this example. how to solve this error? https://blog....
0
votes
1answer
37 views

Decompiling the contract with keccak function

Currently, I'm researching how to construct the solidity version from the bytecode. However, I try to understand how keccak works, but I'm not sure about the parameters (such as the below code) So, ...
0
votes
1answer
87 views

Java Keccak 256 hashing implementation of multiple inputs

What's the best way to achieve the equivalent hashing in Java as below in Solidity? keccak256(abi.encodePacked(arg1,arg2,...))
5
votes
2answers
588 views

How does keccak256 with abi.encodePacked internally works? I am getting two conflicting results

I have two uint256 values -> 2 and 0 When performing: keccak256(abi.encodePacked(uint(2), uint(0))) I got the correct result: 0xabbb5caa7dda850e60932de0934eb1f9d0f59695050f761dc64e443e5030a569 What ...
0
votes
0answers
55 views

Workaround invalid checksum when using ETH Private Key to sign messages sent to contract

I'm using an ETH private key to sign messages sent to a contract. I'm recovering the address from the signature inside the contract to verify the message (This actually took me days to piece together ...
0
votes
1answer
17 views

getting incorrect topic[0] from web3.utils.sha3

I have the following event: event DelegatedManagerSet(bytes32 indexed loanId, address indexed delegator, address indexed delegated, bool isActive); I am trying to calculate the value of topic[0]. I ...
1
vote
1answer
63 views

Why is this Javascript Ethash implementation returning a wrong hash result?

I'm trying to calculate the hash result for the "light" implementation of the Etash algorithm from ethereum/ethash/js but I can't seem to get the correct result. The expected result for ...
0
votes
1answer
54 views

What is the significance of the function keccak256(abi.encode(to, ids))

I have seen a Solidity smart contract made by Polkamon, which is used to store NFT hashes, so that users can create an NFT without minting it, so that they can save Gas fees if they don't like their ...
0
votes
1answer
148 views

When is hashing used when creating a smart contract?

I was going through the solidity docs and in a contract example given I have seen keccak256 used. // Perform checks to determine if transferring a token to the // `OwnedToken` contract should proceed ...
4
votes
1answer
1k views

Solidity's keccak256 hash doesn't match WEB3 keccak hash

TL;DR: I have a method in a contract to calculate a keccak256 hash, and I'm trying to replicate it in Web3, but the hashes don't match. My problem is very similar to the one in this question, but the ...
1
vote
0answers
17 views

How to store in `address` two kinds of addresses at once?

I have a set of address values, each of them can contain a real Ethereum account (user account or contract) or a "virtual" address (an address pseudo-randomly generated by my contract, in ...
5
votes
2answers
206 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
167 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
12 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
241 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
810 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
583 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
950 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 ...
5
votes
1answer
1k 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
184 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
147 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
52 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
1k 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
184 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-...
4
votes
1answer
217 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
79 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
308 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
477 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
263 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
55 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
701 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
317 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(...
1
vote
1answer
328 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
310 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
901 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
217 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
144 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 ...
1
vote
3answers
1k 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
63 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
300 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
201 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
49 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....
2
votes
0answers
366 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
184 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
367 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
644 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 ...
2
votes
2answers
3k 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 ...