Skip to content

Commit

Permalink
Fix account abstraction upgradeable testing (OpenZeppelin#5248)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx authored Oct 10, 2024
1 parent 95e19c5 commit 518fd94
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ jobs:
with:
check_hidden: true
check_filenames: true
skip: package-lock.json,*.pdf
skip: package-lock.json,*.pdf,vendor
4 changes: 2 additions & 2 deletions contracts/abstraction/utils/ERC4337Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ library ERC4337Utils {
if (validationData == 0) {
return (address(0), false);
} else {
(address agregator, uint48 validAfter, uint48 validUntil) = parseValidationData(validationData);
return (agregator, block.timestamp > validUntil || block.timestamp < validAfter);
(address aggregator_, uint48 validAfter, uint48 validUntil) = parseValidationData(validationData);
return (aggregator_, block.timestamp > validUntil || block.timestamp < validAfter);
}
}

Expand Down
11 changes: 6 additions & 5 deletions contracts/abstraction/utils/ERC7579Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ type ExecType is bytes1;
type ModeSelector is bytes4;
type ModePayload is bytes22;

// slither-disable-next-line unused-state
library ERC7579Utils {
using Packing for *;

CallType constant CALLTYPE_SINGLE = CallType.wrap(0x00);
CallType constant CALLTYPE_BATCH = CallType.wrap(0x01);
CallType constant CALLTYPE_DELEGATECALL = CallType.wrap(0xFF);
ExecType constant EXECTYPE_DEFAULT = ExecType.wrap(0x00);
ExecType constant EXECTYPE_TRY = ExecType.wrap(0x01);
CallType internal constant CALLTYPE_SINGLE = CallType.wrap(0x00);
CallType internal constant CALLTYPE_BATCH = CallType.wrap(0x01);
CallType internal constant CALLTYPE_DELEGATECALL = CallType.wrap(0xFF);
ExecType internal constant EXECTYPE_DEFAULT = ExecType.wrap(0x00);
ExecType internal constant EXECTYPE_TRY = ExecType.wrap(0x01);

function encodeMode(
CallType callType,
Expand Down
2 changes: 2 additions & 0 deletions contracts/mocks/Stateless.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {ERC165} from "../utils/introspection/ERC165.sol";
import {ERC165Checker} from "../utils/introspection/ERC165Checker.sol";
import {ERC1967Utils} from "../proxy/ERC1967/ERC1967Utils.sol";
import {ERC721Holder} from "../token/ERC721/utils/ERC721Holder.sol";
import {ERC4337Utils} from "../abstraction/utils/ERC4337Utils.sol";
import {ERC7579Utils} from "../abstraction/utils/ERC7579Utils.sol";
import {Heap} from "../utils/structs/Heap.sol";
import {Math} from "../utils/math/Math.sol";
import {MerkleProof} from "../utils/cryptography/MerkleProof.sol";
Expand Down
3 changes: 2 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"files": [
"**/*.sol",
"/build/contracts/*.json",
"!/mocks/**/*"
"!/mocks/**/*",
"!/vendor/erc4337-entrypoint/**/*"
],
"scripts": {
"prepack": "bash ../scripts/prepack.sh",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"private": true,
"files": [
"/contracts/**/*.sol",
"!/contracts/mocks/**/*"
"!/contracts/mocks/**/*",
"!/contracts/vendor/erc4337-entrypoint"
],
"scripts": {
"compile": "hardhat compile",
Expand Down
2 changes: 1 addition & 1 deletion scripts/upgradeable/patch-apply.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail

DIRNAME="$(dirname -- "${BASH_SOURCE[0]}")"
PATCH="$DIRNAME/upgradeable.patch"
PATCH="$DIRNAME/${1:-upgradeable.patch}"

error() {
echo Error: "$*" >&2
Expand Down
2 changes: 1 addition & 1 deletion scripts/upgradeable/patch-save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail

DIRNAME="$(dirname -- "${BASH_SOURCE[0]}")"
PATCH="$DIRNAME/upgradeable.patch"
PATCH="$DIRNAME/${1:-upgradeable.patch}"

error() {
echo Error: "$*" >&2
Expand Down
10 changes: 9 additions & 1 deletion scripts/upgradeable/transpile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ set -euo pipefail -x
VERSION="$(jq -r .version contracts/package.json)"
DIRNAME="$(dirname -- "${BASH_SOURCE[0]}")"

# Apply patch to contracts that are transpiled
bash "$DIRNAME/patch-apply.sh"
sed -i'' -e "s/<package-version>/$VERSION/g" "contracts/package.json"
git add contracts/package.json

# Build artifacts
npm run clean
npm run compile

# Check artifacts are correctly built
build_info=($(jq -r '.input.sources | keys | if any(test("^contracts/mocks/.*\\bunreachable\\b")) then empty else input_filename end' artifacts/build-info/*))
build_info_num=${#build_info[@]}

Expand All @@ -20,10 +23,13 @@ if [ $build_info_num -ne 1 ]; then
exit 1
fi

# Apply changes to the excluded contracts (these don't need to in the artifact and may prevent compilation)
git apply -3 "$DIRNAME/upgradeable.excluded.patch"

# -D: delete original and excluded files
# -b: use this build info file
# -i: use included Initializable
# -x: exclude proxy-related contracts with a few exceptions
# -x: exclude vendored and proxy-related contracts with a few exceptions
# -p: emit public initializer
# -n: use namespaces
# -N: exclude from namespaces transformation
Expand All @@ -38,6 +44,8 @@ npx @openzeppelin/upgrade-safe-transpiler -D \
-x '!contracts/proxy/ERC1967/ERC1967Utils.sol' \
-x '!contracts/proxy/utils/UUPSUpgradeable.sol' \
-x '!contracts/proxy/beacon/IBeacon.sol' \
-x 'contracts/vendor/**/*' \
-x '!contracts/vendor/compound/ICompoundTimelock.sol' \
-p 'contracts/access/manager/AccessManager.sol' \
-p 'contracts/finance/VestingWallet.sol' \
-p 'contracts/governance/TimelockController.sol' \
Expand Down
17 changes: 17 additions & 0 deletions scripts/upgradeable/upgradeable.excluded.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/contracts/vendor/erc4337-entrypoint/core/EntryPoint.sol b/contracts/vendor/erc4337-entrypoint/core/EntryPoint.sol
index 778115b1..44501524 100644
--- a/contracts/vendor/erc4337-entrypoint/core/EntryPoint.sol
+++ b/contracts/vendor/erc4337-entrypoint/core/EntryPoint.sol
@@ -15,10 +15,8 @@ import "./Helpers.sol";
import "./NonceManager.sol";
import "./UserOperationLib.sol";

-// import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
-// import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
-import "../../../utils/introspection/ERC165.sol"; // OZ edit
-import "../../../utils/ReentrancyGuard.sol"; // OZ edit
+import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
+import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/*
* Account-Abstraction (EIP-4337) singleton EntryPoint implementation.
2 changes: 1 addition & 1 deletion slither.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"detectors_to_run": "arbitrary-send-erc20,array-by-reference,incorrect-shift,name-reused,rtlo,suicidal,uninitialized-state,uninitialized-storage,arbitrary-send-erc20-permit,controlled-array-length,controlled-delegatecall,delegatecall-loop,msg-value-loop,reentrancy-eth,unchecked-transfer,weak-prng,domain-separator-collision,erc20-interface,erc721-interface,locked-ether,mapping-deletion,shadowing-abstract,tautology,write-after-write,boolean-cst,reentrancy-no-eth,reused-constructor,tx-origin,unchecked-lowlevel,unchecked-send,variable-scope,void-cst,events-access,events-maths,incorrect-unary,boolean-equal,cyclomatic-complexity,deprecated-standards,erc20-indexed,function-init-state,pragma,unused-state,reentrancy-unlimited-gas,constable-states,immutable-states,var-read-using-this",
"filter_paths": "contracts/mocks,contracts-exposed",
"filter_paths": "contracts/mocks,contracts/vendor,contracts-exposed",
"compile_force_framework": "hardhat"
}

0 comments on commit 518fd94

Please sign in to comment.