Skip to content
Merged
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
25 changes: 22 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/compilers-types/src/CompilationTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Abi } from "abitype";
import { JsonFragment } from "ethers";
import { SolidityOutputError, SoliditySettings } from "./SolidityTypes";
import { VyperOutputError } from "./VyperTypes";

Expand Down Expand Up @@ -75,7 +75,7 @@ export interface Userdoc {
export type OutputError = SolidityOutputError | VyperOutputError;

export interface MetadataOutput {
abi: Abi;
abi: JsonFragment[];
devdoc?: Devdoc;
userdoc?: Userdoc;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/compilers-types/src/SolidityTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Abi } from "abitype";
import { JsonFragment } from "ethers";
import { Devdoc, Userdoc, LinkReferences } from "./CompilationTypes";

interface File {
Expand Down Expand Up @@ -158,7 +158,7 @@ export interface StorageLayout {
};
}
export interface SolidityOutputContract {
abi: Abi;
abi: JsonFragment[];
metadata: string;
userdoc?: Userdoc;
devdoc?: Devdoc;
Expand Down
4 changes: 2 additions & 2 deletions packages/compilers-types/src/VyperTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Abi } from "abitype";
import { JsonFragment } from "ethers";
import { Devdoc } from "./CompilationTypes";
import { Userdoc } from "./CompilationTypes";

Expand Down Expand Up @@ -63,7 +63,7 @@ export interface VyperOutputSources {
}

export interface VyperOutputContract {
abi: Abi;
abi: JsonFragment[];
userdoc: Userdoc;
devdoc: Devdoc;
ir: string;
Expand Down
2 changes: 0 additions & 2 deletions packages/lib-sourcify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@
"@ethereumjs/statemanager": "2.4.0",
"@ethereumjs/util": "9.1.0",
"@ethereumjs/vm": "8.1.1",
"@ethersproject/abi": "5.8.0",
"@ethersproject/bignumber": "5.8.0",
"@ethersproject/bytes": "5.8.0",
"@fairdatasociety/bmt-js": "2.1.0",
"abitype": "1.0.8",
"bs58": "5.0.0",
"ethers": "6.15.0",
"jszip": "3.10.1",
Expand Down
1 change: 1 addition & 0 deletions packages/lib-sourcify/src/Compilation/CompilationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type CompilationLanguage = 'Solidity' | 'Vyper';
export type CompilationErrorCode =
| 'cannot_generate_cbor_auxdata_positions'
| 'invalid_compiler_version'
| 'unsupported_compiler_version'
| 'contract_not_found_in_compiler_output'
| 'compiler_error'
| 'no_compiler_output'
Expand Down
68 changes: 68 additions & 0 deletions packages/lib-sourcify/src/Compilation/SolidityCompilation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AuxdataStyle, splitAuxdata } from '@ethereum-sourcify/bytecode-utils';
import semver from 'semver';
import { AbstractCompilation } from './AbstractCompilation';
import {
ImmutableReferences,
Expand Down Expand Up @@ -41,6 +42,14 @@ export class SolidityCompilation extends AbstractCompilation {
public compilationTarget: CompilationTarget,
) {
super(compilerVersion, jsonInput);

// Throw error for unsupported compiler versions
if (semver.lt(this.compilerVersion, '0.4.11')) {
throw new CompilationError({
code: 'unsupported_compiler_version',
});
}

this.initSolidityJsonInput();
}

Expand Down Expand Up @@ -96,6 +105,65 @@ export class SolidityCompilation extends AbstractCompilation {
*/
public async generateCborAuxdataPositions(forceEmscripten = false) {
try {
// Handle legacy Solidity versions with different auxdata support
// CBOR auxdata was introduced in Solidity 0.4.7 https://github.com/ethereum/solidity/releases/tag/v0.4.7
if (semver.lt(this.compilerVersion, '0.4.7')) {
// No auxdata exists in versions before 0.4.7
this._creationBytecodeCborAuxdata = {};
this._runtimeBytecodeCborAuxdata = {};
return;
}

// For versions 0.4.7-0.4.11, auxdata exists but is not in legacyAssembly https://github.com/ethereum/sourcify/issues/2217
if (semver.lte(this.compilerVersion, '0.4.11')) {
// Extract auxdata directly from the end of bytecodes using splitAuxdata
// Runtime bytecode auxdata
const [, runtimeAuxdataCbor, runtimeCborLengthHex] = splitAuxdata(
this.runtimeBytecode,
this.auxdataStyle,
);

if (runtimeAuxdataCbor) {
const auxdataFromRawRuntimeBytecode = `${runtimeAuxdataCbor}${runtimeCborLengthHex}`;
this._runtimeBytecodeCborAuxdata = {
'1': {
offset:
this.runtimeBytecode.substring(2).length / 2 -
parseInt(runtimeCborLengthHex, 16) -
2, // bytecode has 2 bytes of cbor length prefix at the end
value: `0x${auxdataFromRawRuntimeBytecode}`,
},
};
} else {
this._runtimeBytecodeCborAuxdata = {};
}

// Creation bytecode auxdata
// We'll try to extract the auxdata from the end of the bytecode
// If it's not at the end and somewhere else, there isn't much we can do. The verification will likely fail.
const [, creationAuxdataCbor, creationCborLengthHex] = splitAuxdata(
this.creationBytecode,
this.auxdataStyle,
);

if (creationAuxdataCbor) {
const auxdataFromRawCreationBytecode = `${creationAuxdataCbor}${creationCborLengthHex}`;
this._creationBytecodeCborAuxdata = {
'1': {
offset:
this.creationBytecode.substring(2).length / 2 -
parseInt(creationCborLengthHex, 16) -
2, // bytecode has 2 bytes of cbor length prefix at the end
value: `0x${auxdataFromRawCreationBytecode}`,
},
};
} else {
this._creationBytecodeCborAuxdata = {};
}
return;
}

// For versions > 0.4.11, use the existing legacyAssembly-based approach
// Auxdata array extracted from the compiler's `legacyAssembly` field
const auxdatasFromCompilerOutput = findAuxdatasInLegacyAssembly(
(this.contractCompilerOutput as SolidityOutputContract).evm
Expand Down
13 changes: 5 additions & 8 deletions packages/lib-sourcify/src/Verification/Transformations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
CompiledContractCborAuxdata,
StringMap,
} from '../Compilation/CompilationTypes';
import { AbiConstructor } from 'abitype';
import { defaultAbiCoder as abiCoder, ParamType } from '@ethersproject/abi';
import { id as keccak256Str } from 'ethers';
import { AbiCoder, id as keccak256Str, Interface } from 'ethers';
import { logError } from '../logger';

const abiCoder = AbiCoder.defaultAbiCoder();

export type Transformation = {
type: 'insert' | 'replace';
reason:
Expand Down Expand Up @@ -202,11 +202,8 @@ export function extractConstructorArgumentsTransformation(
populatedRecompiledBytecode,
onchainCreationBytecode,
);
const constructorAbiParamInputs = (
metadata?.output?.abi?.find(
(param) => param.type === 'constructor',
) as AbiConstructor
)?.inputs as ParamType[];
const constructorAbiParamInputs = new Interface(metadata?.output?.abi).deploy
.inputs;
if (abiEncodedConstructorArguments) {
if (!constructorAbiParamInputs) {
throw new Error(
Expand Down
4 changes: 2 additions & 2 deletions packages/lib-sourcify/src/Verification/VerificationTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Abi } from 'abitype';
import { JsonFragment } from 'ethers';
import {
CompilationLanguage,
CompilationTarget,
Expand Down Expand Up @@ -109,7 +109,7 @@ export interface VerificationExport {
>;
};
contractCompilerOutput: {
abi?: Abi;
abi?: JsonFragment[];
userdoc?: Userdoc;
devdoc?: Devdoc;
storageLayout?: StorageLayout;
Expand Down
Loading