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

Quick Release #986

Merged
merged 3 commits into from
Apr 19, 2023
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
1 change: 0 additions & 1 deletion packages/lib-sourcify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export async function verifyDeployed(
checkedContract: CheckedContract,
sourcifyChain: SourcifyChain,
address: string,
contextVariables?: ContextVariables,
creatorTxHash?: string
): Promise<Match>;
```
Expand Down
6 changes: 3 additions & 3 deletions packages/lib-sourcify/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface Match {
abiEncodedConstructorArguments?: string;
create2Args?: Create2Args;
libraryMap?: StringMap;
contextVariables?: ContextVariables;
/* contextVariables?: ContextVariables; */
creatorTxHash?: string;
immutableReferences?: ImmutableReferences;
}
Expand Down Expand Up @@ -135,10 +135,10 @@ type Currency = {
decimals: number;
};

export type ContextVariables = {
/* export type ContextVariables = {
abiEncodedConstructorArguments?: string;
msgSender?: string;
};
}; */

interface File {
keccak256?: string;
Expand Down
17 changes: 12 additions & 5 deletions packages/lib-sourcify/src/lib/verification.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CheckedContract } from './CheckedContract';
import {
ContextVariables,
/* ContextVariables, */
Create2Args,
ImmutableReferences,
Match,
Expand All @@ -14,12 +14,14 @@ import {
decode as bytecodeDecode,
splitAuxdata,
} from '@ethereum-sourcify/bytecode-utils';
/*
import { EVM } from '@ethereumjs/evm';
import { EEI } from '@ethereumjs/vm';
import { Address } from '@ethereumjs/util';
import { Common } from '@ethereumjs/common';
import { DefaultStateManager } from '@ethereumjs/statemanager';
import { Blockchain } from '@ethereumjs/blockchain';
*/
import { hexZeroPad, isHexString } from '@ethersproject/bytes';
import { BigNumber } from '@ethersproject/bignumber';
import { getAddress, getContractAddress } from '@ethersproject/address';
Expand All @@ -31,7 +33,7 @@ export async function verifyDeployed(
checkedContract: CheckedContract,
sourcifyChain: SourcifyChain,
address: string,
contextVariables?: ContextVariables,
/* _contextVariables?: ContextVariables, */
creatorTxHash?: string
): Promise<Match> {
const match: Match = {
Expand Down Expand Up @@ -62,6 +64,7 @@ export async function verifyDeployed(
if (match.status) return match;

// Try to match with simulating the creation bytecode
/*
await matchWithSimulation(
match,
recompiled.creationBytecode,
Expand All @@ -74,6 +77,7 @@ export async function verifyDeployed(
match.contextVariables = contextVariables;
return match;
}
*/

// Try to match with creationTx, if available
if (creatorTxHash) {
Expand Down Expand Up @@ -193,6 +197,7 @@ export function matchWithDeployedBytecode(
}
}

/*
export async function matchWithSimulation(
match: Match,
recompiledCreaionBytecode: string,
Expand Down Expand Up @@ -234,7 +239,7 @@ export async function matchWithSimulation(
data: initcode,
gasLimit: BigInt(0xffffffffff),
// prettier vs. eslint indentation conflict here
/* eslint-disable indent */
// eslint-disable indent
caller: msgSender
? new Address(
Buffer.from(
Expand All @@ -243,7 +248,7 @@ export async function matchWithSimulation(
)
)
: undefined,
/* eslint-enable indent */
// eslint-disable indent
});
const simulationDeployedBytecode =
'0x' + result.execResult.returnValue.toString('hex');
Expand All @@ -253,7 +258,9 @@ export async function matchWithSimulation(
simulationDeployedBytecode,
deployedBytecode
);
}
}
*/

/**
* Matches the contract via the transaction that created the contract, if that tx is known.
* Checks if the tx.input matches the recompiled creation bytecode. Double checks that the contract address matches the address being verified.
Expand Down
10 changes: 7 additions & 3 deletions packages/lib-sourcify/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import path from 'path';
import Web3 from 'web3';
import fs from 'fs';
import { ContextVariables, Match, SourcifyChain, verifyDeployed } from '../src';
import {
/* ContextVariables, */ Match,
SourcifyChain,
verifyDeployed,
} from '../src';
import { checkFiles } from '../src';
import { expect } from 'chai';

Expand Down Expand Up @@ -76,7 +80,7 @@ export const checkAndVerifyDeployed = async (
contractFolderPath: string,
sourcifyChain: SourcifyChain,
address: string,
contextVariables?: ContextVariables,
/* contextVariables?: ContextVariables, */
creatorTxHash?: string
) => {
const checkedContracts = await checkFilesFromContractFolder(
Expand All @@ -87,7 +91,7 @@ export const checkAndVerifyDeployed = async (
checkedContracts[0],
sourcifyChain,
address,
contextVariables,
/* contextVariables, */
creatorTxHash
);
return match;
Expand Down
15 changes: 10 additions & 5 deletions packages/lib-sourcify/test/verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SourcifyChain } from '../src/lib/types';
import Web3 from 'web3';
import Ganache from 'ganache';
import {
callContractMethodWithTx,
/* callContractMethodWithTx, */
checkAndVerifyDeployed,
checkFilesFromContractFolder,
deployCheckAndVerify,
Expand All @@ -15,13 +15,15 @@ import { describe, it, before } from 'mocha';
import { expect } from 'chai';
import {
calculateCreate2Address,
/*
getBytecode,
matchWithSimulation,
*/
matchWithCreationTx,
replaceImmutableReferences,
verifyCreate2,
} from '../src';
import { Match } from '@ethereum-sourcify/lib-sourcify';
// import { Match } from '@ethereum-sourcify/lib-sourcify';

const ganacheServer = Ganache.server({
wallet: { totalAccounts: 1 },
Expand Down Expand Up @@ -253,7 +255,7 @@ describe('lib-sourcify tests', () => {
expectMatch(match, 'perfect', deployedAddress);
});

it('should verify a contract created by a factory contract and has immutables', async () => {
/* it('should verify a contract created by a factory contract and has immutables', async () => {
const deployValue = 12345;
const childFolderPath = path.join(
__dirname,
Expand Down Expand Up @@ -298,9 +300,9 @@ describe('lib-sourcify tests', () => {
);

expectMatch(match, 'perfect', childAddress);
});
}); */

it('should verify a contract created by a factory contract and has immutables without constructor arguments but with msg.sender assigned immutable', async () => {
/* it('should verify a contract created by a factory contract and has immutables without constructor arguments but with msg.sender assigned immutable', async () => {
const childFolderPath = path.join(
__dirname,
'sources',
Expand Down Expand Up @@ -341,6 +343,7 @@ describe('lib-sourcify tests', () => {

expectMatch(match, 'perfect', childAddress);
});
*/
});

describe('Unit tests', function () {
Expand Down Expand Up @@ -377,6 +380,7 @@ describe('lib-sourcify tests', () => {
expect(replacedBytecode).equals(recompiledDeployedBytecode);
});

/*
it('should matchWithSimulation', async () => {
const childFolderPath = path.join(
__dirname,
Expand Down Expand Up @@ -436,6 +440,7 @@ describe('lib-sourcify tests', () => {

expectMatch(match, 'perfect', childAddress);
});
*/

it('should fail to matchWithCreationTx with wrong creationTxHash', async () => {
const contractFolderPath = path.join(
Expand Down
2 changes: 1 addition & 1 deletion src/monitor/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class ChainMonitor extends EventEmitter {
contract,
this.chainId,
address,
undefined,
/* undefined, */
creatorTxHash
);
await this.repositoryService.storeMatch(contract, match);
Expand Down
22 changes: 13 additions & 9 deletions src/server/controllers/VerificationController-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export type LegacyVerifyRequest = Request & {
addresses: string[];
chain: string;
chosenContract: number;
contextVariables?: {
/* contextVariables?: {
abiEncodedConstructorArguments?: string;
msgSender?: string;
};
}; */
};

type PathBuffer = {
Expand Down Expand Up @@ -158,10 +158,10 @@ export type ContractMeta = {
name?: string;
address?: string;
chainId?: string;
contextVariables?: {
/* contextVariables?: {
abiEncodedConstructorArguments?: string;
msgSender?: string;
};
}; */
creatorTxHash?: string;
status?: Status;
statusMessage?: string;
Expand Down Expand Up @@ -388,8 +388,12 @@ export const verifyContractsInSession = async (
continue;
}

const { address, chainId, contract, contextVariables, creatorTxHash } =
contractWrapper;
const {
address,
chainId,
contract,
/* contextVariables, */ creatorTxHash,
} = contractWrapper;

// The session saves the CheckedContract as a simple object, so we need to reinstantiate it
const checkedContract = new CheckedContract(
Expand All @@ -412,7 +416,7 @@ export const verifyContractsInSession = async (
checkedContract,
chainId as string,
address as string,
contextVariables,
/* contextVariables, */
creatorTxHash
);
// Send to verification again with all source files.
Expand All @@ -431,8 +435,8 @@ export const verifyContractsInSession = async (
const tempMatch = await verificationService.verifyDeployed(
contractWithAllSources,
chainId as string,
address as string,
contextVariables
address as string
/* contextVariables */
);
if (
tempMatch.status === "perfect" ||
Expand Down
14 changes: 7 additions & 7 deletions src/server/controllers/VerificationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class VerificationController
contract,
req.body.chain,
req.addresses[0], // Due to the old API taking an array of addresses.
req.body.contextVariables,
/* req.body.contextVariables, */
req.body.creatorTxHash
);
// Send to verification again with all source files.
Expand All @@ -145,7 +145,7 @@ export default class VerificationController
contractWithAllSources,
req.body.chain,
req.addresses[0], // Due to the old API taking an array of addresses.
req.body.contextVariables,
/* req.body.contextVariables, */
req.body.creatorTxHash
);
if (tempMatch.status === "perfect") {
Expand Down Expand Up @@ -231,7 +231,7 @@ export default class VerificationController
if (contractWrapper) {
contractWrapper.address = receivedContract.address;
contractWrapper.chainId = receivedContract.chainId;
contractWrapper.contextVariables = receivedContract.contextVariables;
/* contractWrapper.contextVariables = receivedContract.contextVariables; */
contractWrapper.creatorTxHash = receivedContract.creatorTxHash;
if (isVerifiable(contractWrapper)) {
verifiable[id] = contractWrapper;
Expand Down Expand Up @@ -550,10 +550,10 @@ export default class VerificationController
.exists()
.bail()
.custom((chain, { req }) => (req.chain = checkChainId(chain))),
body("contextVariables.msgSender").optional(),
body("contextVariables.abiEncodedConstructorArguments").optional(),
/* body("contextVariables.msgSender").optional(),
body("contextVariables.abiEncodedConstructorArguments").optional(), */
// Handle non-json multipart/form-data requests.
body("abiEncodedConstructorArguments")
/* body("abiEncodedConstructorArguments")
.optional()
.custom(
(abiEncodedConstructorArguments, { req }) =>
Expand All @@ -570,7 +570,7 @@ export default class VerificationController
msgSender,
...req.body.contextVariables,
})
),
), */
body("creatorTxHash")
.optional()
.custom(
Expand Down
6 changes: 3 additions & 3 deletions src/server/services/RepositoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Create2Args,
StringMap,
Metadata,
ContextVariables,
/* ContextVariables, */
CheckedContract,
} from "@ethereum-sourcify/lib-sourcify";
import { toChecksumAddress } from "web3-utils";
Expand Down Expand Up @@ -424,7 +424,7 @@ export default class RepositoryService implements IRepositoryService {
);
}

if (
/* if (
match.contextVariables &&
Object.keys(match.contextVariables).length > 0
) {
Expand All @@ -435,7 +435,7 @@ export default class RepositoryService implements IRepositoryService {
"context-variables.json",
match.contextVariables
);
}
} */

if (match.creatorTxHash) {
this.storeTxt(
Expand Down
Loading