Skip to content

Commit

Permalink
fix(pg): Hardcode merkle leaf gas on Darwinia Pangolin
Browse files Browse the repository at this point in the history
  • Loading branch information
RPate97 committed Apr 9, 2024
1 parent 0da20a7 commit 72f363e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 62 deletions.
7 changes: 7 additions & 0 deletions .changeset/polite-brooms-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sphinx-labs/contracts': patch
'@sphinx-labs/plugins': patch
'@sphinx-labs/core': patch
---

Hardcode merkle leaf gas on Darwinia Pangolin
39 changes: 6 additions & 33 deletions packages/contracts/src/networks.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
import { ParsedAccountAccess } from './types'

/**
* Return a hard-coded gas value for Moonbeam, Moonbase Alpha, and Moonriver. We hard-code this
* value as a temporary solution because these networks have a non-standard gas calculation
* mechanism.
*
* @param baseGas The estimated gas cost according to Foundry.
* @param access The ParsedAccountAccess for the transaction.
* @returns
*/
export const calculateActionLeafGasForMoonbeam = (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
foundryGas: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
access: ParsedAccountAccess
): string => {
// This is the maximum Merkle leaf gas size that fits in a batch on these networks. (The max batch
// size is 12M, and there's a buffer applied to the Merkle leaf's gas before we check whether it fits in a
// batch). It's possible to exceed the max batch size if the transaction's calldata is extremely large,
// but that's unlikely to happen. We were able to deploy a very large contract (Mean Finance's DCAHub)
// with this Merkle leaf gas value.
return (10_500_000).toString()
}

export type ExplorerName = 'Blockscout' | 'Etherscan'

export type BlockExplorers = {
Expand Down Expand Up @@ -60,10 +35,7 @@ export type SupportedNetwork = {
provider: RollupProvider
type: RollupType
}
handleNetworkSpecificMerkleLeafGas?: (
foundryGas: string,
access: ParsedAccountAccess
) => string
hardcodedMerkleLeafGas?: string
}

export type SupportedLocalNetwork = {
Expand Down Expand Up @@ -740,7 +712,7 @@ export const SPHINX_NETWORKS: Array<SupportedNetwork> = [
actionGasLimitBuffer: false,
useHigherMaxGasLimit: true,
eip2028: true,
handleNetworkSpecificMerkleLeafGas: calculateActionLeafGasForMoonbeam,
hardcodedMerkleLeafGas: (10_500_000).toString(),
},
{
name: 'moonbeam',
Expand All @@ -765,7 +737,7 @@ export const SPHINX_NETWORKS: Array<SupportedNetwork> = [
actionGasLimitBuffer: false,
useHigherMaxGasLimit: true,
eip2028: true,
handleNetworkSpecificMerkleLeafGas: calculateActionLeafGasForMoonbeam,
hardcodedMerkleLeafGas: (10_500_000).toString(),
},
{
name: 'moonbase_alpha',
Expand All @@ -790,7 +762,7 @@ export const SPHINX_NETWORKS: Array<SupportedNetwork> = [
actionGasLimitBuffer: false,
useHigherMaxGasLimit: true,
eip2028: true,
handleNetworkSpecificMerkleLeafGas: calculateActionLeafGasForMoonbeam,
hardcodedMerkleLeafGas: (10_500_000).toString(),
},
{
name: 'fuse',
Expand Down Expand Up @@ -1253,7 +1225,8 @@ export const SPHINX_NETWORKS: Array<SupportedNetwork> = [
queryFilterBlockLimit: 2000,
legacyTx: false,
actionGasLimitBuffer: false,
useHigherMaxGasLimit: false,
useHigherMaxGasLimit: true,
eip2028: true,
hardcodedMerkleLeafGas: (14_000_000).toString(),
},
]
80 changes: 61 additions & 19 deletions packages/contracts/test/SphinxInitCode.sol

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions packages/core/src/networks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Warning: The constants in this file are commonly imported from the frontend of the Sphinx Managed website.
// Be careful when importing external dependencies to this file because they may cause issues when this file
// is imported by the website.
import { ParsedAccountAccess } from '@sphinx-labs/contracts'
import {
ExplorerName,
SPHINX_LOCAL_NETWORKS,
Expand Down Expand Up @@ -125,15 +124,11 @@ export const fetchDripVersionForNetwork = (chainId: bigint) => {
}
}

export const calculateMerkleLeafGas = (
chainId: bigint,
foundryGas: string,
access: ParsedAccountAccess
) => {
export const calculateMerkleLeafGas = (chainId: bigint, foundryGas: string) => {
const network = SPHINX_NETWORKS.find((n) => n.chainId === chainId)

if (network?.handleNetworkSpecificMerkleLeafGas) {
return network.handleNetworkSpecificMerkleLeafGas(foundryGas, access)
if (network?.hardcodedMerkleLeafGas) {
return network.hardcodedMerkleLeafGas
} else {
return foundryGas
}
Expand Down
3 changes: 1 addition & 2 deletions packages/plugins/src/foundry/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ export const makeNetworkConfig = (
const { root, nested } = accountAccesses[i]
const gas = calculateMerkleLeafGas(
BigInt(chainId),
gasEstimates[i].toString(),
accountAccesses[i]
gasEstimates[i].toString()
)

const { parsedContracts, unlabeled } = parseNestedContractDeployments(
Expand Down

0 comments on commit 72f363e

Please sign in to comment.