@nomicfoundation/hardhat-verify
Version:
Hardhat plugin for verifying contracts
57 lines • 2.41 kB
TypeScript
import type { SemverVersion } from "@nomicfoundation/hardhat-utils/fast-semver";
export declare const METADATA_LENGTH_FIELD_SIZE = 2;
/**
* The Solidity compiler version inferred from a contract's deployed bytecode.
*
* Bytecode metadata was introduced in Solidity v0.4.7, and the explicit
* version field was added in v0.5.9. Below those thresholds we can only
* narrow the version down to a range.
*/
export type InferredSolcVersion = {
type: "exact";
version: SemverVersion;
} | {
type: "lessThan";
bound: SemverVersion;
} | {
type: "between";
min: SemverVersion;
max: SemverVersion;
};
/**
* Attempts to infer the Solidity compiler version from the bytecode metadata.
*
* - Metadata was introduced in Solidity v0.4.7.
* See: https://docs.soliditylang.org/en/v0.4.7/miscellaneous.html#contract-metadata
* - The version field was first added in v0.5.9.
* See https://docs.soliditylang.org/en/v0.5.9/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode
*
* @param bytecode The deployed bytecode as a Uint8Array.
* @returns The inferred solc version, either as an exact `x.y.z` or, when
* the metadata is missing or incomplete, as a fallback range.
*/
export declare function inferSolcVersion(bytecode: Uint8Array): Promise<InferredSolcVersion>;
/**
* Formats an `InferredSolcVersion` as a human-readable string suitable for
* inclusion in error messages: an exact `x.y.z`, a `<x.y.z` upper bound, or
* an `x.y.z - x.y.z` closed range.
*/
export declare function formatInferredSolcVersion(v: InferredSolcVersion): string;
/**
* Reads the Solidity metadata section length from the end of the contract
* bytecode.
*
* Solidity appends metadata to the end of the deployed bytecode.
* The final 2 bytes (defined by METADATA_LENGTH) encode the length of the
* metadata section, using a big-endian unsigned 16-bit integer.
* See https://docs.soliditylang.org/en/latest/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode
*
* This function uses a DataView to read those final 2 bytes, and returns the
* total length of the metadata section (payload + length field).
*
* @param bytecode The bytecode as an Uint8Array.
* @returns The total length (in bytes) of the metadata section at the end of
* the bytecode.
*/
export declare function getMetadataSectionBytesLength(bytecode: Uint8Array): number;
//# sourceMappingURL=metadata.d.ts.map