@openzeppelin/upgrades-core 1.37.1 → 1.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/infer-proxy-admin.d.ts +9 -0
- package/dist/infer-proxy-admin.d.ts.map +1 -0
- package/dist/infer-proxy-admin.js +16 -0
- package/dist/infer-proxy-admin.js.map +1 -0
- package/dist/infer-proxy-admin.test.d.ts +2 -0
- package/dist/infer-proxy-admin.test.d.ts.map +1 -0
- package/dist/infer-proxy-admin.test.js +42 -0
- package/dist/infer-proxy-admin.test.js.map +1 -0
- package/dist/utils/address.js +1 -1
- package/dist/utils/address.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/infer-proxy-admin.test.ts +49 -0
- package/src/infer-proxy-admin.ts +14 -0
- package/src/utils/address.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.38.0 (2024-09-23)
|
|
4
|
+
|
|
5
|
+
- Supports checking to ensure `initialOwner` is not a ProxyAdmin contract when deploying a transparent proxy from Hardhat. ([#1083](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1083))
|
|
6
|
+
|
|
3
7
|
## 1.37.1 (2024-09-09)
|
|
4
8
|
|
|
5
9
|
- Fix Hardhat compile error when using solc version `0.8.27`. ([#1075](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1075))
|
package/dist/index.d.ts
CHANGED
|
@@ -24,4 +24,5 @@ export { ValidateUpgradeSafetyOptions, validateUpgradeSafety, ProjectReport, Ref
|
|
|
24
24
|
export { getUpgradeInterfaceVersion } from './upgrade-interface-version';
|
|
25
25
|
export { makeNamespacedInput } from './utils/make-namespaced';
|
|
26
26
|
export { isNamespaceSupported } from './storage/namespace';
|
|
27
|
+
export { inferProxyAdmin } from './infer-proxy-admin';
|
|
27
28
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC7F,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,aAAa,EACb,qBAAqB,EACrB,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,eAAe,EACf,QAAQ,EACR,eAAe,EACf,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAEvE,cAAc,kCAAkC,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,kCAAkC,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AACvG,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO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AAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,kCAAkC,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AACvG,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,8BAA8B,EAC9B,iCAAiC,EACjC,iCAAiC,EACjC,0BAA0B,EAC1B,2BAA2B,EAC3B,qBAAqB,EACrB,+BAA+B,EAC/B,+BAA+B,EAC/B,gCAAgC,EAChC,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,4BAA4B,EAAE,qBAAqB,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,OAAO,CAAC;AAEtH,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.isNamespaceSupported = exports.makeNamespacedInput = exports.getUpgradeInterfaceVersion = exports.ReferenceContractNotFound = exports.ProjectReport = exports.validateUpgradeSafety = exports.assertNotProxy = exports.InitialOwnerUnsupportedKindError = exports.PrepareUpgradeRequiresKindError = exports.ValidateUpdateRequiresKindError = exports.NoContractImportError = exports.ForceImportUnsupportedError = exports.DeployBeaconProxyKindError = exports.DeployBeaconProxyImplUnknownError = exports.DeployBeaconProxyUnsupportedError = exports.PrepareUpgradeUnsupportedError = exports.LoadProxyUnsupportedError = exports.BeaconProxyUnsupportedError = exports.addProxyToManifest = exports.isBeacon = exports.getImplementationAddressFromProxy = exports.getImplementationAddressFromBeacon = exports.isTransparentProxy = exports.isBeaconProxy = exports.isTransparentOrUUPSProxy = exports.UpgradeableContract = exports.detectProxyKind = exports.processProxyKind = exports.setProxyKind = exports.logWarning = exports.getStorageLayoutForAddress = exports.DeploymentNotFound = exports.migrateManifest = exports.Manifest = exports.isEmptySlot = exports.toFallbackEip1967Hash = exports.toEip1967Hash = exports.getImplementationAddress = exports.getBeaconAddress = exports.getAdminAddress = exports.EIP1967ImplementationNotFound = exports.EIP1967BeaconNotFound = exports.fetchOrDeployGetDeployment = exports.fetchOrDeployAdmin = exports.fetchOrDeploy = void 0;
|
|
17
|
+
exports.inferProxyAdmin = exports.isNamespaceSupported = exports.makeNamespacedInput = exports.getUpgradeInterfaceVersion = exports.ReferenceContractNotFound = exports.ProjectReport = exports.validateUpgradeSafety = exports.assertNotProxy = exports.InitialOwnerUnsupportedKindError = exports.PrepareUpgradeRequiresKindError = exports.ValidateUpdateRequiresKindError = exports.NoContractImportError = exports.ForceImportUnsupportedError = exports.DeployBeaconProxyKindError = exports.DeployBeaconProxyImplUnknownError = exports.DeployBeaconProxyUnsupportedError = exports.PrepareUpgradeUnsupportedError = exports.LoadProxyUnsupportedError = exports.BeaconProxyUnsupportedError = exports.addProxyToManifest = exports.isBeacon = exports.getImplementationAddressFromProxy = exports.getImplementationAddressFromBeacon = exports.isTransparentProxy = exports.isBeaconProxy = exports.isTransparentOrUUPSProxy = exports.UpgradeableContract = exports.detectProxyKind = exports.processProxyKind = exports.setProxyKind = exports.logWarning = exports.getStorageLayoutForAddress = exports.DeploymentNotFound = exports.migrateManifest = exports.Manifest = exports.isEmptySlot = exports.toFallbackEip1967Hash = exports.toEip1967Hash = exports.getImplementationAddress = exports.getBeaconAddress = exports.getAdminAddress = exports.EIP1967ImplementationNotFound = exports.EIP1967BeaconNotFound = exports.fetchOrDeployGetDeployment = exports.fetchOrDeployAdmin = exports.fetchOrDeploy = void 0;
|
|
18
18
|
__exportStar(require("./validate"), exports);
|
|
19
19
|
var impl_store_1 = require("./impl-store");
|
|
20
20
|
Object.defineProperty(exports, "fetchOrDeploy", { enumerable: true, get: function () { return impl_store_1.fetchOrDeploy; } });
|
|
@@ -86,4 +86,6 @@ var make_namespaced_1 = require("./utils/make-namespaced");
|
|
|
86
86
|
Object.defineProperty(exports, "makeNamespacedInput", { enumerable: true, get: function () { return make_namespaced_1.makeNamespacedInput; } });
|
|
87
87
|
var namespace_1 = require("./storage/namespace");
|
|
88
88
|
Object.defineProperty(exports, "isNamespaceSupported", { enumerable: true, get: function () { return namespace_1.isNamespaceSupported; } });
|
|
89
|
+
var infer_proxy_admin_1 = require("./infer-proxy-admin");
|
|
90
|
+
Object.defineProperty(exports, "inferProxyAdmin", { enumerable: true, get: function () { return infer_proxy_admin_1.inferProxyAdmin; } });
|
|
89
91
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,2CAA6F;AAApF,2GAAA,aAAa,OAAA;AAAE,gHAAA,kBAAkB,OAAA;AAAE,wHAAA,0BAA0B,OAAA;AACtE,4CAA0B;AAC1B,4CAA0B;AAC1B,uCASoB;AARlB,iHAAA,qBAAqB,OAAA;AACrB,yHAAA,6BAA6B,OAAA;AAC7B,2GAAA,eAAe,OAAA;AACf,4GAAA,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,OAAA;AACjB,iEAA6D;AAApD,2HAAA,kBAAkB,OAAA;AAE3B,6CAauB;AAZrB,0HAAA,2BAA2B,OAAA;AAC3B,wHAAA,yBAAyB,OAAA;AACzB,6HAAA,8BAA8B,OAAA;AAC9B,gIAAA,iCAAiC,OAAA;AACjC,gIAAA,iCAAiC,OAAA;AACjC,yHAAA,0BAA0B,OAAA;AAC1B,0HAAA,2BAA2B,OAAA;AAC3B,oHAAA,qBAAqB,OAAA;AACrB,8HAAA,+BAA+B,OAAA;AAC/B,8HAAA,+BAA+B,OAAA;AAC/B,+HAAA,gCAAgC,OAAA;AAChC,6GAAA,cAAc,OAAA;AAGhB,6BAAsH;AAA/E,4GAAA,qBAAqB,OAAA;AAAE,oGAAA,aAAa,OAAA;AAAE,gHAAA,yBAAyB,OAAA;AAEtG,yEAAyE;AAAhE,uIAAA,0BAA0B,OAAA;AACnC,2DAA8D;AAArD,sHAAA,mBAAmB,OAAA;AAC5B,iDAA2D;AAAlD,iHAAA,oBAAoB,OAAA;AAC7B,yDAAsD;AAA7C,oHAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EthereumProvider } from './provider';
|
|
2
|
+
/**
|
|
3
|
+
* Infers whether the address might be a ProxyAdmin contract, by checking if it has an owner() function that returns an address.
|
|
4
|
+
* @param provider Ethereum provider
|
|
5
|
+
* @param possibleContractAddress The address to check
|
|
6
|
+
* @returns true if the address might be a ProxyAdmin contract, false otherwise
|
|
7
|
+
*/
|
|
8
|
+
export declare function inferProxyAdmin(provider: EthereumProvider, possibleContractAddress: string): Promise<boolean>;
|
|
9
|
+
//# sourceMappingURL=infer-proxy-admin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer-proxy-admin.d.ts","sourceRoot":"","sources":["../src/infer-proxy-admin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGnH"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inferProxyAdmin = inferProxyAdmin;
|
|
4
|
+
const call_optional_signature_1 = require("./call-optional-signature");
|
|
5
|
+
const address_1 = require("./utils/address");
|
|
6
|
+
/**
|
|
7
|
+
* Infers whether the address might be a ProxyAdmin contract, by checking if it has an owner() function that returns an address.
|
|
8
|
+
* @param provider Ethereum provider
|
|
9
|
+
* @param possibleContractAddress The address to check
|
|
10
|
+
* @returns true if the address might be a ProxyAdmin contract, false otherwise
|
|
11
|
+
*/
|
|
12
|
+
async function inferProxyAdmin(provider, possibleContractAddress) {
|
|
13
|
+
const owner = await (0, call_optional_signature_1.callOptionalSignature)(provider, possibleContractAddress, 'owner()');
|
|
14
|
+
return owner !== undefined && (0, address_1.parseAddress)(owner) !== undefined;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=infer-proxy-admin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer-proxy-admin.js","sourceRoot":"","sources":["../src/infer-proxy-admin.ts"],"names":[],"mappings":";;AAUA,0CAGC;AAbD,uEAAkE;AAElE,6CAA+C;AAE/C;;;;;GAKG;AACI,KAAK,UAAU,eAAe,CAAC,QAA0B,EAAE,uBAA+B;IAC/F,MAAM,KAAK,GAAG,MAAM,IAAA,+CAAqB,EAAC,QAAQ,EAAE,uBAAuB,EAAE,SAAS,CAAC,CAAC;IACxF,OAAO,KAAK,KAAK,SAAS,IAAI,IAAA,sBAAY,EAAC,KAAK,CAAC,KAAK,SAAS,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer-proxy-admin.test.d.ts","sourceRoot":"","sources":["../src/infer-proxy-admin.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ava_1 = __importDefault(require("ava"));
|
|
7
|
+
const infer_proxy_admin_1 = require("./infer-proxy-admin");
|
|
8
|
+
const addr = '0x123';
|
|
9
|
+
function makeProviderReturning(result) {
|
|
10
|
+
return { send: (_method, _params) => Promise.resolve(result) };
|
|
11
|
+
}
|
|
12
|
+
function makeProviderError(msg) {
|
|
13
|
+
return {
|
|
14
|
+
send: (_method, _params) => {
|
|
15
|
+
throw new Error(msg);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
(0, ava_1.default)('inferProxyAdmin returns true when owner looks like an address', async (t) => {
|
|
20
|
+
// abi encoding of address 0x1000000000000000000000000000000000000123
|
|
21
|
+
const provider = makeProviderReturning('0x0000000000000000000000001000000000000000000000000000000000000123');
|
|
22
|
+
t.true(await (0, infer_proxy_admin_1.inferProxyAdmin)(provider, addr));
|
|
23
|
+
});
|
|
24
|
+
(0, ava_1.default)('inferProxyAdmin returns false when returned value is 32 bytes but clearly not an address', async (t) => {
|
|
25
|
+
// dirty upper bits beyond 20 bytes (the 'abc' in the below)
|
|
26
|
+
const provider = makeProviderReturning('0x000000000000000000000abc1000000000000000000000000000000000000123');
|
|
27
|
+
t.false(await (0, infer_proxy_admin_1.inferProxyAdmin)(provider, addr));
|
|
28
|
+
});
|
|
29
|
+
(0, ava_1.default)('inferProxyAdmin returns false when returned value is a string', async (t) => {
|
|
30
|
+
// abi encoding of string 'foo'
|
|
31
|
+
const provider = makeProviderReturning('0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003666f6f0000000000000000000000000000000000000000000000000000000000');
|
|
32
|
+
t.false(await (0, infer_proxy_admin_1.inferProxyAdmin)(provider, addr));
|
|
33
|
+
});
|
|
34
|
+
(0, ava_1.default)('inferProxyAdmin throws unrelated error', async (t) => {
|
|
35
|
+
const provider = makeProviderError('unrelated error');
|
|
36
|
+
await t.throwsAsync(() => (0, infer_proxy_admin_1.inferProxyAdmin)(provider, addr), { message: 'unrelated error' });
|
|
37
|
+
});
|
|
38
|
+
(0, ava_1.default)('inferProxyAdmin returns false for invalid selector', async (t) => {
|
|
39
|
+
const provider = makeProviderError(`Transaction reverted: function selector was not recognized and there's no fallback function`);
|
|
40
|
+
t.false(await (0, infer_proxy_admin_1.inferProxyAdmin)(provider, addr));
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=infer-proxy-admin.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer-proxy-admin.test.js","sourceRoot":"","sources":["../src/infer-proxy-admin.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAuB;AAEvB,2DAAsD;AAEtD,MAAM,IAAI,GAAG,OAAO,CAAC;AAErB,SAAS,qBAAqB,CAAC,MAAe;IAC5C,OAAO,EAAE,IAAI,EAAE,CAAC,OAAe,EAAE,OAAkB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAsB,CAAC;AACxG,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAW;IACpC,OAAO;QACL,IAAI,EAAE,CAAC,OAAe,EAAE,OAAkB,EAAE,EAAE;YAC5C,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;KACkB,CAAC;AACxB,CAAC;AAED,IAAA,aAAI,EAAC,+DAA+D,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE;IAC9E,qEAAqE;IACrE,MAAM,QAAQ,GAAG,qBAAqB,CAAC,oEAAoE,CAAC,CAAC;IAC7G,CAAC,CAAC,IAAI,CAAC,MAAM,IAAA,mCAAe,EAAC,QAAQ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
|
function parseAddress(addressString) {
|
|
12
12
|
const buf = Buffer.from(addressString.replace(/^0x/, ''), 'hex');
|
|
13
|
-
if (!buf.slice(0, 12).equals(Buffer.alloc(12, 0))) {
|
|
13
|
+
if (!buf.slice(0, 12).equals(Buffer.alloc(12, 0)) || buf.length !== 32) {
|
|
14
14
|
return undefined;
|
|
15
15
|
}
|
|
16
16
|
const address = '0x' + buf.toString('hex', 12, 32); // grab the last 20 bytes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/utils/address.ts"],"names":[],"mappings":";;AAQA,oCAOC;AAfD,qDAAoD;AAEpD;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,aAAqB;IAChD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IACjE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/utils/address.ts"],"names":[],"mappings":";;AAQA,oCAOC;AAfD,qDAAoD;AAEpD;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,aAAqB;IAChD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IACjE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACvE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,yBAAyB;IAC7E,OAAO,IAAA,mCAAiB,EAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -62,3 +62,4 @@ export { ValidateUpgradeSafetyOptions, validateUpgradeSafety, ProjectReport, Ref
|
|
|
62
62
|
export { getUpgradeInterfaceVersion } from './upgrade-interface-version';
|
|
63
63
|
export { makeNamespacedInput } from './utils/make-namespaced';
|
|
64
64
|
export { isNamespaceSupported } from './storage/namespace';
|
|
65
|
+
export { inferProxyAdmin } from './infer-proxy-admin';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { EthereumProvider } from './provider';
|
|
3
|
+
import { inferProxyAdmin } from './infer-proxy-admin';
|
|
4
|
+
|
|
5
|
+
const addr = '0x123';
|
|
6
|
+
|
|
7
|
+
function makeProviderReturning(result: unknown): EthereumProvider {
|
|
8
|
+
return { send: (_method: string, _params: unknown[]) => Promise.resolve(result) } as EthereumProvider;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function makeProviderError(msg: string): EthereumProvider {
|
|
12
|
+
return {
|
|
13
|
+
send: (_method: string, _params: unknown[]) => {
|
|
14
|
+
throw new Error(msg);
|
|
15
|
+
},
|
|
16
|
+
} as EthereumProvider;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
test('inferProxyAdmin returns true when owner looks like an address', async t => {
|
|
20
|
+
// abi encoding of address 0x1000000000000000000000000000000000000123
|
|
21
|
+
const provider = makeProviderReturning('0x0000000000000000000000001000000000000000000000000000000000000123');
|
|
22
|
+
t.true(await inferProxyAdmin(provider, addr));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('inferProxyAdmin returns false when returned value is 32 bytes but clearly not an address', async t => {
|
|
26
|
+
// dirty upper bits beyond 20 bytes (the 'abc' in the below)
|
|
27
|
+
const provider = makeProviderReturning('0x000000000000000000000abc1000000000000000000000000000000000000123');
|
|
28
|
+
t.false(await inferProxyAdmin(provider, addr));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('inferProxyAdmin returns false when returned value is a string', async t => {
|
|
32
|
+
// abi encoding of string 'foo'
|
|
33
|
+
const provider = makeProviderReturning(
|
|
34
|
+
'0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003666f6f0000000000000000000000000000000000000000000000000000000000',
|
|
35
|
+
);
|
|
36
|
+
t.false(await inferProxyAdmin(provider, addr));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('inferProxyAdmin throws unrelated error', async t => {
|
|
40
|
+
const provider = makeProviderError('unrelated error');
|
|
41
|
+
await t.throwsAsync(() => inferProxyAdmin(provider, addr), { message: 'unrelated error' });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('inferProxyAdmin returns false for invalid selector', async t => {
|
|
45
|
+
const provider = makeProviderError(
|
|
46
|
+
`Transaction reverted: function selector was not recognized and there's no fallback function`,
|
|
47
|
+
);
|
|
48
|
+
t.false(await inferProxyAdmin(provider, addr));
|
|
49
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { callOptionalSignature } from './call-optional-signature';
|
|
2
|
+
import { EthereumProvider } from './provider';
|
|
3
|
+
import { parseAddress } from './utils/address';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Infers whether the address might be a ProxyAdmin contract, by checking if it has an owner() function that returns an address.
|
|
7
|
+
* @param provider Ethereum provider
|
|
8
|
+
* @param possibleContractAddress The address to check
|
|
9
|
+
* @returns true if the address might be a ProxyAdmin contract, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
export async function inferProxyAdmin(provider: EthereumProvider, possibleContractAddress: string): Promise<boolean> {
|
|
12
|
+
const owner = await callOptionalSignature(provider, possibleContractAddress, 'owner()');
|
|
13
|
+
return owner !== undefined && parseAddress(owner) !== undefined;
|
|
14
|
+
}
|
package/src/utils/address.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { toChecksumAddress } from 'ethereumjs-util';
|
|
|
8
8
|
*/
|
|
9
9
|
export function parseAddress(addressString: string): string | undefined {
|
|
10
10
|
const buf = Buffer.from(addressString.replace(/^0x/, ''), 'hex');
|
|
11
|
-
if (!buf.slice(0, 12).equals(Buffer.alloc(12, 0))) {
|
|
11
|
+
if (!buf.slice(0, 12).equals(Buffer.alloc(12, 0)) || buf.length !== 32) {
|
|
12
12
|
return undefined;
|
|
13
13
|
}
|
|
14
14
|
const address = '0x' + buf.toString('hex', 12, 32); // grab the last 20 bytes
|