ประเภทหนัง
ตัวอย่างหนัง Ethereum: Getting incorrect signer address on verifying the signature with the generated hash of the signed message in solidity
Incorrect signatory address for checking signature in Etherum Solidity
Ethereum is a decentralized, over-source blockchain platform that allows developers to be smarter and decentralized applications (DAPS). One of the most important aspects of the construction of reliable and safer contractions is the check of signatures of transactions.
In this article, we explain the joints about your signing, the solidity used by the programming language for Ethereum intelligent contractions.
The problem: the wrong signing address
*
Intelligent contraction on Wenbuilding Ethereum, the “director” variable is expected to be a private way of transaction. How to apply the applications to the Hesh used in the signed message uses Keccak-2 to meet the wrong Signer Eddresses.
Why does this happen?
The question comes from the “Signer” variable and its relationship with the date of the transaction. In strength, one contraction calls a feature that refreshes
In some cases, this “Rewards” variable can be an incorrect signal to the Eddressesssssss label. This is particles when the signed message created hashja uses the Keccak-256 hash function.
JS Code (according to Keir Finlow-Bates suggestion)
A simple example of break this question:
`Solidity
Pragma solidity ^0.8.0;
Contraact Mycontract {
Eddress public signator; // initialize the default Walue
Uint256 Public Rewards;
Function updatedinner (title _signer).
Signator = _SIGER;
Reward = 0;
}
FUNCTION VERIFYSIGNATURE () at Niceca View Returns (Bool) {
bys memory msg = abi.encodepacked ("hello, world!");
uint256 hash = keccak256 (msg);
Returning signatories [hash] == signatory; // Fighting off inappropriately
}
}
In this example, a contraction is determined When you update the “Signer” variable using the “updatesinner” function, this “Rewards” variable is also a variable.
However, if you were generated, the signed Mating Mesing is Keccak-2 y story Broong Signer Eddress. The reason for this is that the mapping in “Sgners” is a mapping to the right signatories, but the refreshing function.
Solution*
You can also take the following approach to solve the problem:
- Update the “Rewards” variable by the signatory.
- Use the appropriate mark to the appropriate mapping for the appropriate signator.
Here’s an updated example:
`Solidity
Pragma solidity ^0.8.0;
Contraact Mycontract {
Eddress public signator;
Uint256 Public Rewards;
Function updatedinner (address _signer).
Signator = _SIGER;
Reward = 0;
}
FUNCTION VERIFYSIGNATURE () at Niceca View Returns (Bool) {
bys memory msg = abi.encodepacked ("hello, world!");
uint256 hash = keccak256 (msg);
Returning signatories [hash]. Address == Signer; // correctly stories of the correct tagner eddress
}
}
In this updated example, we made a new variable for “Rewards” storage Wenever A Signer changes, updating the “Rewards” variable.