@openzeppelin/upgrades-core 1.45.0-alpha.1 → 1.46.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/artifacts/@openzeppelin/contracts-v5/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.json +2 -2
- package/artifacts/@openzeppelin/contracts-v5/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.json +2 -2
- package/artifacts/@openzeppelin/contracts-v5/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json +2 -2
- package/artifacts/build-info-v5.json +22 -22
- package/dist/cli/validate/build-info-file.js +4 -1
- package/dist/cli/validate/build-info-file.js.map +1 -1
- package/dist/cli/validate/build-info-file.test.js +115 -1
- package/dist/cli/validate/build-info-file.test.js.map +1 -1
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +1 -0
- package/dist/provider.js.map +1 -1
- package/dist/storage/extract.d.ts.map +1 -1
- package/dist/storage/extract.js +21 -7
- package/dist/storage/extract.js.map +1 -1
- package/dist/storage/namespace.d.ts.map +1 -1
- package/dist/storage/namespace.js +18 -11
- package/dist/storage/namespace.js.map +1 -1
- package/dist/storage-erc7201-builtin.test.d.ts +2 -0
- package/dist/storage-erc7201-builtin.test.d.ts.map +1 -0
- package/dist/storage-erc7201-builtin.test.js +105 -0
- package/dist/storage-erc7201-builtin.test.js.map +1 -0
- package/dist/utils/erc7201-builtin.d.ts +24 -0
- package/dist/utils/erc7201-builtin.d.ts.map +1 -0
- package/dist/utils/erc7201-builtin.js +83 -0
- package/dist/utils/erc7201-builtin.js.map +1 -0
- package/dist/utils/erc7201.d.ts.map +1 -1
- package/dist/utils/erc7201.js +5 -3
- package/dist/utils/erc7201.js.map +1 -1
- package/dist/utils/erc7201.test.js +10 -0
- package/dist/utils/erc7201.test.js.map +1 -1
- package/dist/utils/integer-literals.d.ts +19 -6
- package/dist/utils/integer-literals.d.ts.map +1 -1
- package/dist/utils/integer-literals.js +28 -10
- package/dist/utils/integer-literals.js.map +1 -1
- package/dist/utils/integer-literals.test.js +12 -0
- package/dist/utils/integer-literals.test.js.map +1 -1
- package/package.json +3 -3
- package/src/cli/validate/build-info-file.test.ts +156 -1
- package/src/cli/validate/build-info-file.ts +6 -1
- package/src/provider.ts +1 -0
- package/src/storage/extract.ts +28 -12
- package/src/storage/namespace.ts +21 -11
- package/src/storage-erc7201-builtin.test.ts +127 -0
- package/src/utils/erc7201-builtin.ts +91 -0
- package/src/utils/erc7201.test.ts +12 -0
- package/src/utils/erc7201.ts +6 -4
- package/src/utils/integer-literals.test.ts +15 -1
- package/src/utils/integer-literals.ts +29 -10
|
@@ -0,0 +1,105 @@
|
|
|
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 utils_1 = require("solidity-ast/utils");
|
|
8
|
+
const hardhat_1 = require("hardhat");
|
|
9
|
+
const storage_1 = require("./storage");
|
|
10
|
+
const extract_1 = require("./storage/extract");
|
|
11
|
+
const test = ava_1.default;
|
|
12
|
+
const SOURCE = 'contracts/test/Erc7201Builtin.sol';
|
|
13
|
+
test.before(async (t) => {
|
|
14
|
+
const buildInfo = await hardhat_1.artifacts.getBuildInfo(`${SOURCE}:Erc7201Builtin`);
|
|
15
|
+
if (buildInfo === undefined) {
|
|
16
|
+
throw new Error('Build info not found');
|
|
17
|
+
}
|
|
18
|
+
const solcOutput = buildInfo.output;
|
|
19
|
+
const contracts = {};
|
|
20
|
+
const storageLayouts = {};
|
|
21
|
+
for (const def of (0, utils_1.findAll)('ContractDefinition', solcOutput.sources[SOURCE].ast)) {
|
|
22
|
+
contracts[def.name] = def;
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
24
|
+
storageLayouts[def.name] = solcOutput.contracts[SOURCE][def.name].storageLayout;
|
|
25
|
+
}
|
|
26
|
+
const deref = (0, utils_1.astDereferencer)(solcOutput);
|
|
27
|
+
t.context.extractStorageLayout = name => (0, extract_1.extractStorageLayout)(contracts[name], dummyDecodeSrc, deref, storageLayouts[name]);
|
|
28
|
+
t.context.extractStorageLayoutFallback = name => (0, extract_1.extractStorageLayout)(contracts[name], dummyDecodeSrc, deref, undefined);
|
|
29
|
+
});
|
|
30
|
+
const dummyDecodeSrc = () => 'file.sol:1';
|
|
31
|
+
test('erc7201 builtin base slot - extract', t => {
|
|
32
|
+
const layout = t.context.extractStorageLayout('Erc7201Builtin');
|
|
33
|
+
t.is(layout.baseSlot, '0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500');
|
|
34
|
+
t.is(layout.storage.length, 1);
|
|
35
|
+
t.is(layout.storage[0].label, 'a');
|
|
36
|
+
});
|
|
37
|
+
test('erc7201 builtin base slot - append - ok', t => {
|
|
38
|
+
const v1 = t.context.extractStorageLayout('Erc7201Builtin');
|
|
39
|
+
const v2 = t.context.extractStorageLayout('Erc7201Builtin_Append_Ok');
|
|
40
|
+
t.deepEqual((0, storage_1.getStorageUpgradeErrors)(v1, v2), []);
|
|
41
|
+
});
|
|
42
|
+
test('erc7201 builtin base slot - append - fallback - ok', t => {
|
|
43
|
+
const v1 = t.context.extractStorageLayoutFallback('Erc7201Builtin');
|
|
44
|
+
const v2 = t.context.extractStorageLayoutFallback('Erc7201Builtin_Append_Ok');
|
|
45
|
+
t.deepEqual((0, storage_1.getStorageUpgradeErrors)(v1, v2), []);
|
|
46
|
+
});
|
|
47
|
+
test('erc7201 builtin base slot - changed id - bad', t => {
|
|
48
|
+
const v1 = t.context.extractStorageLayout('Erc7201Builtin');
|
|
49
|
+
const v2 = t.context.extractStorageLayout('Erc7201Builtin_Changed_Id_Bad');
|
|
50
|
+
const comparison = (0, storage_1.getStorageUpgradeErrors)(v1, v2);
|
|
51
|
+
t.true(comparison.length > 0);
|
|
52
|
+
t.is(comparison[0].kind, 'layoutchange');
|
|
53
|
+
});
|
|
54
|
+
test('erc7201 builtin base slot - changed id - fallback - bad', t => {
|
|
55
|
+
const v1 = t.context.extractStorageLayoutFallback('Erc7201Builtin');
|
|
56
|
+
const v2 = t.context.extractStorageLayoutFallback('Erc7201Builtin_Changed_Id_Bad');
|
|
57
|
+
// Base slot differs between the two erc7201 ids, so the fallback base-slot check must fail.
|
|
58
|
+
t.throws(() => (0, storage_1.getStorageUpgradeErrors)(v1, v2), {
|
|
59
|
+
message: /Base slot for custom storage layout changed/,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
test('erc7201 builtin and literal-equivalent base slots compare equal', t => {
|
|
63
|
+
const builtin = t.context.extractStorageLayout('Erc7201Builtin');
|
|
64
|
+
const literal = t.context.extractStorageLayout('Erc7201Builtin_Literal_Equivalent');
|
|
65
|
+
// Both resolve to the same base slot; the fallback (base-slot) check must treat them as unchanged.
|
|
66
|
+
const builtinFallback = t.context.extractStorageLayoutFallback('Erc7201Builtin');
|
|
67
|
+
const literalFallback = t.context.extractStorageLayoutFallback('Erc7201Builtin_Literal_Equivalent');
|
|
68
|
+
t.deepEqual((0, storage_1.getStorageUpgradeErrors)(builtin, literal), []);
|
|
69
|
+
t.deepEqual((0, storage_1.getStorageUpgradeErrors)(builtinFallback, literalFallback), []);
|
|
70
|
+
});
|
|
71
|
+
test('erc7201 builtin base slot clashes with namespace - error', t => {
|
|
72
|
+
t.throws(() => t.context.extractStorageLayout('Erc7201Builtin_Clash'), {
|
|
73
|
+
message: /Custom layout for contract Erc7201Builtin_Clash clashes with the storage location for namespace erc7201:example\.main/,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
test('erc7201 builtin base slot different from namespace - no error and no warning', t => {
|
|
77
|
+
const warnings = captureWarnings(() => {
|
|
78
|
+
const layout = t.context.extractStorageLayout('Erc7201Builtin_NoClash_NoWarning');
|
|
79
|
+
t.truthy(layout.baseSlot);
|
|
80
|
+
});
|
|
81
|
+
t.deepEqual(warnings, []);
|
|
82
|
+
});
|
|
83
|
+
test('erc7201 builtin accepts a unicode string literal argument', t => {
|
|
84
|
+
const layout = t.context.extractStorageLayout('Erc7201Builtin_Unicode');
|
|
85
|
+
t.is(layout.baseSlot, '0x2d3e72b7d91644a80150e2643e65016def7067dc9568719707e7eca1a5dab800');
|
|
86
|
+
});
|
|
87
|
+
test('literal base slot with namespace - warning not suppressed', t => {
|
|
88
|
+
const warnings = captureWarnings(() => t.context.extractStorageLayout('Erc7201Builtin_LiteralBase_Warns'));
|
|
89
|
+
t.true(warnings.some(w => w.includes('custom storage layout')));
|
|
90
|
+
});
|
|
91
|
+
function captureWarnings(fn) {
|
|
92
|
+
const warnings = [];
|
|
93
|
+
const original = console.error;
|
|
94
|
+
console.error = (...args) => {
|
|
95
|
+
warnings.push(args.map(String).join(' '));
|
|
96
|
+
};
|
|
97
|
+
try {
|
|
98
|
+
fn();
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
console.error = original;
|
|
102
|
+
}
|
|
103
|
+
return warnings;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=storage-erc7201-builtin.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-erc7201-builtin.test.js","sourceRoot":"","sources":["../src/storage-erc7201-builtin.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAoC;AAEpC,8CAA8D;AAC9D,qCAAoC;AAGpC,uCAAoD;AAEpD,+CAAyD;AAOzD,MAAM,IAAI,GAAG,aAAwB,CAAC;AAEtC,MAAM,MAAM,GAAG,mCAAmC,CAAC;AAEnD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;IACpB,MAAM,SAAS,GAAG,MAAM,mBAAS,CAAC,YAAY,CAAC,GAAG,MAAM,iBAAiB,CAAC,CAAC;IAC3E,IAAI,SAAS,KAAK,SAAS,E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K,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;QACrC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC;IACF,IAAI,CAAC;QACH,EAAE,EAAE,CAAC;IACP,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC;IAC3B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Expression } from 'solidity-ast';
|
|
2
|
+
/**
|
|
3
|
+
* Recognizes the Solidity 0.8.35+ `erc7201(string)` comptime builtin, which evaluates the ERC-7201
|
|
4
|
+
* storage location for a namespace id and can be used in a compile-time context such as a `layout at`
|
|
5
|
+
* specifier (e.g. `contract C layout at erc7201("example.main")`).
|
|
6
|
+
*
|
|
7
|
+
* The builtin compiles to an ordinary `FunctionCall` node, so it is matched by its shape rather than
|
|
8
|
+
* by a dedicated AST node type.
|
|
9
|
+
*
|
|
10
|
+
* @param node The expression to check.
|
|
11
|
+
* @returns The namespace id passed to the builtin (without the `erc7201:` prefix), or undefined if the
|
|
12
|
+
* expression is not a call to the `erc7201` builtin with a single string literal argument.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getErc7201BuiltinNamespaceId(node: Expression): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Resolves an expression to its base slot as a normalized uint256 hex string, for either a numeric
|
|
17
|
+
* literal or an `erc7201(...)` builtin call.
|
|
18
|
+
*
|
|
19
|
+
* @param node The expression to resolve.
|
|
20
|
+
* @returns The normalized base slot hex string, or undefined if the expression is neither a numeric
|
|
21
|
+
* literal nor a resolvable `erc7201(...)` builtin call.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveBaseSlot(node: Expression): string | undefined;
|
|
24
|
+
//# sourceMappingURL=erc7201-builtin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"erc7201-builtin.d.ts","sourceRoot":"","sources":["../../src/utils/erc7201-builtin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,cAAc,CAAC;AAKnD;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAmCjF;AAUD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAWpE"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getErc7201BuiltinNamespaceId = getErc7201BuiltinNamespaceId;
|
|
4
|
+
exports.resolveBaseSlot = resolveBaseSlot;
|
|
5
|
+
const erc7201_1 = require("./erc7201");
|
|
6
|
+
const integer_literals_1 = require("./integer-literals");
|
|
7
|
+
const error_1 = require("../error");
|
|
8
|
+
/**
|
|
9
|
+
* Recognizes the Solidity 0.8.35+ `erc7201(string)` comptime builtin, which evaluates the ERC-7201
|
|
10
|
+
* storage location for a namespace id and can be used in a compile-time context such as a `layout at`
|
|
11
|
+
* specifier (e.g. `contract C layout at erc7201("example.main")`).
|
|
12
|
+
*
|
|
13
|
+
* The builtin compiles to an ordinary `FunctionCall` node, so it is matched by its shape rather than
|
|
14
|
+
* by a dedicated AST node type.
|
|
15
|
+
*
|
|
16
|
+
* @param node The expression to check.
|
|
17
|
+
* @returns The namespace id passed to the builtin (without the `erc7201:` prefix), or undefined if the
|
|
18
|
+
* expression is not a call to the `erc7201` builtin with a single string literal argument.
|
|
19
|
+
*/
|
|
20
|
+
function getErc7201BuiltinNamespaceId(node) {
|
|
21
|
+
// Check that this is a function call to an identifier named `erc7201`. Return undefined for
|
|
22
|
+
// anything else so the caller can fall through to other base-slot forms.
|
|
23
|
+
if (node.nodeType !== 'FunctionCall' || node.kind !== 'functionCall') {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const callee = node.expression;
|
|
27
|
+
if (callee.nodeType !== 'Identifier' || callee.name !== 'erc7201') {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
// Beyond this point, the call is to `erc7201(...)`. Check its expected shape — one string-literal
|
|
31
|
+
// argument with no user-defined declaration shadowing the builtin — and throw if anything is off.
|
|
32
|
+
// Valid Solidity 0.8.35+ cannot produce these mismatches in a call to the builtin:
|
|
33
|
+
// - User-defined `erc7201` (`referencedDeclaration >= 0`): solc resolves the call to the builtin
|
|
34
|
+
// when both are in scope, so this shape doesn't reach a successful compile.
|
|
35
|
+
// - Wrong number of arguments: enforced by the builtin's signature.
|
|
36
|
+
// - Non-`Literal` argument or non-string literal `kind`: the builtin's signature requires a
|
|
37
|
+
// comptime-constant string literal. `hex"..."` is type `bytes` and wouldn't typecheck.
|
|
38
|
+
// We throw instead of returning undefined so a future solc emitting one of these surfaces loudly.
|
|
39
|
+
if (typeof callee.referencedDeclaration === 'number' && callee.referencedDeclaration >= 0) {
|
|
40
|
+
throw unexpectedErc7201BuiltinAst('callee resolves to a user-defined declaration');
|
|
41
|
+
}
|
|
42
|
+
if (node.arguments.length !== 1) {
|
|
43
|
+
throw unexpectedErc7201BuiltinAst(`expected 1 argument, got ${node.arguments.length}`);
|
|
44
|
+
}
|
|
45
|
+
const arg = node.arguments[0];
|
|
46
|
+
if (arg.nodeType !== 'Literal') {
|
|
47
|
+
throw unexpectedErc7201BuiltinAst(`argument is ${arg.nodeType}, expected Literal`);
|
|
48
|
+
}
|
|
49
|
+
if (arg.kind !== 'string' && arg.kind !== 'unicodeString') {
|
|
50
|
+
throw unexpectedErc7201BuiltinAst(`argument literal kind is ${arg.kind}, expected string or unicodeString`);
|
|
51
|
+
}
|
|
52
|
+
return getStringLiteralValue(arg);
|
|
53
|
+
}
|
|
54
|
+
function unexpectedErc7201BuiltinAst(detail) {
|
|
55
|
+
return new error_1.UpgradesError(`Unexpected AST for \`erc7201(...)\` builtin call: ${detail}`, () => 'Please report this at https://zpl.in/upgrades/report and include the `erc7201(...)` expression from your contract.');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Resolves an expression to its base slot as a normalized uint256 hex string, for either a numeric
|
|
59
|
+
* literal or an `erc7201(...)` builtin call.
|
|
60
|
+
*
|
|
61
|
+
* @param node The expression to resolve.
|
|
62
|
+
* @returns The normalized base slot hex string, or undefined if the expression is neither a numeric
|
|
63
|
+
* literal nor a resolvable `erc7201(...)` builtin call.
|
|
64
|
+
*/
|
|
65
|
+
function resolveBaseSlot(node) {
|
|
66
|
+
if (node.nodeType === 'Literal') {
|
|
67
|
+
return (0, integer_literals_1.normalizeUint256Literal)(node.value);
|
|
68
|
+
}
|
|
69
|
+
const id = getErc7201BuiltinNamespaceId(node);
|
|
70
|
+
if (id !== undefined) {
|
|
71
|
+
return (0, erc7201_1.calculateERC7201StorageLocation)(id);
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
function getStringLiteralValue(literal) {
|
|
76
|
+
// solc populates `value` for `kind: 'string'`/`'unicodeString'` literals; throw defensively if
|
|
77
|
+
// a future solc ever produces a null/missing `value` for such a literal.
|
|
78
|
+
if (literal.value === undefined || literal.value === null) {
|
|
79
|
+
throw unexpectedErc7201BuiltinAst('string literal `value` is null or missing');
|
|
80
|
+
}
|
|
81
|
+
return literal.value;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=erc7201-builtin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"erc7201-builtin.js","sourceRoot":"","sources":["../../src/utils/erc7201-builtin.ts"],"names":[],"mappings":";;AAiBA,oEAmCC;AAkBD,0CAWC;AAhFD,uCAA4D;AAC5D,yDAA6D;AAC7D,oCAAyC;AAEzC;;;;;;;;;;;GAWG;AACH,SAAgB,4BAA4B,CAAC,IAAgB;IAC3D,4FAA4F;IAC5F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MAAc;IACjD,OAAO,IAAI,qBAAa,CACtB,qDAAqD,MAAM,EAAE,EAC7D,GAAG,EAAE,CACH,oHAAoH,CACvH,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,eAAe,CAAC,IAAgB;IAC9C,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,IAAA,0CAAuB,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,EAAE,GAAG,4BAA4B,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QACrB,OAAO,IAAA,yCAA+B,EAAC,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,qBAAqB,CAAC,OAAgB;IAC7C,+FAA+F;IAC/F,yEAAyE;IACzE,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,OAAO,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;QAC1D,MAAM,2BAA2B,CAAC,2CAA2C,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,OAAO,CAAC,KAAK,CAAC;AACvB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"erc7201.d.ts","sourceRoot":"","sources":["../../src/utils/erc7201.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"erc7201.d.ts","sourceRoot":"","sources":["../../src/utils/erc7201.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,sBAAsB,aAAa,CAAC;AAEjD;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAalE"}
|
package/dist/utils/erc7201.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ERC7201_FORMULA_PREFIX = void 0;
|
|
4
4
|
exports.calculateERC7201StorageLocation = calculateERC7201StorageLocation;
|
|
5
5
|
const ethereumjs_util_1 = require("ethereumjs-util");
|
|
6
|
+
const integer_literals_1 = require("./integer-literals");
|
|
6
7
|
exports.ERC7201_FORMULA_PREFIX = 'erc7201:';
|
|
7
8
|
/**
|
|
8
9
|
* Returns the ERC-7201 storage location hash for a given namespace id using formula:
|
|
@@ -14,11 +15,12 @@ exports.ERC7201_FORMULA_PREFIX = 'erc7201:';
|
|
|
14
15
|
function calculateERC7201StorageLocation(id) {
|
|
15
16
|
const firstHash = (0, ethereumjs_util_1.keccak256)(Buffer.from(id));
|
|
16
17
|
const minusOne = BigInt(`0x${firstHash.toString('hex')}`) - 1n;
|
|
17
|
-
|
|
18
|
+
// Pad to 64 hex chars so that `Buffer.from` doesn't silently truncate odd-length input;
|
|
19
|
+
// `abi.encode(uint256)` is always 32 bytes.
|
|
20
|
+
const minusOneBuffer = Buffer.from(minusOne.toString(16).padStart(64, '0'), 'hex');
|
|
18
21
|
const secondHash = (0, ethereumjs_util_1.keccak256)(minusOneBuffer);
|
|
19
22
|
const mask = BigInt('0xff');
|
|
20
23
|
const masked = BigInt(`0x${secondHash.toString('hex')}`) & ~mask;
|
|
21
|
-
|
|
22
|
-
return `0x${padded}`;
|
|
24
|
+
return (0, integer_literals_1.toBytes32Hex)(masked);
|
|
23
25
|
}
|
|
24
26
|
//# sourceMappingURL=erc7201.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"erc7201.js","sourceRoot":"","sources":["../../src/utils/erc7201.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"erc7201.js","sourceRoot":"","sources":["../../src/utils/erc7201.ts"],"names":[],"mappings":";;;AAaA,0EAaC;AA1BD,qDAA4C;AAE5C,yDAAkD;AAErC,QAAA,sBAAsB,GAAG,UAAU,CAAC;AAEjD;;;;;;GAMG;AACH,SAAgB,+BAA+B,CAAC,EAAU;IACxD,MAAM,SAAS,GAAG,IAAA,2BAAS,EAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC;IAC/D,wFAAwF;IACxF,4CAA4C;IAC5C,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAEnF,MAAM,UAAU,GAAG,IAAA,2BAAS,EAAC,cAAc,CAAC,CAAC;IAE7C,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;IAEjE,OAAO,IAAA,+BAAY,EAAC,MAAM,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -8,4 +8,14 @@ const erc7201_1 = require("./erc7201");
|
|
|
8
8
|
(0, ava_1.default)('calculateERC7201StorageLocation', t => {
|
|
9
9
|
t.is((0, erc7201_1.calculateERC7201StorageLocation)('example.main'), '0x183a6125c38840424c4a85fa12bab2ab606c4b6d0e7cc73c0c06ba5300eab500');
|
|
10
10
|
});
|
|
11
|
+
// `keccak256("ns2") - 1` is 63 hex chars (odd-length), which must be zero-padded to 32 bytes
|
|
12
|
+
// before hashing. Regression test for truncation of the intermediate buffer.
|
|
13
|
+
(0, ava_1.default)('calculateERC7201StorageLocation - odd-length intermediate hash', t => {
|
|
14
|
+
t.is((0, erc7201_1.calculateERC7201StorageLocation)('ns2'), '0xa61069020885c09e922542fb3fa98c8d50e6481fc1251ff86c3319a70f0f7d00');
|
|
15
|
+
});
|
|
16
|
+
// `keccak256("ns297") - 1` is 62 hex chars (i.e., its top byte is `0x00`). Without zero-padding,
|
|
17
|
+
// `Buffer.from('hex')` would interpret it as a 31-byte buffer rather than 32, producing the wrong hash.
|
|
18
|
+
(0, ava_1.default)('calculateERC7201StorageLocation - leading-zero-byte intermediate hash', t => {
|
|
19
|
+
t.is((0, erc7201_1.calculateERC7201StorageLocation)('ns297'), '0xe06f9faa11c8032ea604e1764972c1a5594987f1678d8fabf921c28d1a7a4c00');
|
|
20
|
+
});
|
|
11
21
|
//# sourceMappingURL=erc7201.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"erc7201.test.js","sourceRoot":"","sources":["../../src/utils/erc7201.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAuB;AAEvB,uCAA4D;AAE5D,IAAA,aAAI,EAAC,iCAAiC,EAAE,CAAC,CAAC,EAAE;IAC1C,CAAC,CAAC,EAAE,CACF,IAAA,yCAA+B,EAAC,cAAc,CAAC,EAC/C,oEAAoE,CACrE,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"erc7201.test.js","sourceRoot":"","sources":["../../src/utils/erc7201.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAuB;AAEvB,uCAA4D;AAE5D,IAAA,aAAI,EAAC,iCAAiC,EAAE,CAAC,CAAC,EAAE;IAC1C,CAAC,CAAC,EAAE,CACF,IAAA,yCAA+B,EAAC,cAAc,CAAC,EAC/C,oEAAoE,CACrE,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,6FAA6F;AAC7F,6EAA6E;AAC7E,IAAA,aAAI,EAAC,gEAAgE,EAAE,CAAC,CAAC,EAAE;IACzE,CAAC,CAAC,EAAE,CAAC,IAAA,yCAA+B,EAAC,KAAK,CAAC,EAAE,oEAAoE,CAAC,CAAC;AACrH,CAAC,CAAC,CAAC;AAEH,iGAAiG;AACjG,wGAAwG;AACxG,IAAA,aAAI,EAAC,uEAAuE,EAAE,CAAC,CAAC,EAAE;IAChF,CAAC,CAAC,EAAE,CAAC,IAAA,yCAA+B,EAAC,OAAO,CAAC,EAAE,oEAAoE,CAAC,CAAC;AACvH,CAAC,CAAC,CAAC"}
|
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Encodes a bigint as a 0x-prefixed, 64-char lowercase hex string — the canonical text encoding of
|
|
3
|
+
* a `bytes32` value, used throughout this package for storage slots and similar 256-bit identifiers.
|
|
4
|
+
* Throws if the value is outside the 0..2^256-1 range, since that almost certainly indicates a bug
|
|
5
|
+
* upstream (overflow, wrong hash, etc.) and would silently produce a string longer than 64 chars.
|
|
4
6
|
*
|
|
5
|
-
*
|
|
7
|
+
* @param value bigint value to encode
|
|
8
|
+
* @returns 0x-prefixed, 64-char lowercase hex string
|
|
9
|
+
*/
|
|
10
|
+
export declare function toBytes32Hex(value: bigint): string;
|
|
11
|
+
/**
|
|
12
|
+
* Parses a Solidity unsigned integer literal source string (per
|
|
13
|
+
* https://docs.soliditylang.org/en/latest/types.html#rational-literals) and returns it in the
|
|
14
|
+
* canonical hex form produced by {@link toBytes32Hex}.
|
|
15
|
+
*
|
|
16
|
+
* Parsing is delegated to {@link BigNumber}, which accepts decimal (`1000`), hex (`0x1f`), and
|
|
17
|
+
* scientific notation (`1e18`). Underscore separators and uppercase digits, which BigNumber rejects
|
|
18
|
+
* but Solidity allows, are stripped/lowercased first. Non-integer results (e.g. `1.5e3`) are rejected.
|
|
6
19
|
*
|
|
7
|
-
* If the input is null or undefined, returns
|
|
20
|
+
* If the input is null or undefined, returns the canonical hex form of zero.
|
|
8
21
|
*
|
|
9
22
|
* Assumes the input is a valid uint256-compatible literal for Solidity, and only performs minimal validation.
|
|
10
23
|
*
|
|
11
|
-
* @param literal Integer literal to
|
|
12
|
-
* @returns
|
|
24
|
+
* @param literal Integer literal source string to parse
|
|
25
|
+
* @returns 0x-prefixed, 64-char lowercase hex string
|
|
13
26
|
*/
|
|
14
27
|
export declare function normalizeUint256Literal(literal: string | null | undefined): string;
|
|
15
28
|
//# sourceMappingURL=integer-literals.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integer-literals.d.ts","sourceRoot":"","sources":["../../src/utils/integer-literals.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"integer-literals.d.ts","sourceRoot":"","sources":["../../src/utils/integer-literals.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKlD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAWlF"}
|
|
@@ -3,32 +3,50 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toBytes32Hex = toBytes32Hex;
|
|
6
7
|
exports.normalizeUint256Literal = normalizeUint256Literal;
|
|
7
8
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
|
+
const MAX_UINT256 = (1n << 256n) - 1n;
|
|
8
10
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
+
* Encodes a bigint as a 0x-prefixed, 64-char lowercase hex string — the canonical text encoding of
|
|
12
|
+
* a `bytes32` value, used throughout this package for storage slots and similar 256-bit identifiers.
|
|
13
|
+
* Throws if the value is outside the 0..2^256-1 range, since that almost certainly indicates a bug
|
|
14
|
+
* upstream (overflow, wrong hash, etc.) and would silently produce a string longer than 64 chars.
|
|
11
15
|
*
|
|
12
|
-
*
|
|
16
|
+
* @param value bigint value to encode
|
|
17
|
+
* @returns 0x-prefixed, 64-char lowercase hex string
|
|
18
|
+
*/
|
|
19
|
+
function toBytes32Hex(value) {
|
|
20
|
+
if (value < 0n || value > MAX_UINT256) {
|
|
21
|
+
throw new Error(`Value out of uint256 range: ${value}`);
|
|
22
|
+
}
|
|
23
|
+
return `0x${value.toString(16).padStart(64, '0')}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parses a Solidity unsigned integer literal source string (per
|
|
27
|
+
* https://docs.soliditylang.org/en/latest/types.html#rational-literals) and returns it in the
|
|
28
|
+
* canonical hex form produced by {@link toBytes32Hex}.
|
|
29
|
+
*
|
|
30
|
+
* Parsing is delegated to {@link BigNumber}, which accepts decimal (`1000`), hex (`0x1f`), and
|
|
31
|
+
* scientific notation (`1e18`). Underscore separators and uppercase digits, which BigNumber rejects
|
|
32
|
+
* but Solidity allows, are stripped/lowercased first. Non-integer results (e.g. `1.5e3`) are rejected.
|
|
13
33
|
*
|
|
14
|
-
* If the input is null or undefined, returns
|
|
34
|
+
* If the input is null or undefined, returns the canonical hex form of zero.
|
|
15
35
|
*
|
|
16
36
|
* Assumes the input is a valid uint256-compatible literal for Solidity, and only performs minimal validation.
|
|
17
37
|
*
|
|
18
|
-
* @param literal Integer literal to
|
|
19
|
-
* @returns
|
|
38
|
+
* @param literal Integer literal source string to parse
|
|
39
|
+
* @returns 0x-prefixed, 64-char lowercase hex string
|
|
20
40
|
*/
|
|
21
41
|
function normalizeUint256Literal(literal) {
|
|
22
42
|
if (!literal) {
|
|
23
|
-
return
|
|
43
|
+
return toBytes32Hex(0n);
|
|
24
44
|
}
|
|
25
45
|
const lowercaseNoUnderscores = literal.replace(/_/g, '').toLowerCase();
|
|
26
46
|
const parsed = new bignumber_js_1.default(lowercaseNoUnderscores);
|
|
27
47
|
if (!parsed.isInteger()) {
|
|
28
48
|
throw new Error(`Invalid integer literal: ${literal}`);
|
|
29
49
|
}
|
|
30
|
-
|
|
31
|
-
const padded = calculatedValueAsHex.padStart(64, '0');
|
|
32
|
-
return `0x${padded}`;
|
|
50
|
+
return toBytes32Hex(BigInt(parsed.toFixed()));
|
|
33
51
|
}
|
|
34
52
|
//# sourceMappingURL=integer-literals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integer-literals.js","sourceRoot":"","sources":["../../src/utils/integer-literals.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"integer-literals.js","sourceRoot":"","sources":["../../src/utils/integer-literals.ts"],"names":[],"mappings":";;;;;AAaA,oCAKC;AAkBD,0DAWC;AA/CD,gEAAqC;AAErC,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;AAEtC;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAAC,KAAa;IACxC,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,GAAG,WAAW,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,+BAA+B,KAAK,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,KAAK,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC;AACrD,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,uBAAuB,CAAC,OAAkC;IACxE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,YAAY,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IACD,MAAM,sBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAEvE,MAAM,MAAM,GAAG,IAAI,sBAAS,CAAC,sBAAsB,CAAC,CAAC;IACrD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,4BAA4B,OAAO,EAAE,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -54,4 +54,16 @@ const ZEROES = '0x00000000000000000000000000000000000000000000000000000000000000
|
|
|
54
54
|
(0, ava_1.default)('full hex with leading and trailing zeroes', t => {
|
|
55
55
|
t.is((0, integer_literals_1.normalizeUint256Literal)('0x00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00'), '0x00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00');
|
|
56
56
|
});
|
|
57
|
+
(0, ava_1.default)('rejects values above uint256 max', t => {
|
|
58
|
+
const tooLarge = '0x10000000000000000000000000000000000000000000000000000000000000000';
|
|
59
|
+
const error = t.throws(() => (0, integer_literals_1.normalizeUint256Literal)(tooLarge));
|
|
60
|
+
t.regex(error?.message ?? '', /uint256 range/);
|
|
61
|
+
});
|
|
62
|
+
(0, ava_1.default)('toBytes32Hex - boundaries', t => {
|
|
63
|
+
const MAX_HEX = '0x' + 'f'.repeat(64);
|
|
64
|
+
t.is((0, integer_literals_1.toBytes32Hex)(0n), '0x' + '0'.repeat(64));
|
|
65
|
+
t.is((0, integer_literals_1.toBytes32Hex)(BigInt(MAX_HEX)), MAX_HEX);
|
|
66
|
+
t.throws(() => (0, integer_literals_1.toBytes32Hex)(BigInt(MAX_HEX) + 1n), { message: /uint256 range/ });
|
|
67
|
+
t.throws(() => (0, integer_literals_1.toBytes32Hex)(-1n), { message: /uint256 range/ });
|
|
68
|
+
});
|
|
57
69
|
//# sourceMappingURL=integer-literals.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integer-literals.test.js","sourceRoot":"","sources":["../../src/utils/integer-literals.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAuB;AAEvB,
|
|
1
|
+
{"version":3,"file":"integer-literals.test.js","sourceRoot":"","sources":["../../src/utils/integer-literals.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAuB;AAEvB,yDAA2E;AAE3E,MAAM,MAAM,GAAG,oEAAoE,CAAC;AAEpF,IAAA,aAAI,EAAC,OAAO,EAAE,CAAC,CAAC,EAAE;IAChB,CAAC,CAAC,EAAE,CAAC,IAAA,0CAAuB,EAAC,SAAS,CAAC,EAAE,MAAM,C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AE,CAAC,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC;AAClE,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openzeppelin/upgrades-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.46.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"ava": "^6.0.0",
|
|
58
58
|
"dotenv": "^16.0.0",
|
|
59
59
|
"fgbg": "^0.1.4",
|
|
60
|
-
"hardhat": "^2.
|
|
60
|
+
"hardhat": "^2.28.0",
|
|
61
61
|
"rimraf": "^5.0.0",
|
|
62
62
|
"typescript": "^5.0.0"
|
|
63
63
|
},
|
|
@@ -72,6 +72,6 @@
|
|
|
72
72
|
"minimist": "^1.2.7",
|
|
73
73
|
"proper-lockfile": "^4.1.1",
|
|
74
74
|
"solidity-ast": "^0.4.60",
|
|
75
|
-
"minimatch": "^
|
|
75
|
+
"minimatch": "^10.2.5"
|
|
76
76
|
}
|
|
77
77
|
}
|