Questions tagged [keccak]
keccak is a cryptographic family which is used in ethereum and nowerdays provides the standards for sha-3
156
questions
0
votes
1
answer
11
views
Need help trying to replicate ethers.utils.solidityKeccak256 in a Rails 6 controller
I'm not super familiar with Ruby or Rails, but I basically need to replicate this Javascript that uses ethersjs and call it from a Rails 6 controller. Anyone have any ideas how to achieve this? I've ...
0
votes
1
answer
55
views
use javascript merkle tree to generate hex proof for solidity merkletree validation
Here is my js code of generating hex proof for solidity verification
const express = require('express')
const { MerkleTree } = require('merkletreejs');
const { bufferToHex } = require('ethereumjs-util'...
0
votes
1
answer
17
views
when i call my function metamask telling "this operation is expected to fail"
Hi guys im trying to create question challenge dapp and i have a checkAnswer() function can accessable from frontend.
My question struct:
struct Question{
string qDesc;
uint qPrize;...
0
votes
0
answers
42
views
Recover address from signature works only with MetaMask
I try to implement Web3 login to my page. It works with MetaMask, but with other wallets (like LRC, Coinbase or Argent) it doesn't - recovered address differs from the original one.
Ethereum\EcRecover ...
0
votes
1
answer
35
views
How to hash an address?
I just want to hash the senders' address
function myHash() public returns(string memory){
return(keccak256(abi.encodePacked(msg.sender)));
}
but no matter what I do I get the ...
1
vote
1
answer
51
views
What is the max number of inputs that can be entered in a keccak256(abi.encodePacked()) function?
I'm learning to use the keccak function on cryptozombies, and seeing that this function takes three inputs:
uint(keccak256(abi.encodePacked(now, msg.sender, randNonce)))
made me wonder how many ...
0
votes
1
answer
51
views
Different keccak256 for the same string
What is the reason that when i try to get the keccak256 values for the same string (which is "0x0000000000000000000000000000000000000000000000000000000000000001" or simply value of 1 in ...
0
votes
0
answers
15
views
Go Ethereum "invalid signature recovery id" when recovery byte is >= 4 [duplicate]
I have a signed message that was generated by Metamask. It looks like this: ...
0
votes
0
answers
12
views
I have made a DAO handler by using mapping of daoName and bytes32 and generated a random no. using keccak but the output is still coming 0;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
contract DAOManager {
mapping(bytes32 => string) public daos;
function _registerDAO(string memory daoName) public returns(bytes32){
...
0
votes
1
answer
72
views
Hash of hex value is different between Solidity and Ethers
Assume you have a string of hex data you want to hash.
In Ethers:
ethers.utils.keccak256("0x1234");
// "0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432"
In ...
5
votes
2
answers
989
views
How to use ethers keccak256?
I tried to use ethers' keccak256 function like this:
import { keccak256 } from "@ethersproject/keccak256";
const signature = keccak256("balanceOf(address)");
But the script ...
0
votes
2
answers
199
views
What exactly is the output of a keccak256() function?
I've been looking through articles and youtube videos and I still don't get it.
I'm trying to get to a place where I can explain it to myself in simple terms (I'm still pretty new to coding).
What I ...
0
votes
1
answer
45
views
Can you get a duplicate hash with params that are NOT a string or array, using keccak256(abi.encodePacked(a, b))?
It's relatively common to confirm a msg.sender is pre-approved for some contract interaction by verifying a signed hash of their address and another parameter. For instance:
bytes32 checkHsh = ...
0
votes
0
answers
27
views
CryptoZombies - Confused on how exactly using "randomNum % 10^16" shortens randomNum to 16 digits?
In the second to last line, I can see that the input argument is being hashed into a random 256-bit hexadecimal number.
Then in the last line, it takes the random number and uses " % dnaModulus&...
0
votes
0
answers
39
views
Keccak hash for empty buffer("0x") is different in "web3-utils" and "ethereumjs-util"
Consider this example:
import { keccak256 } from 'web3-utils'
import { keccak } from 'ethereumjs-util'
let web3UtilHash = keccak256('0x');
// web3UtilHash == null
let ethUtilHash = keccak('0x', 256)...
0
votes
2
answers
42
views
Does SHA256 and/or Keccak consider current date time in hashing?
Does SHA256 and/or Keccak considers current date time in hashing? I am curious how it avoids or reduces chances of collision. With so many wallets addresses getting created, I hope there is some ...
0
votes
1
answer
88
views
What is the return of uint(keccak256(_str));?
I'm doing the chapter 1 of the crypto zombies course.
uint id = zombies.push(Zombie(_name, _dna)) - 1;
NewZombie(id, _name, _dna);
}
function _generateRandomDna(string _str) ...
0
votes
2
answers
393
views
Using ECDSA to verify a signature inside smart contract
Following the technique to verify ethereum signature with ECDSA.
Sign it like you mean it: creating and verifying Ethereum signatures
Signing and Verifying Messages in Ethereum
A Closer Look At ...
1
vote
1
answer
123
views
Unable to construct hash from address and uint256 for ecrecover and signature verification
I am creating a signature with web3.js form a hashed message that contains two numbers and an address:
const tokenIds = [1,2,3];
const state = 1;
const messageHash = web3.utils.keccak256(tokenIds....
0
votes
1
answer
73
views
Minimum and Maximum Values Returned by keccak256
In the statement:
uint256 x = uint256(keccak256(abi.encodePacked(valuesToEncode)));
What’s the minimum and maximum possible values for x?
When I looped random valuesToEncode the smallest resulting ...
0
votes
0
answers
54
views
Why We use hex'ff' for genrate the pair address in uniswapV2 library?
I am working on uniswap router contract for _addLiquadity and there uniswap used uniswapV2library and into that library this below function is return the pair address but i dont understand what first ...
0
votes
0
answers
22
views
Vulnerability detection using Constraint Solving: Problem with the understanding Example of keccak256 as constraint
I am trying to discuss a paper based on Teether tool. It uses constraint programming to detect Vulnerabilities
The text is discussing about an algorithm related to constraint solving and gives an ...
1
vote
1
answer
122
views
How to make ethereum address from public key?
I want to manually create ethereum addres from any str message like that:
const msg = '00'
const pk = bytesToHex(sha256(msg))
//pk is ...
1
vote
0
answers
306
views
How do I perform _hashTypedDataV4 on a struct containing an array of structs
I have signed a typed data, and I am trying to recover the address of the signer from my contract using ECDSA.recover(). But each time I try it, I get an address that is different from the address of ...
0
votes
0
answers
57
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
2
answers
357
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
0
answers
111
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
1
answer
108
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
1
answer
115
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
1
answer
444
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
2
answers
2k
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
0
answers
107
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
1
answer
50
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
1
answer
118
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
2
answers
245
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
1
answer
649
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
...
5
votes
1
answer
3k
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
0
answers
22
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 ...
6
votes
2
answers
513
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
0
answers
419
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
1
answer
423
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
1
answer
1k
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),
...
2
votes
1
answer
1k
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
1
answer
3k
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
1
answer
2k
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
0
answers
267
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
1
answer
349
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
0
answers
167
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 ...
2
votes
1
answer
3k
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:
...
3
votes
1
answer
293
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-...