Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: change state override detection #1077

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/libs/deployless/simulateDeployCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { DeploylessMode, fromDescriptor } from './deployless'
// on the given network
export async function getSASupport(
provider: JsonRpcProvider
): Promise<{ addressMatches: boolean; supportsStateOverride: boolean }> {
): Promise<{ addressMatches: boolean }> {
const smartAccount = await getSmartAccount(
[
{
Expand All @@ -31,7 +31,6 @@ export async function getSASupport(
mode: DeploylessMode.StateOverride
}
const deployless = fromDescriptor(provider, AmbireFactory, true)
let supportsStateOverride = true
const result = await deployless
.call(
'deployAndExecute',
Expand All @@ -50,12 +49,10 @@ export async function getSASupport(

// if there's an error, return the zero address indicating that
// our smart accounts will most likely not work on this chain
supportsStateOverride = false
return [ZeroAddress]
})

return {
addressMatches: result[0] === smartAccount.addr,
supportsStateOverride
addressMatches: result[0] === smartAccount.addr
}
}
42 changes: 42 additions & 0 deletions src/libs/deployless/supportsStateOverride.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { JsonRpcProvider, ZeroAddress } from 'ethers'

import Estimation from '../../../contracts/compiled/Estimation.json'
import { FEE_COLLECTOR } from '../../consts/addresses'
import { getEOAEstimationStateOverride } from '../estimate/estimateEOA'
import { EOA_SIMULATION_NONCE } from '../portfolio/getOnchainBalances'
import { Deployless, DeploylessMode } from './deployless'

export async function doesItSupportStateOverride(provider: JsonRpcProvider) {
const estimator = new Deployless(provider, Estimation.abi, Estimation.bin, Estimation.binRuntime)

// try to write to the state in deployless mode
const accAddr = '0xc1e7354c7d11d95BDa4adf2A3Fd8984E1ddE7aCc'
const result = await estimator
.call(
'estimateEoa',
[
accAddr,
[
accAddr,
EOA_SIMULATION_NONCE,
[['0x3e2D734349654166a2Ad92CaB2437A76a70B650a', 1n, '0x']],
'0x'
],
'0x',
[accAddr],
FEE_COLLECTOR,
ZeroAddress
],
{
from: '0x0000000000000000000000000000000000000001',
blockTag: 'latest',
mode: DeploylessMode.StateOverride,
stateToOverride: getEOAEstimationStateOverride(accAddr)
}
)
.catch(() => {
return 'not working'
})

return result !== 'not working'
}
2 changes: 1 addition & 1 deletion src/libs/estimate/estimateEOA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const abiCoder = new AbiCoder()

// this is the state override we use for the EOA when
// estimating through Estimation.sol
function getEOAEstimationStateOverride(accountAddr: string) {
export function getEOAEstimationStateOverride(accountAddr: string) {
return {
[accountAddr]: {
code: AmbireAccount.binRuntime,
Expand Down
9 changes: 6 additions & 3 deletions src/libs/networks/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { RPCProviders } from '../../interfaces/provider'
import { Bundler } from '../../services/bundlers/bundler'
import { getRpcProvider } from '../../services/provider'
import { getSASupport } from '../deployless/simulateDeployCall'
import { doesItSupportStateOverride } from '../deployless/supportsStateOverride'

// bnb, fantom, metis
const relayerAdditionalNetworks = [56n, 250n, 1088n]
Expand Down Expand Up @@ -84,12 +85,14 @@ export async function getNetworkInfo(
retryRequest(() => provider.getCode(SINGLETON)),
retryRequest(() => provider.getCode(AMBIRE_ACCOUNT_FACTORY)),
retryRequest(() => getSASupport(provider)),
retryRequest(() => doesItSupportStateOverride(provider)),
Bundler.isNetworkSupported(fetch, chainId).catch(() => false)
// retryRequest(() => provider.getCode(ERC_4337_ENTRYPOINT)),
]).catch((e: Error) =>
raiseFlagged(e, ['0x', '0x', { addressMatches: false, supportsStateOverride: false }])
)
const [singletonCode, factoryCode, saSupport, is4337enabled] = responses
const [singletonCode, factoryCode, saSupport, supportsStateOverride, is4337enabled] =
responses
const areContractsDeployed = factoryCode !== '0x'
// const has4337 = entryPointCode !== '0x' && hasBundler
const predefinedNetwork = predefinedNetworks.find((net) => net.chainId === chainId)
Expand All @@ -98,7 +101,7 @@ export async function getNetworkInfo(
// - or we can't do the simulation with this RPC but we have the factory
// deployed on the network
const supportsAmbire =
saSupport.addressMatches || (!saSupport.supportsStateOverride && areContractsDeployed)
saSupport.addressMatches || (!supportsStateOverride && areContractsDeployed)
networkInfo = {
...networkInfo,
hasSingleton: singletonCode !== '0x',
Expand All @@ -107,7 +110,7 @@ export async function getNetworkInfo(
rpcNoStateOverride:
predefinedNetwork && predefinedNetwork.rpcNoStateOverride === true
? true
: !saSupport.supportsStateOverride,
: !supportsStateOverride,
erc4337: {
enabled: predefinedNetwork ? predefinedNetwork.erc4337.enabled : is4337enabled,
hasPaymaster: predefinedNetwork ? predefinedNetwork.erc4337.hasPaymaster : false
Expand Down
Loading