-
Notifications
You must be signed in to change notification settings - Fork 0
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
_isValidSignature
in DefaultAccount.sol
is not compliant to EIP1271 as stated in the documentation
#504
Comments
bytes032 marked the issue as primary issue |
bytes032 marked the issue as sufficient quality report |
QA. This report said more about inconsistency between documentation than any security issues. |
miladpiri marked the issue as disagree with severity |
miladpiri (sponsor) acknowledged |
Looks off, will double check: |
GalloDaSballo changed the severity to QA (Quality Assurance) |
Agree with the sponsor, in this case the comment is wrong The calling function returns the MAGIC_VALUE which is compliant with the EIP |
@VagnerAndrei26 please refrain from making comments before PJQA |
I want to address this issue and give some more explanations since I focused too much on the NatSpec and documentation in the reports. This is not only a comment issue, where the NatSpec/comments are wrong, this is a compliance issue, which most of the time is treated as a Medium on Code4Arena. I specified about documentation and NatSpec, to solidify my arguments about those specific functionalities needing to be EIP1271 compliant. As I said in my report, the function does not return the right value, as the EIP1271 suggests. The return value MUST BE /**
* @notice Verifies that the signer is the owner of the signing contract.
*/
function isValidSignature(
bytes32 _hash,
bytes calldata _signature
) external override view returns (bytes4) {
// Validate signatures
if (recoverSigner(_hash, _signature) == owner) {
return 0x1626ba7e;
} else {
return 0xffffffff;
}
} Considering all of this, I believe this should not be treated as a simple NatSpec/Documentation issue, since it is about EIP compliancy and not just some wrong comments. |
@VagnerAndrei26 the function is not zkSync seems to be using the Validation Scheme from the EIP, but they don't seem to be implementing the EIP |
Hey @GalloDaSballo , thanks for you time again. The main function used is |
After spending quite some time reviewing this, I believe that the interpretation of the issues is incorrect and that QA severity is most appropriate The finding asserts that zkSync is implementing More specifically, the zkSync contracts are using Changing the return value would cause more harm than good as it would brick previous contracts Overall I think this was a welcome suggestion, but is logically equivalent to my discussion here: code-423n4/org#130 |
I understand and respect the final decision |
Per the judge's request, marking as grade-C and closing. |
Lines of code
https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/DefaultAccount.sol#L161-L191
Vulnerability details
Impact
It is stated in the documentation on the ZkSync website and also in the NatSpec of the
_isValidSignature
that the validation should follow the EIP1271 standard but that is not true.Proof of Concept
As you can see, in the documentation of ZkSync there is the section where it talks about Accounts Abstraction
https://era.zksync.io/docs/reference/concepts/account-abstraction.html
section where it speaks about the EIP1271 which is highly encourage to be used in those Accounts, since it is the standard that is endorsed by the ZkSync team
https://era.zksync.io/docs/reference/concepts/account-abstraction.html#eip1271
There are also comments in the NatSpec of
DefaultAccount.sol
contract which states that if the signature is valid it should returnEIP1271_SUCCESS_RETURN_VALUE
, otherwise revertshttps://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/DefaultAccount.sol#L160
In reality the function
_isValidSignature
is not compliant to EIP1271 as it is stated and does not return the value which is should. If we look closely to EIP1271 standard we can see two important things which does not happen in the implementation found inDefaultAccount.sol
:bytes4
magic value of 0x1626ba7e which represents the function signature ofisValidSignature(bytes32,bytes)
, as you can se here https://eips.ethereum.org/EIPS/eip-1271. In the case ofDefaultAccount.sol
the return value is not the correct function signature, as it should, since in case of a valid signature the magic value would beACCOUNT_VALIDATION_SUCCESS_MAGIC
https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/DefaultAccount.sol#L102-L103 which is equal to the selector ofvalidateTransaction
function as you can see here https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/interfaces/IAccount.sol#L7 selector which equates with 0x202bcce7 , different than the one imposed by the EIP1271_isValidSignature
MUST allow external calls https://eips.ethereum.org/EIPS/eip-1271, which in the case ofDefaultAccount.sol
it is not true since the function it isinternal
https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/DefaultAccount.sol#L161Because of those issues the implementation is not EIP1271 compliant, even though it is stated multiple times in the documentation and in the NatSpec, that it is highly encouraged to use the EIP1271 since that is the standard endorsed by the ZkSync team, which could lead to multiple compatibility issues in the long run.
Tools Used
Manual review
Recommended Mitigation Steps
The first problem can be easily solved, since instead of returning the selector of
validateTransaction
which equates to 0x202bcce7, return the correct value of the EIP1271 which is theisValidSignature(bytes32,bytes)
selector that equates to 0x1626ba7e. The second issue is more complicated to be solved, since you intend to have theDefaultAccount.sol
behave like a EOA account, which means that any calls should be successful and return(0,0), which will not be the case if you make the function public and callable by anyone. What I believe should be done is documenting the difference implementation of EIP1271 in theDefaultAccount.sol
, in case you want to keep the functioninternal
, since nowhere is spoken about that and people could assume full compliancy with the standard, which is not true.Assessed type
Other
The text was updated successfully, but these errors were encountered: