Skip to content
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

Update Contract #8

Open
wants to merge 440 commits into
base: main
Choose a base branch
from
Open

Update Contract #8

wants to merge 440 commits into from

Conversation

Hirama
Copy link

@Hirama Hirama commented Dec 12, 2023

No description provided.

mmv08 and others added 30 commits August 1, 2023 14:37
Change code block language identifier
Formal verification: Add rules for owners
Formal verification: Add rules for modules
Merge main into checkSignatures branch
mmv08 and others added 30 commits September 6, 2024 12:41
…loyment (#822)

merging #742 broke the build because it used a different deployer
account. This PR fixes it by using the new one in the SafeToL2Setup
contract deployment
)

This PR makes the changes based on Certora's audit report from the
branch `release/v1.4.1-2` to `main`.

In the release branch, we used the `ISafe` contract written inside the
respective library files, but with `main`, we use the `ISafe` standard
interface in the `interfaces` folder. Similarly, `Enum` was moved from
`common` to `libraries`, and thus that is used for the same in the
migration contracts.

Note: A `fmt` change was made to `DebugTransactionGuard.sol`.
This PR adds the Audit Report conducted on the Safe Library Migration
Contracts by the Certora Team and updates the `CHANGELOG` with the
contract addresses (cherry picked from
aa14911)

Closes #785
Based on #829 

Some extra changes:
- Adding FV to Certora Workflow
- Remove the unused `data` from the `SafeMock`.
- EOF and some capitalization changes
- Parametric argument to some rules

---------

Co-authored-by: Hristo Grigorov <[email protected]>
Co-authored-by: Nicholas Rodrigues Lordello <[email protected]>
Co-authored-by: Mikhail <[email protected]>
Co-authored-by: Nicholas Rodrigues Lordello <[email protected]>
This PR:
- Partially solves
#767 (test
updates for `SafeToL2Upgrade` are still pending)
- It is based on version 1.5.0 because 1.4.1 cannot be compiled at the
moment because we used `.send` in there, and hardhat zksync compiler
plugin needs to be updated to support suppressing errors. I will
cherry-pick it later.
- I updated the `deployContract` function name and return type to be
more self-explanatory
- The main changes were around adding zksync compatible bytecode and
also using the ContractFactory from the "zksync-ethers" package because
in ZkSync you need to interact with a system contract to deploy
contracts and not just send a transaction with the bytecode and
`to` address omitted.

One bug found: matter-labs/hardhat-zksync#1420
This PR:
- Almost Implements #767 by applying the same principles to
SafeToL2Migration tests as in
#833
- I will cherry-pick the changes back to 1.4.1 branch once the hardhat
compiler plugin issue is addressed
This branch:

- [x] fix two function state mutability
- [x] fix husky deprecated command
Previously we only checked coverage using `npm run coverage` which I
believe only checked `hardhat test --network hardhat`, thus not checking
the rest of the types of test based on L1, L2 and ZK. This adds another
job in the CI which checks for the same.
This pull request focuses on cleaning up the `SafeToL2Migration.spec.ts`
test file by removing unused imports and redundant mock setup code.
These changes streamline the test setup and improve code readability.

Code cleanup and simplification:

* Removed the unused `getMock` import from
`test/libraries/SafeToL2Migration.spec.ts`.
* Deleted the setup and usage of `validGuardMock` and `invalidGuardMock`
in the `SafeToL2Migration` library tests, as they were not used in the
actual tests.
[[1]](diffhunk://#diff-75100fb7649ea61385b33880528c60fc7ed991face5d9285fa01ebaeb4616221L79-L86)
[[2]](diffhunk://#diff-75100fb7649ea61385b33880528c60fc7ed991face5d9285fa01ebaeb4616221L116-L117)
Fixes #715

This PR implements error propagation for internal TX so the user/dev can
know the reason for revert instead of generic `GS013`.
While working on an indexer for module events, I noticed this comment is
no longer valid as `SafeL2` now uses `onBeforeExecTransactionFromModule`
to emit the `SafeModuleTransaction` event.
…846)

This pull request includes changes in the `Safe` contract in the
`contracts/Safe.sol` file. The changes involve renaming a variable for
clarity.

Variable renaming for clarity:

*
[`contracts/Safe.sol`](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL415-R415):
Renamed the variable `safeTxHash` to `safeTxStructHash` to better
reflect its purpose in the `encodeTransactionData` function.
[[1]](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL415-R415)
[[2]](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL430-R430)
Bumps [secp256k1](https://github.com/cryptocoinjs/secp256k1-node) from
4.0.3 to 4.0.4.
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/cryptocoinjs/secp256k1-node/commit/756fce19036700a3fc421ba5a9520cd090d2b92a"><code>756fce1</code></a>
4.0.4</li>
<li><a
href="https://github.com/cryptocoinjs/secp256k1-node/commit/8bd6446e000fa59df3cda0ae3e424300747ea5ed"><code>8bd6446</code></a>
elliptic: fix key verification in loadCompressedPublicKey</li>
<li><a
href="https://github.com/cryptocoinjs/secp256k1-node/commit/840834e833f9b077e0f29828140cc8cd91be3ee2"><code>840834e</code></a>
Update elliptic to 6.5.7 (CVE-2024-42461) (<a
href="https://redirect.github.com/cryptocoinjs/secp256k1-node/issues/206">#206</a>)</li>
<li>See full diff in <a
href="https://github.com/cryptocoinjs/secp256k1-node/compare/v4.0.3...v4.0.4">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=secp256k1&package-manager=npm_and_yarn&previous-version=4.0.3&new-version=4.0.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/safe-global/safe-smart-account/network/alerts).

</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
As part of improving the capabilities for indexing safe creation data, a
new set of functions is introduced which emits an extra event named
`ProxyCreationL2` which also emits the `initializer` and `saltNonce`.
The previous function remains the same for backward compatibility.
This pull request includes significant changes to the `Safe` contract
and its associated test suite. The changes focus on optimizing the
encoding of transaction data and enhancing the test coverage for
transaction hash calculations.

### Optimizations in `Safe` contract:

*
[`contracts/Safe.sol`](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL414-R467):
Rewrote the transaction data encoding logic in assembly to avoid
multiple memory allocations, improving gas efficiency.

### Enhancements in test suite:

*
[`test/core/Safe.Signatures.spec.ts`](diffhunk://#diff-d7bc3771858069f85022d38344b6cb5302146da4bafde1ac18910e3d7bfac43bL49-R56):
Enhanced the test case for calculating EIP-712 hash by introducing a
loop to generate and test multiple random transactions.
[[1]](diffhunk://#diff-d7bc3771858069f85022d38344b6cb5302146da4bafde1ac18910e3d7bfac43bL49-R56)
[[2]](diffhunk://#diff-d7bc3771858069f85022d38344b6cb5302146da4bafde1ac18910e3d7bfac43bR72).
The previous test case was inefficient as it contained empty safe
transaction data. The test would still pass if you forgot to include it
in hashing.
* I also added a FV rule to verify hash computation correctness.

### Benchmarks

#### Before
```
  ERC20 - transfer
           Used 51800n gas for >transfer<
    ✔ with an EOA (137ms)
           Used 82980n gas for >transfer<
    ✔ with a single owner Safe
           Used 88874n gas for >transfer<
    ✔ with a single owner and guard Safe
           Used 90024n gas for >transfer<
    ✔ with a 2 out of 2 Safe
           Used 97094n gas for >transfer<
    ✔ with a 3 out of 3 Safe
           Used 97094n gas for >transfer<
    ✔ with a 3 out of 5 Safe
```    

#### After

```
ERC20 - transfer
           Used 51800n gas for >transfer<
    ✔ with an EOA (71ms)
           Used 82494n gas for >transfer<
    ✔ with a single owner Safe
           Used 88375n gas for >transfer<
    ✔ with a single owner and guard Safe
           Used 89547n gas for >transfer<
    ✔ with a 2 out of 2 Safe
           Used 96577n gas for >transfer<
    ✔ with a 3 out of 3 Safe
           Used 96589n gas for >transfer<
    ✔ with a 3 out of 5 Safe
```

On average, it saves ~485 gas, not much, but considering this is the
hottest path, it should result in significant accumulated savings.
(After 44 Safe transactions, a user would save 21k gas - enough for
broadcasting a native token transfer)

### Codesize

It saves 273 bytes in code size.

#### Before
SafeL2 22582 bytes (limit is 24576)

#### After

SafeL2 22309 bytes (limit is 24576)
This PR brings the `ExtensibleFallbackHandler` created
[here](https://github.com/rndlabs/safe-contracts/blob/merged-efh-sigmuxer/contracts/handler/ExtensibleFallbackHandler.sol)
to `safe-smart-account` repo. Changes taken based on [git
diff](main...rndlabs:safe-contracts:main).

Some small changes were made like:
- Adapting tests to the `safe-smart-account` repo.
- Remove unused import.
- Replace global importing (based on our lint setup) with specific
contracts required.
This pull request includes updates to the repository to reflect the new
version 1.5.0, with a few improvements and updates to the documentation,
contracts, and tests.

### Version Updates:
* Updated the version number in `Safe.sol` from `1.4.1` to `1.5.0`.

### Documentation Updates:
* Updated CHANGELOG to new addresses with `v1.5.0` and changes included
with that version.
* Updated `safe_tx_gas.md` to reflect changes in the `Safe.sol`
contract, including detailed inline assembly code for error handling.

### Test Updates:
* Updated migration tests to reflect the new version `1.5.0` in
`UpgradeFromSafe111.spec.ts` and `UpgradeFromSafe120.spec.ts`.
[[1]](diffhunk://#diff-fabd1eff3a7e83fccbd17c2ddd31b90179573d48337eb2d4af14cf7cdc45e68cL28-R28)
[[2]](diffhunk://#diff-fabd1eff3a7e83fccbd17c2ddd31b90179573d48337eb2d4af14cf7cdc45e68cL39-R42)
[[3]](diffhunk://#diff-77a3075c46c527d198eb5d1ccd5c10f9e0fae972ae7e45edc7ced44bcf6883fdL29-R29)
[[4]](diffhunk://#diff-77a3075c46c527d198eb5d1ccd5c10f9e0fae972ae7e45edc7ced44bcf6883fdL40-R43)
* Added new migration test (this is just added as a complimentary check,
detailed checks are already added otherwise with Safe Migration Tests)
to check `v1.3.0` & `v1.4.1` to `v1.5.1`
### 🕓 Changelog

This PR adds a note in the `CHANGELOG` indicating that the `private`
function `encodeTransactionData` has been completely removed and
replaced with an optimised inline-assembly version via PR
[#847](#847).
This pull request includes various minor corrections and improvements to
the codebase, primarily focused on fixing typos and improving clarity in
comments and documentation. The address will be regenerated for the
CHANGELOG in a separate PR once this PR is merged.

### Documentation and Comment Improvements:

* Corrected typos and improved clarity in comments across multiple
files, including `contracts/Safe.sol`,
`contracts/base/FallbackManager.sol`, `contracts/base/GuardManager.sol`,
and more.
[[1]](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL31-R31)
[[2]](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL94-R101)
[[3]](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL167-R167)
[[4]](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL303-R304)
[[5]](diffhunk://#diff-5b429d16265a4811c02f813788ee8a558995600c739f7eff184544767119b3ffL53-R61)
[[6]](diffhunk://#diff-657b684b5cb5e637061eee5f7184f2f07d7077822192dc6e577d1ba786d7dd08L44-R44)
[[7]](diffhunk://#diff-82762908b9416ddadffb149ee4d25f328078fc27f938d454d8a207aad1ec3839L72-R80)
[[8]](diffhunk://#diff-82762908b9416ddadffb149ee4d25f328078fc27f938d454d8a207aad1ec3839L229-R229)
[[9]](diffhunk://#diff-82762908b9416ddadffb149ee4d25f328078fc27f938d454d8a207aad1ec3839L241-R241)
[[10]](diffhunk://#diff-795fb06764b4c2d991707584a31509badf0b036c9401bfbcb82d6bc9fdebab82L8-R8)
[[11]](diffhunk://#diff-795fb06764b4c2d991707584a31509badf0b036c9401bfbcb82d6bc9fdebab82L30-R32)
[[12]](diffhunk://#diff-7a34930a339acfe3b45e163bee3e08df2132c01826e6e03771827a4181c6f567L19-R19)
[[13]](diffhunk://#diff-a7dd65d90b0567bb9ba14ecd4ff414529a934cd3752ccf309800fad93fba354eL12-R12)
[[14]](diffhunk://#diff-45ea681fa13f307d8b998511744a26b824ed0366455c4c8c7b2fec17efbe6b35L26-R26)
[[15]](diffhunk://#diff-2974a1e991d1528f345c77ee21a96dba70e82352e5924666dc2c5576b8ed9637L16-R16)
[[16]](diffhunk://#diff-8f962f6dc833091675056d29e3ee1ad34c70d259a6c6e9371c732e78a7155359L42-R42)
[[17]](diffhunk://#diff-8f962f6dc833091675056d29e3ee1ad34c70d259a6c6e9371c732e78a7155359L119-R119)
[[18]](diffhunk://#diff-19a90186392862f1f41b151cfae86c5d34dffd78e4d358c58386b9240aa31a58L5-R5)
[[19]](diffhunk://#diff-0b2d708a1eb2dc0c8b74b6e40007b2afc7df03bbc4a7f994a0833ddb277df384L10-R10)
[[20]](diffhunk://#diff-62f21ce8850527f34ef2acdacd96d4a2a1150e3e2a7e16457e82236bbd4259d2L14-R14)
[[21]](diffhunk://#diff-4763011ce3c09340f84758cd74f9f9fd7951e1aca207789847ca5c63e7d3ddc9L67-R67)
[[22]](diffhunk://#diff-4763011ce3c09340f84758cd74f9f9fd7951e1aca207789847ca5c63e7d3ddc9L86-R86)
[[23]](diffhunk://#diff-59325c0efc34794e4c2c873712d190bb642968404634af6fe8f5fb585811a41cL54-R54)
[[24]](diffhunk://#diff-850f06cc1a3d3ce68df28ca73abce16a58e42ba86c15ce3667a3ecd8d7155441L89-R90)
[[25]](diffhunk://#diff-35cf5e8e07a21f0128c32349d41c2d671c2c85866f384ac135f89164eb53922fL8-R8)

### Specific Changes:

*
[`contracts/Safe.sol`](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL31-R31):
Corrected several typos in comments to improve readability and accuracy.
[[1]](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL31-R31)
[[2]](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL94-R101)
[[3]](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL167-R167)
[[4]](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL303-R304)
*
[`contracts/base/FallbackManager.sol`](diffhunk://#diff-5b429d16265a4811c02f813788ee8a558995600c739f7eff184544767119b3ffL53-R61):
Fixed a typo in the comment regarding the use of `HandlerContext.sol`.
*
[`contracts/base/GuardManager.sol`](diffhunk://#diff-657b684b5cb5e637061eee5f7184f2f07d7077822192dc6e577d1ba786d7dd08L44-R44):
Improved comment clarity by specifying "the transaction" instead of
"transaction".
*
[`contracts/base/ModuleManager.sol`](diffhunk://#diff-82762908b9416ddadffb149ee4d25f328078fc27f938d454d8a207aad1ec3839L72-R80):
Enhanced comments for better understanding of the setup and validation
processes.
[[1]](diffhunk://#diff-82762908b9416ddadffb149ee4d25f328078fc27f938d454d8a207aad1ec3839L72-R80)
[[2]](diffhunk://#diff-82762908b9416ddadffb149ee4d25f328078fc27f938d454d8a207aad1ec3839L229-R229)
[[3]](diffhunk://#diff-82762908b9416ddadffb149ee4d25f328078fc27f938d454d8a207aad1ec3839L241-R241)
*
[`contracts/base/OwnerManager.sol`](diffhunk://#diff-795fb06764b4c2d991707584a31509badf0b036c9401bfbcb82d6bc9fdebab82L8-R8):
Clarified comments to ensure better comprehension of the setup function
and validation checks.
[[1]](diffhunk://#diff-795fb06764b4c2d991707584a31509badf0b036c9401bfbcb82d6bc9fdebab82L8-R8)
[[2]](diffhunk://#diff-795fb06764b4c2d991707584a31509badf0b036c9401bfbcb82d6bc9fdebab82L30-R32)
*
[`contracts/common/SecuredTokenTransfer.sol`](diffhunk://#diff-7a34930a339acfe3b45e163bee3e08df2132c01826e6e03771827a4181c6f567L19-R19):
Corrected the spelling of "keccak" in the comment.
*
[`contracts/common/StorageAccessible.sol`](diffhunk://#diff-a7dd65d90b0567bb9ba14ecd4ff414529a934cd3752ccf309800fad93fba354eL12-R12):
Fixed a typo in the comment describing the storage reading function.
*
[`contracts/examples/guards/DelegateCallTransactionGuard.sol`](diffhunk://#diff-45ea681fa13f307d8b998511744a26b824ed0366455c4c8c7b2fec17efbe6b35L26-R26):
Improved comment clarity regarding delegate call checks.
*
[`contracts/external/SafeMath.sol`](diffhunk://#diff-2974a1e991d1528f345c77ee21a96dba70e82352e5924666dc2c5576b8ed9637L16-R16):
Enhanced comment for gas optimization explanation.
*
[`contracts/handler/CompatibilityFallbackHandler.sol`](diffhunk://#diff-8f962f6dc833091675056d29e3ee1ad34c70d259a6c6e9371c732e78a7155359L42-R42):
Corrected and clarified comments related to message hashing and call
return values.
[[1]](diffhunk://#diff-8f962f6dc833091675056d29e3ee1ad34c70d259a6c6e9371c732e78a7155359L42-R42)
[[2]](diffhunk://#diff-8f962f6dc833091675056d29e3ee1ad34c70d259a6c6e9371c732e78a7155359L119-R119)
*
[`contracts/handler/HandlerContext.sol`](diffhunk://#diff-19a90186392862f1f41b151cfae86c5d34dffd78e4d358c58386b9240aa31a58L5-R5):
Fixed a typo in the context extraction comment.
*
[`contracts/handler/TokenCallbackHandler.sol`](diffhunk://#diff-0b2d708a1eb2dc0c8b74b6e40007b2afc7df03bbc4a7f994a0833ddb277df384L10-R10):
Improved comment clarity on token callback handling.
*
[`contracts/handler/extensible/SignatureVerifierMuxer.sol`](diffhunk://#diff-62f21ce8850527f34ef2acdacd96d4a2a1150e3e2a7e16457e82236bbd4259d2L14-R14):
Corrected a typo in the interface comment.
*
[`contracts/interfaces/IModuleManager.sol`](diffhunk://#diff-4763011ce3c09340f84758cd74f9f9fd7951e1aca207789847ca5c63e7d3ddc9L67-R67):
Clarified comments regarding module enablement and guard setup.
[[1]](diffhunk://#diff-4763011ce3c09340f84758cd74f9f9fd7951e1aca207789847ca5c63e7d3ddc9L67-R67)
[[2]](diffhunk://#diff-4763011ce3c09340f84758cd74f9f9fd7951e1aca207789847ca5c63e7d3ddc9L86-R86)
*
[`contracts/interfaces/IOwnerManager.sol`](diffhunk://#diff-59325c0efc34794e4c2c873712d190bb642968404634af6fe8f5fb585811a41cL54-R54):
Enhanced comment clarity on owner verification.
*
[`contracts/interfaces/ISafe.sol`](diffhunk://#diff-850f06cc1a3d3ce68df28ca73abce16a58e42ba86c15ce3667a3ecd8d7155441L89-R90):
Improved comment clarity on signature verification.
*
[`contracts/libraries/ErrorMessage.sol`](diffhunk://#diff-35cf5e8e07a21f0128c32349d41c2d671c2c85866f384ac135f89164eb53922fL8-R8):
Fixed a typo in the comment explaining the purpose of the contract.
This pull request includes updates to contract addresses in the
`CHANGELOG.md`, a minor comment correction in `Safe.sol`, and a
rephrasing in the `safe_tx_gas.md` documentation.

### Updates to contract addresses:

*
[`CHANGELOG.md`](diffhunk://#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4edL58-R91):
Updated various contract addresses for `Safe`, `SafeL2`,
`SafeProxyFactory`, `TokenCallbackHandler`,
`CompatibilityFallbackHandler`, `ExtensibleFallbackHandler`,
`MultiSend`, `MultiSendCallOnly`, `SignMessageLib`, `SafeToL2Migration`,
`SafeMigration`, and `SimulateTxAccessor` for both EVM and ZKSync.

### Minor corrections:

*
[`contracts/Safe.sol`](diffhunk://#diff-587b494ea631bb6b7adf4fc3e1a2e6a277a385ff16e1163b26e39de24e9483deL303-R303):
Corrected a comment to fix a typo from "signatures bytes" to "signature
bytes".

### Documentation rephrasing:

*
[`docs/safe_tx_gas.md`](diffhunk://#diff-aeaeca7ce2ac6a208f0dc43d50269b314cafff87237e5123040cbf6f49e9d36cL3-R3):
Rephrased the introduction for better clarity.
This PR does a once-over on memory Safety for the 1.5.0 contracts. In
particular, there were a couple of missing `memory-safe` tags for some
assembly blocks which were preventing the IR assembler from working
correctly.

Additionally, since the `MultiSend*` contracts changed anyway in 1.5.0,
I took this opportunity to change the assembly to be memory-safe so that
we can tag it. Note that it only adds more code in the revert case, so
it should not have a negative impact for most use-cases.

Furthermore, I added a comment explaining why we did not make the
`SafeProxy` contract memory-safe (that is one intentional).

Lastly, I noticed that there were some `eq(..., 0)` assembly calls which
can be written as `iszero(...)` to save some gas and code. Again, it was
an opportunistic change as the affected contracts have changed anyway
and will be re-audited.

---------

Co-authored-by: Shebin John <[email protected]>
It is now ~~1.4.1-2~~ 1.4.1-3 with the migration contracts.
Matter Labs recently renamed `era-test-node` to `zksync-anvil`. This
causes the official `hardhat-zksync-node` package to stop working.

It is possible to patch the NPM package so that it works with `sed`:

```sh
find node_modules/@matterlabs/hardhat-zksync-node/ -type f -exec sed -i "s/era[_-]test[_-]node/anvil-zksync/g" '{}' ';'
```

However, the tests seem to be quite flaky (ran on my machine once, but
the `anvil` node seems to crash quite often).
This pull request includes a small but significant change to the
`package.json` file to enhance the testing process.

Enhancements to testing:

*
[`package.json`](diffhunk://#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L22-R22):
Modified the `test` script to include running `test:zk` to ensure zkSync
tests are executed along with other tests.
The migration tests are defining `describe` blocks asyncronously within
an `it` block. AFAIU, this is a no-no and causes ugly test formatting.
This PR adjusts the test definitions so that they belong to the correct
parent `describe` block (one per migration version).

<details><summary>Test formatting <strong>before</strong>:</summary>

```
  addOwner
    ✔ should add owner and change threshold

  enableModule
    ✔ should enabled module and be able to use it

  multiSend
    ✔ execute multisend via delegatecall

  fallbackHandler
    ✔ should be correctly set

  execTransaction
    ✔ should be able to transfer ETH (48ms)

  addOwner
    ✔ should add owner and change threshold

  enableModule
    ✔ should enabled module and be able to use it

  multiSend
    ✔ execute multisend via delegatecall

  fallbackHandler
    ✔ should be correctly set

  execTransaction
    ✔ should be able to transfer ETH (48ms)

  addOwner
    ✔ should add owner and change threshold

  enableModule
    ✔ should enabled module and be able to use it

  multiSend
    ✔ execute multisend via delegatecall

  fallbackHandler
    ✔ should be correctly set

  execTransaction
    ✔ should be able to transfer ETH (45ms)

  addOwner
    ✔ should add owner and change threshold

  enableModule
    ✔ should enabled module and be able to use it

  multiSend
    ✔ execute multisend via delegatecall

  fallbackHandler
    ✔ should be correctly set

  execTransaction
    ✔ should be able to transfer ETH (49ms)

  addOwner
    ✔ should add owner and change threshold

  enableModule
    ✔ should enabled module and be able to use it

  multiSend
    ✔ execute multisend via delegatecall

  fallbackHandler
    ✔ should be correctly set

  execTransaction
    ✔ should be able to transfer ETH (52ms)

  addOwner
    ✔ should add owner and change threshold

  enableModule
    ✔ should enabled module and be able to use it

  multiSend
    ✔ execute multisend via delegatecall

  fallbackHandler
    ✔ should be correctly set
```

</details>

<details><summary>Test formatting <strong>after</strong>:</summary>

```
  Upgrade from Safe 1.1.1
    execTransaction
      ✔ should be able to transfer ETH (50ms)
    addOwner
      ✔ should add owner and change threshold
    enableModule
      ✔ should enabled module and be able to use it
    multiSend
      ✔ execute multisend via delegatecall
    fallbackHandler
      ✔ should be correctly set

  Upgrade from Safe 1.2.0
    execTransaction
      ✔ should be able to transfer ETH (45ms)
    addOwner
      ✔ should add owner and change threshold
    enableModule
      ✔ should enabled module and be able to use it
    multiSend
      ✔ execute multisend via delegatecall
    fallbackHandler
      ✔ should be correctly set

  Upgrade from Safe 1.3.0
    execTransaction
      ✔ should be able to transfer ETH (52ms)
    addOwner
      ✔ should add owner and change threshold
    enableModule
      ✔ should enabled module and be able to use it
    multiSend
      ✔ execute multisend via delegatecall
    fallbackHandler
      ✔ should be correctly set

  Upgrade from Safe 1.3.0 L2
    execTransaction
      ✔ should be able to transfer ETH (50ms)
    addOwner
      ✔ should add owner and change threshold
    enableModule
      ✔ should enabled module and be able to use it
    multiSend
      ✔ execute multisend via delegatecall
    fallbackHandler
      ✔ should be correctly set

  Upgrade from Safe 1.4.1
    execTransaction
      ✔ should be able to transfer ETH (52ms)
    addOwner
      ✔ should add owner and change threshold
    enableModule
      ✔ should enabled module and be able to use it
    multiSend
      ✔ execute multisend via delegatecall
    fallbackHandler
      ✔ should be correctly set

  Upgrade from Safe 1.4.1 L2
    execTransaction
      ✔ should be able to transfer ETH (51ms)
    addOwner
      ✔ should add owner and change threshold
    enableModule
      ✔ should enabled module and be able to use it
    multiSend
      ✔ execute multisend via delegatecall
    fallbackHandler
      ✔ should be correctly set
```

</details>
This commit disables support for pre-approved signatures from
`msg.sender` for `isValidSignature` calls.

Note that we remove the new 1.5.0-only `checkSignatures` interface in
favour of one with `executor` explicitly provided to avoid issues for
contracts that make use of this function.
This PR fixes the shift amounts in the `SafeProxy` implementation. It
also slightly optimizes how we do the masking by 2 instructions (removes
the need to `PUSH 0` and `SHR`).

I added some additional tests to make sure the masking works as expected
and a comment explaining why we only mask for handling the
`masterCopy()` call.

---------

Co-authored-by: Mikhail <[email protected]>
Co-authored-by: Nicholas Rodrigues Lordello <[email protected]>
…sh` (#872)

This commit adds a detailed warning in the `Safe.sol` contract regarding
potential dirty bits in assembly code for types smaller than 256 bits.
It emphasizes the importance of considering this for future changes
while explaining the rationale behind using assembly for memory
efficiency.

No functional changes were made to the contract logic. This update aims
to improve code clarity and maintainability.

Originally reported by @jhoenicke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.