-
Notifications
You must be signed in to change notification settings - Fork 465
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
fix: use dataGas
when calculating message hash of <1.0.0
#4621
Conversation
Branch preview✅ Deploy successful! Storybook: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review by ChatGPT
), | ||
) | ||
}) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Consistency in TypeHash Constants: Consider organizing the constants (
OLD_SAFE_TX_TYPEHASH
andNEW_SAFE_TX_TYPEHASH
) similarly to improve readability and maintainability. Grouping them together with their respective contexts (like versions) can enhance the logical flow. -
Comment Clarification: The inline comment
// <1.0.0 is dataGas
in the test case might lead to confusion. Consider rephrasing it for clarity, such as// For versions <1.0.0, it's dataGas
to clearly relate it to handling within the test case. -
DRY Principle: The encoding parameter list in
getMessageHash
test has repetition. Consider moving the parameter arrays ('address', 'uint256', etc., andSafeTx.to
,SafeTx.value
, etc.) to separate reusable constants or functions to reduce redundancy and improve clarity. -
Type Safety: Instead of using
as const
, defining a type or enum for versions could improve type safety and clarity, making the code more robust to potential version mismatches. -
Functionality Clarification: The test setup for
SafeTx
includes a version switch betweendataGas
andbaseGas
. Consider clarifying the handling ingetMessageHash
, potentially through comments or structuring the code to highlight this distinction, to avoid confusion during future modifications.
Overall, the changes generally follow good practices, but addressing these points could improve code maintenance and readability.
const messageHash = safeTxData | ||
? TypedDataEncoder.hashStruct('SafeTx', { SafeTx: getEip712TxTypes(safeVersion).SafeTx }, safeTxData) | ||
: undefined | ||
const messageHash = safeTxData ? getMessageHash({ safeVersion, safeTxData }) : undefined | ||
|
||
return ( | ||
<> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Function Naming and Consistency:
- In the
getMessageHash
function, consider using consistent naming for variables and functions. For example,tx
is used as a shorthand which could be improved by renaming totransaction
for clarity.
- In the
-
Type Safety:
- The
tx
variable is typed asany
. If possible, provide a more specific TypeScript type instead of usingany
to enhance type safety and catch potential errors during compilation.
- The
-
Direct Modification Avoidance:
- In
getMessageHash
, there is direct mutation of theSafeTx
array element:SafeTx[5].name = 'dataGas'
. This could lead to potential side effects ifSafeTx
is used elsewhere. Consider creating a modified copy instead, adhering to immutability principles.
- In
-
Potential Logic Concerns:
- Ensure that
SafeTx[5]
exists before attempting to access or modify it to avoid potential runtime errors.
- Ensure that
-
Semantic Version Utility:
- The line
const usesBaseGas = semverSatisfies(safeVersion, NEW_SAFE_TX_TYPE_HASH_VERSION)
assumes thatsemverSatisfies
is a valid utility function. Verify the correctness of this approach and ensure it is imported or defined as expected.
- The line
-
Conditional Logic Simplification:
- Review the condition
if (!usesBaseGas)
logic. If more such conditions are expected, consider refactoring by using helper functions or extracting condition checks to be more descriptive.
- Review the condition
-
React Component Logic Separation:
- Within
SafeTxHashDataRow
, try to minimize logic by further separating complex logic outside of the main render function.
- Within
-
Use of Dependencies:
- Ensure all necessary imports for utilities like
TypedDataEncoder
and any other dependencies are correctly imported and up-to-date.
- Ensure all necessary imports for utilities like
No significant issues that require more detailed refactoring suggestions were found.
📦 Next.js Bundle Analysis for safe-wallet-webThis analysis was generated by the Next.js Bundle Analysis action. 🤖
|
Page | Size (compressed) |
---|---|
global |
1016.58 KB (🟡 +98 B) |
Details
The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.
Any third party scripts you have added directly to your app using the <script>
tag are not accounted for in this analysis
If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!
Coverage report
Test suite run success1718 tests passing in 232 suites. Report generated by 🧪jest coverage report action from 10d9e24 |
What it solves
Resolves incorrect message hash for <1.0.0 Safes
How this PR fixes it
For Safe versions >=1.0.0, the SafeTx typehash uses
baseGas
:For Safe versions <1.0.0, the SafeTx typehas uses
dataGas
:When calculating the message hash, we do not take the contract version into account, calculating based on the newer SafeTx typehash.
This conditionally adjusted
baseGas
todataGas
when calculating the message hash for the current Safe, therfore correcting it for <1.0.0 versions.How to test it
Cross-reference message hash match with the following script for <1.0.0 Safes.
Note: an example 0.1.0 Safe is
eth:0xecd11858a4bcc35A51084Ebe672beaCe01142fcA
Checklist