Skip to content

Commit

Permalink
fix(core): Handle bytecode hash is none during verification
Browse files Browse the repository at this point in the history
  • Loading branch information
RPate97 committed Feb 19, 2024
1 parent fa61861 commit f980cc2
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .changeset/quick-singers-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sphinx-labs/plugins': patch
'@sphinx-labs/core': patch
---

Handle bytecodeHash=none during etherscan verification
5 changes: 2 additions & 3 deletions packages/core/src/etherscan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as dotenv from 'dotenv'
import { ethers } from 'ethers'
import { CompilerInput } from 'hardhat/types'
import {
CompilerOutputMetadata,
SystemContractType,
Expand All @@ -25,7 +24,7 @@ import {
isLiveNetwork,
sleep,
} from './utils'
import { BuildInfo } from './languages'
import { BuildInfo, SolcInput } from './languages'
import {
fetchNameForNetwork,
isVerificationSupportedForNetwork,
Expand Down Expand Up @@ -192,7 +191,7 @@ export const attemptVerification = async (
encodedConstructorArgs: string,
fullyQualifiedName: string,
solcLongVersion: string,
minimumCompilerInput: CompilerInput,
minimumCompilerInput: SolcInput,
provider: ethers.Provider,
chainId: string,
etherscanApiKey: string
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/languages/solidity/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CompilerInput } from 'hardhat/types'
import { CompilerOutputMetadata } from '@sphinx-labs/contracts'

import { SolcInput } from './types'

/**
* Returns the minimum compiler input necessary to compile a given source name. All contracts that
* are imported in the given source must be included in the minimum compiler input.
Expand All @@ -11,16 +12,16 @@ import { CompilerOutputMetadata } from '@sphinx-labs/contracts'
* @returns Minimum compiler input necessary to compile the source name.
*/
export const getMinimumCompilerInput = (
fullCompilerInput: CompilerInput,
fullCompilerInput: SolcInput,
metadata: CompilerOutputMetadata
): CompilerInput => {
const minimumSources: CompilerInput['sources'] = {}
): SolcInput => {
const minimumSources: SolcInput['sources'] = {}
for (const newSourceName of Object.keys(metadata.sources)) {
minimumSources[newSourceName] = fullCompilerInput.sources[newSourceName]
}

const { language, settings } = fullCompilerInput
const minimumCompilerInput: CompilerInput = {
const minimumCompilerInput: SolcInput = {
language,
settings,
sources: minimumSources,
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/languages/solidity/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ export interface SolcInput {
}
}
}
metadata?: { useLiteralContent: boolean }
metadata?: {
useLiteralContent: boolean
bytecodeHash: string
appendCBOR: boolean
}
outputSelection: {
[sourceName: string]: {
[contractName: string]: string[]
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/test/Solc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Solidity Compiler', () => {
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
],
{
SPHINX_INTERNAL_TEST__SKIP_GIT: 'true',
SPHINX_INTERNAL_TEST__DEMO_TEST: 'true',
}
)
if (code !== 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/demo/test/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ describe('Init CLI command', () => {

const ownerAddress = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'

// We use `SPHINX_INTERNAL_TEST__SKIP_GIT` to skip the init command steps where we create a git repo and commit all the files to it.
// We use `SPHINX_INTERNAL_TEST__DEMO_TEST` to skip the init command steps where we create a git repo and commit all the files to it.
// We do this to avoid messing with out commit history when testing locally.
await execAsync(
`export SPHINX_INTERNAL_TEST__SKIP_GIT=true && npx sphinx init --org-id TEST_ORG_ID --sphinx-api-key TEST_SPHINX_KEY --alchemy-api-key TEST_ALCHEMY_KEY --owner ${ownerAddress}`
`export SPHINX_INTERNAL_TEST__DEMO_TEST=true && npx sphinx init --org-id TEST_ORG_ID --sphinx-api-key TEST_SPHINX_KEY --alchemy-api-key TEST_ALCHEMY_KEY --owner ${ownerAddress}`
)

// Check that the files have been created
Expand Down
12 changes: 7 additions & 5 deletions packages/plugins/src/cli/install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ const installWithUpdate = async (
ci: boolean
) => {
if (!ci) {
await userConfirmation(
'Would you like to install the Sphinx Foundry fork? This is required to use Sphinx and will replace your existing Foundry installation.\nConfirm? (y\\n):'
)
if (process.env.SPHINX_INTERNAL_TEST__DEMO_TEST !== 'true') {
await userConfirmation(
'Would you like to install the Sphinx Foundry fork? This is required to use Sphinx and will replace your existing Foundry installation.\nConfirm? (y\\n):'
)
}
const foundryupStatus = await spawnAsync('/bin/bash', [
'-c',
'curl -L https://foundry.paradigm.xyz | bash',
Expand Down Expand Up @@ -103,9 +105,9 @@ const installWithUpdate = async (
export const handleInstall = async (
spinner: ora.Ora,
skipLibrary: boolean,
confirm: boolean
ci: boolean
) => {
await installWithUpdate(spinner, skipLibrary, confirm)
await installWithUpdate(spinner, skipLibrary, ci)
if (skipLibrary) {
return
}
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/src/foundry/utils/trim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export const BuildInfoTemplate: BuildInfo = {
},
metadata: {
useLiteralContent: false,
bytecodeHash: '',
appendCBOR: true,
},
outputSelection: {
sphinx_all_keys: {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/src/sample-project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const sampleScriptFileName = 'HelloSphinx.s.sol'
export const sampleTestFileName = 'HelloSphinx.t.sol'

const handleGitInit = async () => {
if (process.env.SPHINX_INTERNAL_TEST__SKIP_GIT === 'true') {
if (process.env.SPHINX_INTERNAL_TEST__DEMO_TEST === 'true') {
return
}

Expand All @@ -40,7 +40,7 @@ const handleGitInit = async () => {
}

const handleCommit = async () => {
if (process.env.SPHINX_INTERNAL_TEST__SKIP_GIT === 'true') {
if (process.env.SPHINX_INTERNAL_TEST__DEMO_TEST === 'true') {
return
}

Expand Down

0 comments on commit f980cc2

Please sign in to comment.