Skip to content

Commit

Permalink
Add lookup_methods endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lok52 committed Nov 6, 2023
1 parent e5bb729 commit ef4a2fd
Show file tree
Hide file tree
Showing 16 changed files with 763 additions and 92 deletions.
197 changes: 161 additions & 36 deletions smart-contract-verifier/Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ http:
- selector: blockscout.smartContractVerifier.v2.SolidityVerifier.ListCompilerVersions
get: /api/v2/verifier/solidity/versions

- selector: blockscout.smartContractVerifier.v2.SolidityVerifier.LookupMethods
post: /api/v2/verifier/solidity/lookup-methods
body: "*"


#################### Vyper Verifier ####################

- selector: blockscout.smartContractVerifier.v2.VyperVerifier.VerifyMultiPart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ service SolidityVerifier {
rpc VerifyStandardJson(VerifySolidityStandardJsonRequest) returns (VerifyResponse) {}

rpc ListCompilerVersions(ListCompilerVersionsRequest) returns (ListCompilerVersionsResponse) {}

rpc LookupMethods(LookupMethodsRequest) returns (LookupMethodsResponse) {}
}

service VyperVerifier {
Expand Down Expand Up @@ -218,3 +220,19 @@ message ListCompilerVersionsResponse {
/// Compiler versions available
repeated string compiler_versions = 1;
}

message LookupMethodsRequest {
string bytecode = 1;
string abi = 2;
string source_map = 3;
map<uint32, string> file_id_map = 4;
}

message LookupMethodsResponse {
message Method {
string file_name = 1;
int32 file_offset = 2;
int32 length = 3;
}
map<string, Method> methods = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ consumes:
produces:
- application/json
paths:
/api/v2/verifier/solidity/lookup-methods:
post:
operationId: SolidityVerifier_LookupMethods
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v2LookupMethodsResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: body
in: body
required: true
schema:
$ref: '#/definitions/v2LookupMethodsRequest'
tags:
- SolidityVerifier
/api/v2/verifier/solidity/sources:verify-multi-part:
post:
operationId: SolidityVerifier_VerifyMultiPart
Expand Down Expand Up @@ -186,10 +206,10 @@ definitions:
ExtraDataBytecodePart:
type: object
properties:
data:
type: string
type:
type: string
data:
type: string
HealthCheckResponseServingStatus:
type: string
enum:
Expand All @@ -198,6 +218,18 @@ definitions:
- NOT_SERVING
- SERVICE_UNKNOWN
default: UNKNOWN
description: ' - SERVICE_UNKNOWN: Used only by the Watch method.'
LookupMethodsResponseMethod:
type: object
properties:
fileName:
type: string
fileOffset:
type: integer
format: int32
length:
type: integer
format: int32
SourceMatchType:
type: string
enum:
Expand Down Expand Up @@ -238,12 +270,12 @@ definitions:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
$ref: '#/definitions/protobufAny'
message:
type: string
protobufAny:
type: object
properties:
Expand All @@ -270,53 +302,73 @@ definitions:
items:
type: string
title: / Compiler versions available
v2Source:
v2LookupMethodsRequest:
type: object
properties:
bytecode:
type: string
abi:
type: string
title: |-
/ Contract abi (https://docs.soliditylang.org/en/latest/abi-spec.html?highlight=abi#json);
/ (does not exist for Yul contracts)
compilationArtifacts:
sourceMap:
type: string
description: |-
/ General and compiler-specific artifacts (abi, userdoc, devdoc, licenses, ast, etc),
/ encoded as a json.
fileIdMap:
type: object
additionalProperties:
type: string
v2LookupMethodsResponse:
type: object
properties:
methods:
type: object
additionalProperties:
$ref: '#/definitions/LookupMethodsResponseMethod'
v2Source:
type: object
properties:
fileName:
type: string
title: / The name of the file verified contract was located at
contractName:
type: string
title: / The name of the contract which was verified
compilerVersion:
type: string
title: Compiler version used to compile the contract
compilerSettings:
type: string
title: |-
/ 'settings' key in Standard Input JSON
/ (https://docs.soliditylang.org/en/latest/using-the-compiler.html#input-description)
compilerVersion:
sourceType:
$ref: '#/definitions/SourceSourceType'
sourceFiles:
type: object
additionalProperties:
type: string
abi:
type: string
title: Compiler version used to compile the contract
title: |-
/ Contract abi (https://docs.soliditylang.org/en/latest/abi-spec.html?highlight=abi#json);
/ (does not exist for Yul contracts)
constructorArguments:
type: string
title: |-
/ Constructor arguments used for deploying verified contract
/ (exists only for creation inputs)
contractName:
matchType:
$ref: '#/definitions/SourceMatchType'
title: / Similar to Sourcify (see https://docs.sourcify.dev/docs/full-vs-partial-match/)
compilationArtifacts:
type: string
title: / The name of the contract which was verified
description: |-
/ General and compiler-specific artifacts (abi, userdoc, devdoc, licenses, ast, etc),
/ encoded as a json.
creationInputArtifacts:
type: string
description: / Info about the creation code (sourcemaps, linkreferences) encoded as a json.
deployedBytecodeArtifacts:
type: string
description: / Info about the runtime code (sourcemaps, linkreferences, immutables) encoded as a json.
fileName:
type: string
title: / The name of the file verified contract was located at
matchType:
$ref: '#/definitions/SourceMatchType'
title: / Similar to Sourcify (see https://docs.sourcify.dev/docs/full-vs-partial-match/)
sourceFiles:
type: object
additionalProperties:
type: string
sourceType:
$ref: '#/definitions/SourceSourceType'
v2VerificationMetadata:
type: object
properties:
Expand All @@ -340,14 +392,14 @@ definitions:
v2VerifyResponse:
type: object
properties:
extraData:
$ref: '#/definitions/VerifyResponseExtraData'
message:
type: string
source:
$ref: '#/definitions/v2Source'
status:
$ref: '#/definitions/v2VerifyResponseStatus'
source:
$ref: '#/definitions/v2Source'
extraData:
$ref: '#/definitions/VerifyResponseExtraData'
v2VerifyResponseStatus:
type: string
enum:
Expand All @@ -370,14 +422,6 @@ definitions:
evmVersion:
type: string
title: / Version of the EVM to compile for. If absent results in default EVM version
libraries:
type: object
additionalProperties:
type: string
title: / Map from a library name to its address
metadata:
$ref: '#/definitions/v2VerificationMetadata'
title: / An optional field to be filled by explorers
optimizationRuns:
type: integer
format: int32
Expand All @@ -389,6 +433,14 @@ definitions:
additionalProperties:
type: string
title: / Map from a source file name to the actual source code
libraries:
type: object
additionalProperties:
type: string
title: / Map from a library name to its address
metadata:
$ref: '#/definitions/v2VerificationMetadata'
title: / An optional field to be filled by explorers
v2VerifySolidityStandardJsonRequest:
type: object
properties:
Expand Down Expand Up @@ -418,10 +470,6 @@ definitions:
title: |-
/ The chain (network) the contract was deployed to
/ (https://docs.sourcify.dev/docs/api/chains/)
chosenContract:
type: integer
format: int32
title: (optional) see Sourcify Api
files:
type: object
additionalProperties:
Expand All @@ -430,6 +478,10 @@ definitions:
/ Files required for verification (see Sourcify Api)
Is named as `files` instead of `source_files`
to correspond with Sourcify api
chosenContract:
type: integer
format: int32
title: (optional) see Sourcify Api
v2VerifyVyperMultiPartRequest:
type: object
properties:
Expand All @@ -445,6 +497,11 @@ definitions:
evmVersion:
type: string
title: / Version of the EVM to compile for. If absent results in default EVM version
sourceFiles:
type: object
additionalProperties:
type: string
title: / Map from a source file name to the actual source code
interfaces:
type: object
additionalProperties:
Expand All @@ -455,11 +512,6 @@ definitions:
metadata:
$ref: '#/definitions/v2VerificationMetadata'
title: / An optional field to be filled by explorers
sourceFiles:
type: object
additionalProperties:
type: string
title: / Map from a source file name to the actual source code
v2VerifyVyperStandardJsonRequest:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sig-provider-extension = { path = "../sig-provider-extension", optional = true }

actix-web = "4"
actix-web-prom = "0.6"
amplify = { version = "3.13.0", features = ["derive"] }
anyhow = "1.0"
async-trait = "0.1"
blockscout-display-bytes = { version = "1.0" }
Expand All @@ -20,6 +21,7 @@ bytes = "1.3"
config = "0.13"
cron = "0.11"
ethers-solc = "2.0.6"
ethers-core = "2.0.10"
futures = "0.3"
lazy_static = "1"
opentelemetry = { version = "0.18", features = ["rt-tokio"] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pub use smart_contract_verifier_proto::blockscout::smart_contract_verifier::v2::{
health_actix, health_check_response, health_server, solidity_verifier_actix,
solidity_verifier_server, source, sourcify_verifier_actix, sourcify_verifier_server,
verify_response, vyper_verifier_actix, vyper_verifier_server, BytecodeType, HealthCheckRequest,
HealthCheckResponse, ListCompilerVersionsRequest, ListCompilerVersionsResponse, Source,
health_actix, health_check_response, health_server, lookup_methods_response,
solidity_verifier_actix, solidity_verifier_server, source, sourcify_verifier_actix,
sourcify_verifier_server, verify_response, vyper_verifier_actix, vyper_verifier_server,
BytecodeType, HealthCheckRequest, HealthCheckResponse, ListCompilerVersionsRequest,
ListCompilerVersionsResponse, LookupMethodsRequest, LookupMethodsResponse, Source,
VerificationMetadata, VerifyFromEtherscanSourcifyRequest, VerifyResponse,
VerifySolidityMultiPartRequest, VerifySolidityStandardJsonRequest, VerifySourcifyRequest,
VerifyVyperMultiPartRequest, VerifyVyperStandardJsonRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ use crate::{
},
settings::{Extensions, FetcherSettings, S3FetcherSettings, SoliditySettings},
types::{
StandardJsonParseError, VerifyResponseWrapper, VerifySolidityMultiPartRequestWrapper,
LookupMethodsRequestWrapper, LookupMethodsResponseWrapper, StandardJsonParseError,
VerifyResponseWrapper, VerifySolidityMultiPartRequestWrapper,
VerifySolidityStandardJsonRequestWrapper,
},
};
use s3::{creds::Credentials, Bucket, Region};
use smart_contract_verifier::{
solidity, Compilers, Fetcher, ListFetcher, S3Fetcher, SolcValidator, SolidityClient,
SolidityCompiler, VerificationError,
find_methods, solidity, Compilers, Fetcher, ListFetcher, S3Fetcher, SolcValidator,
SolidityClient, SolidityCompiler, VerificationError,
};
use smart_contract_verifier_proto::blockscout::smart_contract_verifier::v2::{
LookupMethodsRequest, LookupMethodsResponse,
};
use std::{str::FromStr, sync::Arc};
use tokio::sync::Semaphore;
Expand Down Expand Up @@ -184,6 +188,17 @@ impl SolidityVerifier for SolidityVerifierService {
compiler_versions,
}))
}

async fn lookup_methods(
&self,
request: Request<LookupMethodsRequest>,
) -> Result<Response<LookupMethodsResponse>, Status> {
let r: LookupMethodsRequestWrapper = request.into_inner().into();
let methods = find_methods(r.try_into()?);
println!("methods: {:?}", methods.methods);
let response = LookupMethodsResponseWrapper::from(methods);
Ok(Response::new(response.into()))
}
}

fn new_region(region: Option<String>, endpoint: Option<String>) -> Option<Region> {
Expand Down
Loading

0 comments on commit ef4a2fd

Please sign in to comment.