Closed
Description
Given: I sign a message with a private key generated using eth.rb
Then: I get a signature
Expected: The signer of the message to be the signer verified on the smart contract
Ruby (Eth.rb)
# Generate new key and wallet address
new_wallet = Eth::Key.new
# Array to be encoded
token_ids = [1,2,3]
# Sign message
get_signature = Eth::Util.method(:prefix_hex) << new_wallet.method(:personal_sign) << Eth::Util
.method(:bin_to_prefixed_hex) << Eth::Util.method(:keccak256) << Eth::Abi.method(:encode)
get_signature.call(['uint256[]'], [token_ids])
# returns 0x656f70ae6747dc4de541fdaea84701a4b06feea22714cdae6b49ebd4e3c32d1b5b96dca9cf232add9ee0d0e35c951f3e940e93d26fcaf22a51413cd058402fb21c
Smart contract
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.9;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
contract VerifySignature {
using ECDSA for bytes32;
function getMessageHash(uint256[] memory ids) public pure returns (bytes32) {
return keccak256(abi.encodePacked(ids));
}
function verify(bytes memory sig, uint256[] memory ids) external pure returns (bool) {
bytes32 messagehash = keccak256(
abi.encodePacked(ids)
);
return messagehash.toEthSignedMessageHash().recover(sig) == 0x2ceBaa61f571C38d41cFFc8605FB3C1ac4d7F6e7;
}
function getSigner(bytes memory sig, uint256[] memory ids) external pure returns (address) {
bytes32 messagehash = getMessageHash(ids);
return messagehash.toEthSignedMessageHash().recover(sig);
}
}
getSigner
returns a different address from the new_wallet.address
@q9f @kurotaky
Is there a difference between how encodePacked in solidity works and encode in eth.rb?
Using v'0.5.3'