Skip to content

Commit c781086

Browse files
committed
chore: deprecate signature uploading
1 parent ae2ebd6 commit c781086

File tree

6 files changed

+22
-354
lines changed

6 files changed

+22
-354
lines changed

crates/cast/src/args.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ use foundry_common::{
1919
fmt::{format_tokens, format_uint_exp, serialize_value_as_json},
2020
fs,
2121
selectors::{
22-
ParsedSignatures, SelectorImportData, SelectorKind, decode_calldata, decode_event_topic,
23-
decode_function_selector, decode_selectors, import_selectors, parse_signatures,
24-
pretty_calldata,
22+
SelectorKind, decode_calldata, decode_event_topic, decode_function_selector,
23+
decode_selectors, pretty_calldata,
2524
},
2625
shell, stdin,
2726
};
@@ -594,15 +593,13 @@ pub async fn run_command(args: CastArgs) -> Result<()> {
594593
sh_println!("{sig}")?
595594
}
596595
}
597-
CastSubcommand::UploadSignature { signatures } => {
598-
let signatures = stdin::unwrap_vec(signatures)?;
599-
let ParsedSignatures { signatures, abis } = parse_signatures(signatures);
600-
if !abis.is_empty() {
601-
import_selectors(SelectorImportData::Abi(abis)).await?.describe();
602-
}
603-
if !signatures.is_empty() {
604-
import_selectors(SelectorImportData::Raw(signatures)).await?.describe();
605-
}
596+
CastSubcommand::UploadSignature { .. } => {
597+
sh_eprintln!(
598+
"Selector uploading is deprecated and is currently a no-op, as the upstream API has been removed."
599+
)?;
600+
sh_eprintln!(
601+
"To upload selectors in the future, verify your contracts with Sourcify."
602+
)?;
606603
}
607604

608605
// ENS

crates/cast/src/opts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ pub enum CastSubcommand {
742742
topic: Option<B256>,
743743
},
744744

745-
/// Upload the given signatures to <https://docs.sourcify.dev/docs/api/>.
745+
/// DEPRECATED: Upload the given signatures to <https://docs.sourcify.dev/docs/api/>.
746746
///
747747
/// Example inputs:
748748
/// - "transfer(address,uint256)"

crates/cast/tests/cli/selectors.rs

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use foundry_test_utils::util::OutputExt;
2-
use std::path::Path;
3-
41
casttest!(error_decode_with_sourcify, |prj, cmd| {
52
prj.clear_cache();
63
cmd.args(["decode-error", "0x7a0e198500000000000000000000000000000000000000000000000000000000000000650000000000000000000000000000000000000000000000000000000000000064"]).assert_success().stdout_eq(str![[r#"
@@ -14,6 +11,7 @@ ValueTooHigh(uint256,uint256)
1411
casttest!(fourbyte, |_prj, cmd| {
1512
cmd.args(["4byte", "0xa9059cbb"]).assert_success().stdout_eq(str![[r#"
1613
transfer(address,uint256)
14+
_____$_$__$___$$$___$$___$__$$(address,uint256)
1715
1816
"#]]);
1917
});
@@ -39,6 +37,7 @@ casttest!(fourbyte_calldata, |_prj, cmd| {
3937
casttest!(fourbyte_calldata_only_selector, |_prj, cmd| {
4038
cmd.args(["4byte-calldata", "0xa9059cbb"]).assert_success().stdout_eq(str![[r#"
4139
transfer(address,uint256)
40+
_____$_$__$___$$$___$$___$__$$(address,uint256)
4241
4342
"#]]);
4443
});
@@ -70,66 +69,6 @@ canCall(address,address,bytes4)
7069
"#]]);
7170
});
7271

73-
casttest!(upload_signatures, |_prj, cmd| {
74-
// test no prefix is accepted as function
75-
let output = cmd
76-
.args(["upload-signature", "transfer(address,uint256)"])
77-
.assert_success()
78-
.get_output()
79-
.stdout_lossy();
80-
assert!(output.contains("Function transfer(address,uint256): 0xa9059cbb"), "{}", output);
81-
82-
// test event prefix
83-
cmd.args(["upload-signature", "event Transfer(address,uint256)"]);
84-
let output = cmd.assert_success().get_output().stdout_lossy();
85-
assert!(output.contains("Event Transfer(address,uint256): 0x69ca02dd4edd7bf0a4abb9ed3b7af3f14778db5d61921c7dc7cd545266326de2"), "{}", output);
86-
87-
// test error prefix
88-
cmd.args(["upload-signature", "error ERC20InsufficientBalance(address,uint256,uint256)"]);
89-
let output = cmd.assert_success().get_output().stdout_lossy();
90-
assert!(
91-
output.contains("Function ERC20InsufficientBalance(address,uint256,uint256): 0xe450d38c"),
92-
"{}",
93-
output
94-
); // Custom error is interpreted as function
95-
96-
// test multiple sigs
97-
cmd.args([
98-
"upload-signature",
99-
"event Transfer(address,uint256)",
100-
"transfer(address,uint256)",
101-
"approve(address,uint256)",
102-
]);
103-
let output = cmd.assert_success().get_output().stdout_lossy();
104-
assert!(output.contains("Event Transfer(address,uint256): 0x69ca02dd4edd7bf0a4abb9ed3b7af3f14778db5d61921c7dc7cd545266326de2"), "{}", output);
105-
assert!(output.contains("Function transfer(address,uint256): 0xa9059cbb"), "{}", output);
106-
assert!(output.contains("Function approve(address,uint256): 0x095ea7b3"), "{}", output);
107-
108-
// test abi
109-
cmd.args([
110-
"upload-signature",
111-
"event Transfer(address,uint256)",
112-
"transfer(address,uint256)",
113-
"error ERC20InsufficientBalance(address,uint256,uint256)",
114-
Path::new(env!("CARGO_MANIFEST_DIR"))
115-
.join("tests/fixtures/ERC20Artifact.json")
116-
.as_os_str()
117-
.to_str()
118-
.unwrap(),
119-
]);
120-
let output = cmd.assert_success().get_output().stdout_lossy();
121-
assert!(output.contains("Event Transfer(address,uint256): 0x69ca02dd4edd7bf0a4abb9ed3b7af3f14778db5d61921c7dc7cd545266326de2"), "{}", output);
122-
assert!(output.contains("Function transfer(address,uint256): 0xa9059cbb"), "{}", output);
123-
assert!(output.contains("Function approve(address,uint256): 0x095ea7b3"), "{}", output);
124-
assert!(output.contains("Function decimals(): 0x313ce567"), "{}", output);
125-
assert!(output.contains("Function allowance(address,address): 0xdd62ed3e"), "{}", output);
126-
assert!(
127-
output.contains("Function ERC20InsufficientBalance(address,uint256,uint256): 0xe450d38c"),
128-
"{}",
129-
output
130-
);
131-
});
132-
13372
// tests cast can decode event with provided signature
13473
casttest!(event_decode_with_sig, |_prj, cmd| {
13574
cmd.args(["decode-event", "--sig", "MyEvent(uint256,address)", "0x000000000000000000000000000000000000000000000000000000000000004e0000000000000000000000000000000000000000000000000000000000d0004f"]).assert_success().stdout_eq(str![[r#"

crates/common/src/selectors.rs

Lines changed: 1 addition & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use alloy_json_abi::JsonAbi;
77
use alloy_primitives::{B256, Selector, map::HashMap};
88
use eyre::Context;
99
use itertools::Itertools;
10-
use serde::{Deserialize, Serialize, de::DeserializeOwned};
10+
use serde::{Deserialize, Serialize};
1111
use std::{
1212
fmt,
1313
sync::{
@@ -19,7 +19,6 @@ use std::{
1919

2020
const BASE_URL: &str = "https://sourcify.dev/server";
2121
const SELECTOR_LOOKUP_URL: &str = "https://sourcify.dev/server/signature-database/v1/lookup";
22-
const SELECTOR_IMPORT_URL: &str = "https://sourcify.dev/server/signature-database/v1/import";
2322

2423
/// The standard request timeout for API requests.
2524
const REQ_TIMEOUT: Duration = Duration::from_secs(15);
@@ -70,24 +69,6 @@ impl SourcifyClient {
7069
.inspect_err(|err| self.on_reqwest_err(err))
7170
}
7271

73-
/// Sends a new post request
74-
async fn post_json<T: Serialize + std::fmt::Debug, R: DeserializeOwned>(
75-
&self,
76-
url: &str,
77-
body: &T,
78-
) -> reqwest::Result<R> {
79-
trace!(%url, body=?serde_json::to_string(body), "POST");
80-
self.inner
81-
.post(url)
82-
.json(body)
83-
.send()
84-
.await
85-
.inspect_err(|err| self.on_reqwest_err(err))?
86-
.json()
87-
.await
88-
.inspect_err(|err| self.on_reqwest_err(err))
89-
}
90-
9172
fn on_reqwest_err(&self, err: &reqwest::Error) {
9273
fn is_connectivity_err(err: &reqwest::Error) -> bool {
9374
if err.is_timeout() || err.is_connect() {
@@ -280,42 +261,6 @@ impl SourcifyClient {
280261
}
281262
Ok(possible_info)
282263
}
283-
284-
/// uploads selectors to Sourcify using the given data
285-
pub async fn import_selectors(
286-
&self,
287-
data: SelectorImportData,
288-
) -> eyre::Result<SelectorImportResponse> {
289-
self.ensure_not_spurious()?;
290-
291-
let request = match data {
292-
SelectorImportData::Abi(abis) => {
293-
let functions_and_errors: SourcifySignatures = abis
294-
.iter()
295-
.flat_map(|abi| {
296-
abi.functions()
297-
.map(|func| func.signature())
298-
.chain(abi.errors().map(|error| error.signature()))
299-
.collect::<Vec<_>>()
300-
})
301-
.collect();
302-
303-
let events = abis
304-
.iter()
305-
.flat_map(|abi| abi.events().map(|event| event.signature()))
306-
.collect::<Vec<_>>();
307-
308-
SelectorImportRequest { function: functions_and_errors, event: events }
309-
}
310-
SelectorImportData::Raw(raw) => {
311-
let function_and_error =
312-
raw.function.iter().chain(raw.error.iter()).cloned().collect::<Vec<_>>();
313-
SelectorImportRequest { function: function_and_error, event: raw.event }
314-
}
315-
};
316-
317-
Ok(self.post_json(SELECTOR_IMPORT_URL, &request).await?)
318-
}
319264
}
320265

321266
pub enum SelectorOrSig {
@@ -447,61 +392,6 @@ impl RawSelectorImportData {
447392
}
448393
}
449394

450-
#[derive(Serialize)]
451-
#[serde(untagged)]
452-
pub enum SelectorImportData {
453-
Abi(Vec<JsonAbi>),
454-
Raw(RawSelectorImportData),
455-
}
456-
457-
#[derive(Debug, Default, Serialize)]
458-
struct SelectorImportRequest {
459-
function: SourcifySignatures,
460-
event: SourcifySignatures,
461-
}
462-
463-
#[derive(Debug, Deserialize)]
464-
struct SelectorImportEffect {
465-
imported: HashMap<String, String>,
466-
duplicated: HashMap<String, String>,
467-
}
468-
469-
#[derive(Debug, Deserialize)]
470-
struct SelectorImportResult {
471-
function: SelectorImportEffect,
472-
event: SelectorImportEffect,
473-
}
474-
475-
#[derive(Debug, Deserialize)]
476-
pub struct SelectorImportResponse {
477-
result: SelectorImportResult,
478-
}
479-
480-
impl SelectorImportResponse {
481-
/// Print info about the functions which were uploaded or already known
482-
pub fn describe(&self) {
483-
self.result.function.imported.iter().for_each(|(k, v)| {
484-
let _ = sh_println!("Imported: Function {k}: {v}");
485-
});
486-
self.result.event.imported.iter().for_each(|(k, v)| {
487-
let _ = sh_println!("Imported: Event {k}: {v}");
488-
});
489-
self.result.function.duplicated.iter().for_each(|(k, v)| {
490-
let _ = sh_println!("Duplicated: Function {k}: {v}");
491-
});
492-
self.result.event.duplicated.iter().for_each(|(k, v)| {
493-
let _ = sh_println!("Duplicated: Event {k}: {v}");
494-
});
495-
496-
let _ = sh_println!("Selectors successfully uploaded to Sourcify");
497-
}
498-
}
499-
500-
/// uploads selectors to Sourcify using the given data
501-
pub async fn import_selectors(data: SelectorImportData) -> eyre::Result<SelectorImportResponse> {
502-
SourcifyClient::new()?.import_selectors(data).await
503-
}
504-
505395
#[derive(Debug, Default, PartialEq, Eq)]
506396
pub struct ParsedSignatures {
507397
pub signatures: RawSelectorImportData,

crates/forge/src/cmd/selectors.rs

Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use foundry_cli::{
77
utils::{FoundryPathExt, cache_local_signatures},
88
};
99
use foundry_common::{
10-
compile::{PathOrContractInfo, ProjectCompiler, compile_target},
11-
selectors::{SelectorImportData, import_selectors},
10+
compile::{PathOrContractInfo, ProjectCompiler},
1211
shell,
1312
};
1413
use foundry_compilers::{artifacts::output_selection::ContractOutputSelection, info::ContractInfo};
@@ -32,7 +31,7 @@ pub enum SelectorsSubcommands {
3231
build: Box<BuildOpts>,
3332
},
3433

35-
/// Upload selectors to registry
34+
/// DEPRECATED: Upload selectors to registry
3635
#[command(visible_alias = "up")]
3736
Upload {
3837
/// The name of the contract to upload selectors for.
@@ -100,77 +99,13 @@ impl SelectorsSubcommands {
10099
let outcome = ProjectCompiler::new().quiet(true).compile(&project)?;
101100
cache_local_signatures(&outcome)?;
102101
}
103-
Self::Upload { contract, all, project_paths } => {
104-
let build_args = BuildOpts {
105-
project_paths: project_paths.clone(),
106-
compiler: CompilerOpts {
107-
extra_output: vec![ContractOutputSelection::Abi],
108-
..Default::default()
109-
},
110-
..Default::default()
111-
};
112-
113-
let project = build_args.project()?;
114-
let output = if let Some(contract_info) = &contract {
115-
let Some(contract_name) = contract_info.name() else {
116-
eyre::bail!("No contract name provided.")
117-
};
118-
119-
let target_path = contract_info
120-
.path()
121-
.map(Ok)
122-
.unwrap_or_else(|| project.find_contract_path(contract_name))?;
123-
compile_target(&target_path, &project, false)?
124-
} else {
125-
ProjectCompiler::new().compile(&project)?
126-
};
127-
let artifacts = if all {
128-
output
129-
.into_artifacts_with_files()
130-
.filter(|(file, _, _)| {
131-
let is_sources_path = file.starts_with(&project.paths.sources);
132-
let is_test = file.is_sol_test();
133-
134-
is_sources_path && !is_test
135-
})
136-
.map(|(_, contract, artifact)| (contract, artifact))
137-
.collect()
138-
} else {
139-
let contract_info = contract.unwrap();
140-
let contract = contract_info.name().unwrap().to_string();
141-
142-
let found_artifact = if let Some(path) = contract_info.path() {
143-
output.find(project.root().join(path).as_path(), &contract)
144-
} else {
145-
output.find_first(&contract)
146-
};
147-
148-
let artifact = found_artifact
149-
.ok_or_else(|| {
150-
eyre::eyre!(
151-
"Could not find artifact `{contract}` in the compiled artifacts"
152-
)
153-
})?
154-
.clone();
155-
vec![(contract, artifact)]
156-
};
157-
158-
let mut artifacts = artifacts.into_iter().peekable();
159-
while let Some((contract, artifact)) = artifacts.next() {
160-
let abi = artifact.abi.ok_or_else(|| eyre::eyre!("Unable to fetch abi"))?;
161-
if abi.functions.is_empty() && abi.events.is_empty() && abi.errors.is_empty() {
162-
continue;
163-
}
164-
165-
sh_println!("Uploading selectors for {contract}...")?;
166-
167-
// upload abi to selector database
168-
import_selectors(SelectorImportData::Abi(vec![abi])).await?.describe();
169-
170-
if artifacts.peek().is_some() {
171-
sh_println!()?
172-
}
173-
}
102+
Self::Upload { .. } => {
103+
sh_eprintln!(
104+
"Selector uploading is deprecated and is currently a no-op, as the upstream API has been removed."
105+
)?;
106+
sh_eprintln!(
107+
"To upload selectors in the future, verify your contracts with Sourcify."
108+
)?;
174109
}
175110
Self::Collision { mut first_contract, mut second_contract, build } => {
176111
// Compile the project with the two contracts included

0 commit comments

Comments
 (0)