New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getBaseEncoder to support "uint" #4541
Comments
That does look wrong… I’ll get that fixed right away. Thanks! |
@ricmoo I would much appreciate it! I am trying to deploy my code with ethers V6 as soon as possible. |
In the meantime, you can just use "uint256" instead (which is the same thing), but I will get it out today. :) |
I've added a fix to the repo, but want to sleep on the solution over night before publishing. Please feel free to check ou the change above though. And all dust files have been updated, so you can try it out by installing it (via npm) from the GitHub repo. Would love some feedback. Basically, I normalize the types in the constructor so there is no change to the getBaseEncoder, since the types are also required in other parts of the encoder to reflect what the baseEncoder would use. I also add a case allowing for a custom type of There are test cases too, if curious what I mean. :) |
Thanks. I think it should support |
Still getting error
|
Is that from GitHub? The error indicates you are using 6.10.0, but the fix is only in 6.10.1 (which is not on npm yet). |
You’re right. I need to add the arrayification to that. I’m going to break that out into another function, like I should’ve in the first place. |
I installed as this.
by running command
|
@charlie-kim I've refactored the Array parsing code. I'd love an extra set of eyes to look it over. ;) You should be able to install the |
Hey @ricmoo , I just found out I was running code in lib.commonjs and it didn't have the change you made. What is the process to have the change in the code here? |
The |
The current main branch seems to have the code built for lib.commonjs. I think the current main branch is working but let me test further to make sure. |
FYI, my contract has signature type defined with It looks good to me! |
There shouldn’t be any difference between using |
I tried your above example, swapping out the |
My test called
returns
and
returns
And contract can only validate the signature from the first one. My test uses hardhat-ethers and it does this to create signature.
|
I can successfully test signature by using pure ethers js. But using it with hardhat-ethers does not work with the new version. This one works.
This one does not work.
The work might be on them not you. |
I think I spotted the problem earlier. I just need to prepare a test case for the before-and-after. I think it’s a one-line fix when preparing the payload. Just got back from a tooth extraction though, so I’ll get to it in the next couple hours. :) |
Oh dang! Are you still under influence of anesthesia?? Take it easy! |
Oh no. They just froze my mouth. No crazy anesthesia. :) I've pushed a new version up to GitHub, if you could test against the main branch again? :) |
It works fine now! |
Somehow, the change creates an error in another test when actually calling a contract function to validate the signature. I will let you know after looking into it. |
@ricmoo This is a tough case for me that the latest change seems to work within the tests here. But it breaks the test that used to work in hardhat. I am calling You can find the contract here. https://etherscan.io/address/0xE5D3d7da4b24bc9D2FDA0e206680CD8A00C0FeBD#code
Please let me know if there's any information I can provide to help debugging. I will try to go deeper on the issue as well. |
The contract has a bug in it. When you are computing the keccak256 of a signature you must still use uint256 (not uint). I highly recommend you let Solidity compute those for you, as it will perform all the necessary normalizations (both types, white-space, etc). Using event.selector will save you. You should be able to do: // Define the event if not already defined
event Pay(address user,address collateral,address[] assets,uint[] amounts,uint nonce,uint expiresAt);
// Get the selector, which for an Event is a bytes32
bytes32 public constant PAY_TYPE_HASH = Pay.selector; Make sense? |
I see what is happening now. Is there any chance we can still make |
Without updating the contract? It unfortunately is not possible, as no wallet would be able to produce a valid hash for that (such as MetaMask); the hash is incorrect, so software like MetaMask will correctly reject it. The v5 Typed Encoder should not have worked either though? Also, you should talk to your auditing company, because that is definitely something that should have been caught... |
Actually, the contract has been working in production about a year with V5. We are generating signature in server side and let user call Also, V5 typed encoder uses |
Yikes. That is definitely a bug in v5 then. The hash is not to spec, so would not work with any other (non-buggy ;)) software. It is bad though, since it means wallets cannot accurately represent EIP-712 data to the user. It basically forces "blind signing", when it shouldn't. |
I will have to use v5 for now until we can upgrade the contract 😭 Thank you! |
@ricmoo I am trying to use event selector like you suggested. But the signature cannot be validated with it. Is there a working code sample? I used solidity 0.8.23. |
Ethers Version
6.9.2
Search Terms
hash
Describe the Problem
getBaseEncoder
function crashes whentype
isuint
.match[2]
is an empty string and it is not equal tonull
.https://github.com/ethers-io/ethers.js/blob/main/src.ts/hash/typed-data.ts#L132C2-L132C2
Updating to this might work.
(match[2] == null || match[2] == '' || match[2] === String(width))
Code Snippet
No response
Contract ABI
No response
Errors
No response
Environment
node.js (v12 or newer)
Environment (Other)
No response
The text was updated successfully, but these errors were encountered: