Skip to content

Commit

Permalink
feat: nonce check in storage map
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSulpiride committed Aug 13, 2024
1 parent e38baaa commit 91a9dfa
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,13 @@ export class FastlaneRelayer extends BaseRelayer {
async canSubmitBundle(): Promise<boolean> {
try {
const provider = new providers.JsonRpcProvider(
"https://rpc-mainnet.maticvigil.com"
"https://polygon-bor-rpc.publicnode.com"
);
const validators = await provider.send("bor_getCurrentValidators", []);
const validator = await provider.send("bor_getCurrentProposer", []);
this.logger.debug(`Fastlane: current proposer: ${validator}`);
for (let fastlane of this.networkConfig.fastlaneValidators) {
fastlane = fastlane.toLowerCase();
if (
validators.some(
(validator: { signer: string }) =>
validator.signer.toLowerCase() == fastlane
)
) {
if (validator.toLowerCase() == fastlane) {
return true;
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/executor/src/services/BundlingService/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
EchoRelayer,
FastlaneRelayer,
} from "./relayers";
import { getUserOpGasLimit } from "./utils";
import { getNonceStorageMapForBundle, getUserOpGasLimit } from "./utils";

export class BundlingService {
private mutex: Mutex;
Expand Down Expand Up @@ -439,6 +439,9 @@ export class BundlingService {
);
await this.mempoolService.attemptToBundle(bundle.entries);

this.logger.debug(bundle.storageMap, "before");
bundle.storageMap = getNonceStorageMapForBundle(bundle);
this.logger.debug(bundle.storageMap, "after");
if (this.config.testingMode) {
// need to wait for the tx hash during testing
await this.relayer.sendBundle(bundle).catch((err) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./getUserOpHashes";
export * from "./estimateBundleGasLimit";
export * from "./nonceStorageMap";
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { BigNumber, BigNumberish, ethers } from "ethers";
import { Bundle, StorageMap } from "../../../interfaces";
import { mergeStorageMap } from "../../../utils/mergeStorageMap";

const EP6_NONCE_SLOT = 1;

export function getNonceStorageMap(
account: string,
nonce: BigNumberish
): [string, BigNumber] {
const abiCoder = new ethers.utils.AbiCoder();
const key = BigNumber.from(nonce).shr(64);
const seq = BigNumber.from(nonce).shl(192).shr(192);
const keyLevelEncoded = abiCoder.encode(
["address", "uint256"],
[account, EP6_NONCE_SLOT]
);
const nonceLevelEncoded = abiCoder.encode(["uint192"], [key]);
const slot = ethers.utils.keccak256(
ethers.utils.concat([
nonceLevelEncoded,
ethers.utils.keccak256(keyLevelEncoded),
])
);
return [slot, seq];
}

export function getNonceStorageMapForBundle(bundle: Bundle): StorageMap {
if (bundle.entries.length == 0) return bundle.storageMap;
const storageMap = { ...bundle.storageMap }; // cloning
const entryPoint = bundle.entries[0].entryPoint;
for (const entry of bundle.entries) {
const { userOp } = entry;
const nonceCheck = getNonceStorageMap(userOp.sender, userOp.nonce);
mergeStorageMap(storageMap, {
[entryPoint]: {
[nonceCheck[0]]: nonceCheck[1].toString(),
},
});
}
return storageMap;
}

0 comments on commit 91a9dfa

Please sign in to comment.