Skip to content

Commit 94f02f3

Browse files
committed
WIP
1 parent 82c12d3 commit 94f02f3

File tree

4 files changed

+24
-30
lines changed

4 files changed

+24
-30
lines changed

src/genesis-hardhat/create-genesis-hardhat.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export async function createGenesisHardhat(_genesisBase: any, initializeParams:
153153
const sovereignChainBridgeContract = bridgeDeploymentResult.contract as unknown as BridgeL2SovereignChain;
154154

155155
// Get addresses from bridge deployment
156-
const bridgeProxyAddress = sovereignChainBridgeContract.target;
156+
const bridgeProxyAddress = sovereignChainBridgeContract.target.toString().toLowerCase();
157157
const bridgeImplAddress = (await upgrades.erc1967.getImplementationAddress(bridgeProxyAddress)).toLocaleLowerCase();
158158
const tokenWrappedAddress = (
159159
await sovereignChainBridgeContract.getWrappedTokenBridgeImplementation()
@@ -173,7 +173,7 @@ export async function createGenesisHardhat(_genesisBase: any, initializeParams:
173173
const gerManagerContract = gerDeploymentResult.contract as unknown as GlobalExitRootManagerL2SovereignChain;
174174

175175
// Get addresses from ger deployment
176-
const gerProxyAddress = gerManagerContract.target;
176+
const gerProxyAddress = gerManagerContract.target.toString().toLowerCase();
177177
const gerImplAddress = await upgrades.erc1967.getImplementationAddress(gerProxyAddress);
178178

179179
/// ///////////////////////////////////
@@ -182,6 +182,7 @@ export async function createGenesisHardhat(_genesisBase: any, initializeParams:
182182

183183
let globalExitRootUpdater;
184184
let aggOracleImplementationAddress;
185+
let aggOracleCommitteeAddress;
185186
let aggOracleCommitteeContract;
186187
let aggOracleCommitteeDeploymentResult;
187188
let txInitializeAggOracleCommittee;
@@ -202,6 +203,7 @@ export async function createGenesisHardhat(_genesisBase: any, initializeParams:
202203
aggOracleCommitteeContract = aggOracleCommitteeDeploymentResult.contract as unknown as AggOracleCommittee;
203204
initializeParams.globalExitRootUpdater = aggOracleCommitteeContract.target;
204205
globalExitRootUpdater = aggOracleCommitteeContract.target;
206+
aggOracleCommitteeAddress = aggOracleCommitteeContract.target;
205207
aggOracleImplementationAddress = await upgrades.erc1967.getImplementationAddress(
206208
aggOracleCommitteeContract.target,
207209
);
@@ -365,10 +367,8 @@ export async function createGenesisHardhat(_genesisBase: any, initializeParams:
365367
const initTx = await ethers.provider.getTransaction(txInitializeBridge.hash);
366368
if (initTx) {
367369
const initStorageWrites = await getTraceStorageWrites(txInitializeBridge.hash);
368-
storageModifications.BridgeL2SovereignChain_Initialization = initStorageWrites[bridgeImplAddress];
370+
storageModifications.BridgeL2SovereignChain_Initialization = initStorageWrites[bridgeProxyAddress];
369371
storageModifications.TokenWrappedBridgeUpgradeable = initStorageWrites[WETHTokenAddress];
370-
storageModifications.TokenWrappedBridgeUpgradeable_Initialization =
371-
initStorageWrites[tokenWrappedAddress];
372372
}
373373
} catch (error) {
374374
logger.error('Could not get Bridge initialization storage writes:', error);
@@ -400,7 +400,7 @@ export async function createGenesisHardhat(_genesisBase: any, initializeParams:
400400
if (implTx) {
401401
const implStorageWrites = await getTraceStorageWrites(
402402
aggOracleCommitteeDeploymentResult.txHashes.proxy,
403-
aggOracleCommitteeContract.target,
403+
aggOracleCommitteeAddress,
404404
);
405405
storageModifications.AggOracleCommittee = implStorageWrites;
406406
}
@@ -415,7 +415,7 @@ export async function createGenesisHardhat(_genesisBase: any, initializeParams:
415415
if (initTx) {
416416
const initStorageWrites = await getTraceStorageWrites(
417417
txInitializeAggOracleCommittee.hash,
418-
aggOracleImplementationAddress,
418+
aggOracleCommitteeAddress,
419419
);
420420
storageModifications.AggOracleCommittee_Initialization = initStorageWrites;
421421
}
@@ -464,7 +464,7 @@ export async function createGenesisHardhat(_genesisBase: any, initializeParams:
464464
try {
465465
const gerInitTx = await ethers.provider.getTransaction(txInitializeGer.hash);
466466
if (gerInitTx) {
467-
const gerInitStorageWrites = await getTraceStorageWrites(txInitializeGer.hash, gerImplAddress);
467+
const gerInitStorageWrites = await getTraceStorageWrites(txInitializeGer.hash, gerProxyAddress);
468468
storageModifications.GlobalExitRootManagerL2SovereignChain_Initialization = gerInitStorageWrites;
469469
}
470470
} catch (error) {
@@ -521,10 +521,7 @@ export async function createGenesisHardhat(_genesisBase: any, initializeParams:
521521
sovereignChainBridgeContract,
522522
tokenWrappedAddress,
523523
);
524-
expectedStorageModifications.TokenWrappedBridgeUpgradeable = tokenStorage.tokenWrappedBridgeUpgradeable;
525-
// proxy storage init
526-
expectedStorageModifications.TokenWrappedBridgeUpgradeable_Initialization =
527-
tokenStorage.tokenWrappedBridgeUpgradeableInit;
524+
expectedStorageModifications.TokenWrappedBridgeUpgradeable = tokenStorage;
528525
// Add WETH to bridge storage
529526
updateExpectedStorageBridgeToken(
530527
expectedStorageModifications.BridgeL2SovereignChain_Initialization,
@@ -615,10 +612,6 @@ export async function createGenesisHardhat(_genesisBase: any, initializeParams:
615612
storageModifications.TokenWrappedBridgeUpgradeable,
616613
wethAddressProxy,
617614
);
618-
actualStorage.TokenWrappedBridgeUpgradeable_Initialization = await getActualStorage(
619-
storageModifications.TokenWrappedBridgeUpgradeable_Initialization,
620-
wethAddressProxy,
621-
);
622615
}
623616
// AggOracleCommittee
624617
if (initializeParams.useAggOracleCommittee === true) {

src/genesis-hardhat/utils.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export async function getTraceStorageWrites(txHash: any, address = undefined) {
1414
if (!infoTx) {
1515
throw new Error(`No info tx: ${txHash}`);
1616
}
17-
const addressInfo: { address?: string; nonce?: number } = {};
17+
const addressInfo: { address?: string; sender?: string; nonce?: number } = {};
18+
addressInfo.sender = infoTx.from.toLowerCase();
1819
if (!infoTx.to) {
1920
const receipt = await ethers.provider.getTransactionReceipt(txHash);
2021
addressInfo.address = receipt?.contractAddress?.toLowerCase();
@@ -388,14 +389,13 @@ export async function getExpectedStorageTokenWrappedBridgeUpgradeable(
388389
) {
389390
// Add proxy WETH
390391
const wethAddressProxy = await sovereignChainBridgeContract.WETHToken();
391-
const tokenWrappedBridgeUpgradeable = {};
392392
const tokenWrappedBridgeUpgradeableInit = {};
393-
tokenWrappedBridgeUpgradeable[STORAGE_GENESIS.STORAGE_PROXY.IMPLEMENTATION] = ethers.zeroPadValue(
393+
tokenWrappedBridgeUpgradeableInit[STORAGE_GENESIS.STORAGE_PROXY.IMPLEMENTATION] = ethers.zeroPadValue(
394394
tokenWrappedAddress,
395395
32,
396396
);
397397
const adminWethProxy = await upgrades.erc1967.getAdminAddress(wethAddressProxy as string);
398-
tokenWrappedBridgeUpgradeable[STORAGE_GENESIS.STORAGE_PROXY.ADMIN] = ethers.zeroPadValue(adminWethProxy, 32);
398+
tokenWrappedBridgeUpgradeableInit[STORAGE_GENESIS.STORAGE_PROXY.ADMIN] = ethers.zeroPadValue(adminWethProxy, 32);
399399
// proxy storage init
400400
tokenWrappedBridgeUpgradeableInit[STORAGE_GENESIS.TOKEN_WRAPPED_BRIDGE_UPGRADEABLE_STORAGE.INITIALIZER] =
401401
ethers.zeroPadValue('0x01', 32);
@@ -419,10 +419,8 @@ export async function getExpectedStorageTokenWrappedBridgeUpgradeable(
419419
tokenWrappedBridgeUpgradeableInit[
420420
STORAGE_GENESIS.TOKEN_WRAPPED_BRIDGE_UPGRADEABLE_STORAGE.WETH_DECIMALS_BRIDGE_ADDRESS
421421
] = ethers.zeroPadValue(`${sovereignChainBridgeContract.target}${ethers.toBeHex(18).slice(2).toLowerCase()}`, 32);
422-
return {
423-
tokenWrappedBridgeUpgradeable,
424-
tokenWrappedBridgeUpgradeableInit,
425-
};
422+
423+
return tokenWrappedBridgeUpgradeableInit;
426424
}
427425

428426
export async function getExpectedStorageAggOracleCommittee(initParams, aggOracleCommitteeContract) {

src/utils.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export async function getStorageWrites(trace, addressInfo) {
103103
const addresses: { [address: string]: any } = {};
104104
addresses[addressInfo.address] = addressInfo.nonce;
105105
const stackAddressesStorage = [addressInfo.address];
106-
const stackAddressesCaller = [addressInfo.address];
107106
const logs = trace.structLogs.filter(
108107
(log) =>
109108
log.op === 'CALL' ||
@@ -122,20 +121,23 @@ export async function getStorageWrites(trace, addressInfo) {
122121
const writeObject: { [address: string]: any } = {};
123122
// eslint-disable-next-line no-restricted-syntax
124123
for (const log of logs) {
125-
if (log.op === 'DELEGATECALL' || log.op === 'CALL' || log.op === 'STATICCALL' || log.op === 'CALLCODE') {
124+
if (log.op === 'CALL' || log.op === 'STATICCALL') {
126125
// Get address from stack
127126
const addressStack = `0x${log.stack.slice(-2)[0].slice(-40)}`;
128127
// eslint-disable-next-line no-await-in-loop
129128
addresses[addressStack] = await ethers.provider.getTransactionCount(addressStack);
130129
// Update address stack
131130
stackAddressesStorage.push(addressStack);
131+
} else if (log.op === 'DELEGATECALL' || log.op === 'CALLCODE') {
132+
// Update address stack
133+
stackAddressesStorage.push(stackAddressesStorage[stackAddressesStorage.length - 1]);
132134
} else if (log.op === 'CREATE') {
133135
// Get actual address (create is with this address)
134-
const actualAddress = stackAddressesCaller[stackAddressesCaller.length - 1];
136+
const actualAddress = stackAddressesStorage[stackAddressesStorage.length - 1];
135137
// Calculate with actual address and nonce
136138
const calculatedAddress = ethers.getCreateAddress({
137139
from: actualAddress,
138-
nonce: addresses[actualAddress]
140+
nonce: addresses[actualAddress],
139141
});
140142
// Add new address and nonce
141143
addresses[calculatedAddress] = 1;
@@ -147,7 +149,7 @@ export async function getStorageWrites(trace, addressInfo) {
147149
// eslint-disable-next-line no-await-in-loop
148150
await fs.writeFileSync('log.json', JSON.stringify(log, null, 1));
149151
// Get actual address (create is with this address)
150-
const actualAddress = stackAddressesCaller[stackAddressesCaller.length - 1];
152+
const actualAddress = stackAddressesStorage[stackAddressesStorage.length - 1];
151153
const parameters = log.stack.slice(-4);
152154
const memHex = `${log.memory.join('')}`;
153155
const salt = `0x${parameters[0]}`;

tools/createSovereignGenesisHardhat/create-genesis-sovereign-params.json.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@
3030
"aggOracleCommittee": ["0x8576158a89648aA88B6036f47B8b74Fc0C2b5c66", "0xb420EAAbFeFA05b39dE520f811325A463E023954"],
3131
"quorum": 1,
3232
"aggOracleOwner": "0x8576158a89648aA88B6036f47B8b74Fc0C2b5c66",
33-
"formatGenesis": "geth"
33+
"formatGenesis": "geth",
34+
"debug": true
3435
}

0 commit comments

Comments
 (0)