From a53328c6fc4e3130adf2974ec0e73e0c4f09e7dc Mon Sep 17 00:00:00 2001 From: willco-1 Date: Wed, 23 Oct 2024 15:55:47 -0400 Subject: [PATCH 1/9] wip: poc compute selectors --- crates/ast/src/util.rs | 89 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/crates/ast/src/util.rs b/crates/ast/src/util.rs index 126d98c..46242fb 100644 --- a/crates/ast/src/util.rs +++ b/crates/ast/src/util.rs @@ -1,5 +1,8 @@ -use alloy_primitives::U256; +use alloy_primitives::{U256,FixedBytes, keccak256}; +use crate::Spanned; +use alloy_dyn_abi::DynSolType; use evm_glue::opcodes::Opcode; +use crate::ast::{SolError, SolFunction}; pub(crate) fn u256_as_push_data(value: U256) -> Result<[u8; N], String> { if value.byte_len() > N { @@ -53,3 +56,87 @@ pub fn u256_as_push(value: U256) -> Opcode { _ => unreachable!(), } } +type Selector = (FixedBytes<4>, FixedBytes<4>); + + +pub fn build_signature(func_name: &Spanned<&str>, args: &Box<[Spanned]>) -> Vec { + let mut arg_types = Vec::new(); + + + for arg in args.iter() { + let arg_type = match arg.0 { + DynSolType::Address => "address", + DynSolType::Uint(_) => "uint256", + DynSolType::String => "string", + _ => panic!("Unsupported type: {:?}", arg.0), + }; + arg_types.push(arg_type); + } + + // Build the signature using a String + let mut signature = String::new(); + signature.push_str(func_name.0); + signature.push('('); + signature.push_str(&arg_types.join(",")); + signature.push(')'); + + // Convert the signature String to Vec + signature.into_bytes() +} + + + +pub fn compute_selector(func: SolFunction, err: SolError) -> Option { + let func_signature = build_signature(&func.name, &func.args); + let err_signature = build_signature(&err.name, &err.args); + + let func_hash = keccak256(func_signature); + let err_hash = keccak256(err_signature); + + + let func_selector: FixedBytes<4> = FixedBytes::from_slice(&func_hash[..4]); + let err_selector: FixedBytes<4> = FixedBytes::from_slice(&err_hash[..4]); + + Some((func_selector, err_selector)) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::ast::*; + use alloy_primitives::keccak256; + use alloy_dyn_abi::DynSolType; + use chumsky::span::Span; + + + + + #[test] + fn test_compute_selector() { + let func = SolFunction { + name: Spanned::new("transfer", 0..8), + args: Box::new([ + Spanned::new(DynSolType::Address, 9..17), + Spanned::new(DynSolType::Uint(256), 18..26), + ]), + rets: Box::new([]), + }; + let err = SolError { + name: Spanned::new("TransferFailed", 0..15), + args: Box::new([ + Spanned::new(DynSolType::String, 16..21), + Spanned::new(DynSolType::Uint(256), 22..30), + ]), + }; + let selectors = compute_selector(func.clone(), err.clone()).unwrap(); + let func_signature = build_signature(&Spanned::new("transfer", 0..8), &func.args); + let err_signature = build_signature(&Spanned::new("TransferFailed", 0..15), &err.args); + let expected_func_hash = keccak256(func_signature.clone()); + let expected_err_hash = keccak256(err_signature.clone()); + //println!("{}", &selectors); + let expected_func_selector: Selector = (FixedBytes::from_slice(&expected_func_hash[..4]), FixedBytes::from_slice(&expected_err_hash[..4])); + assert_eq!(selectors.0, expected_func_selector.0); + assert_eq!(selectors.1, expected_func_selector.1); + } +} + From fd514e1890e5345f45ca0034b2ac9a15e50bb199 Mon Sep 17 00:00:00 2001 From: willco-1 Date: Thu, 24 Oct 2024 13:05:21 -0400 Subject: [PATCH 2/9] refactor: compute selectors #6 --- crates/ast/src/util.rs | 88 +++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 48 deletions(-) diff --git a/crates/ast/src/util.rs b/crates/ast/src/util.rs index 46242fb..09fad43 100644 --- a/crates/ast/src/util.rs +++ b/crates/ast/src/util.rs @@ -1,8 +1,8 @@ -use alloy_primitives::{U256,FixedBytes, keccak256}; +use crate::ast::{SolError, SolFunction}; use crate::Spanned; use alloy_dyn_abi::DynSolType; +use alloy_primitives::{keccak256, FixedBytes, U256}; use evm_glue::opcodes::Opcode; -use crate::ast::{SolError, SolFunction}; pub(crate) fn u256_as_push_data(value: U256) -> Result<[u8; N], String> { if value.byte_len() > N { @@ -56,46 +56,41 @@ pub fn u256_as_push(value: U256) -> Opcode { _ => unreachable!(), } } -type Selector = (FixedBytes<4>, FixedBytes<4>); - - -pub fn build_signature(func_name: &Spanned<&str>, args: &Box<[Spanned]>) -> Vec { - let mut arg_types = Vec::new(); +type Selector = (FixedBytes<4>, FixedBytes<4>); - for arg in args.iter() { - let arg_type = match arg.0 { - DynSolType::Address => "address", - DynSolType::Uint(_) => "uint256", - DynSolType::String => "string", - _ => panic!("Unsupported type: {:?}", arg.0), +pub fn compute_selector( + func: SolFunction, + err: SolError, +) -> Option<(FixedBytes<4>, FixedBytes<4>)> { + let build_signature = |name: &Spanned<&str>, args: &Box<[Spanned]>| -> Vec { + let arg_types: Vec<_> = args + .iter() + .map(|arg| match arg.0 { + DynSolType::Address => "address", + DynSolType::Uint(_) => "uint256", + DynSolType::String => "string", + _ => panic!("Unsupported type: {:?}", arg.0), + }) + .collect(); + + let mut signature = String::new(); + signature.push_str(name.0); + signature.push('('); + signature.push_str(&arg_types.join(",")); + signature.push(')'); + signature.into_bytes() + }; + + let build_selector = + |name: &Spanned<&str>, args: &Box<[Spanned]>| -> FixedBytes<4> { + let signature = build_signature(name, args); + let hash = keccak256(signature); + FixedBytes::<4>::from_slice(&hash[..4]) }; - arg_types.push(arg_type); - } - - // Build the signature using a String - let mut signature = String::new(); - signature.push_str(func_name.0); - signature.push('('); - signature.push_str(&arg_types.join(",")); - signature.push(')'); - - // Convert the signature String to Vec - signature.into_bytes() -} - - -pub fn compute_selector(func: SolFunction, err: SolError) -> Option { - let func_signature = build_signature(&func.name, &func.args); - let err_signature = build_signature(&err.name, &err.args); - - let func_hash = keccak256(func_signature); - let err_hash = keccak256(err_signature); - - - let func_selector: FixedBytes<4> = FixedBytes::from_slice(&func_hash[..4]); - let err_selector: FixedBytes<4> = FixedBytes::from_slice(&err_hash[..4]); + let func_selector = build_selector(&func.name, &func.args); + let err_selector = build_selector(&err.name, &err.args); Some((func_selector, err_selector)) } @@ -104,13 +99,10 @@ pub fn compute_selector(func: SolFunction, err: SolError) -> Option { mod tests { use super::*; use crate::ast::*; - use alloy_primitives::keccak256; use alloy_dyn_abi::DynSolType; + use alloy_primitives::keccak256; use chumsky::span::Span; - - - #[test] fn test_compute_selector() { let func = SolFunction { @@ -129,14 +121,14 @@ mod tests { ]), }; let selectors = compute_selector(func.clone(), err.clone()).unwrap(); - let func_signature = build_signature(&Spanned::new("transfer", 0..8), &func.args); - let err_signature = build_signature(&Spanned::new("TransferFailed", 0..15), &err.args); - let expected_func_hash = keccak256(func_signature.clone()); - let expected_err_hash = keccak256(err_signature.clone()); + let expected_func_hash = keccak256(selectors.0.clone()); + let expected_err_hash = keccak256(selectors.1.clone()); //println!("{}", &selectors); - let expected_func_selector: Selector = (FixedBytes::from_slice(&expected_func_hash[..4]), FixedBytes::from_slice(&expected_err_hash[..4])); + let expected_func_selector: Selector = ( + FixedBytes::from_slice(&expected_func_hash[..4]), + FixedBytes::from_slice(&expected_err_hash[..4]), + ); assert_eq!(selectors.0, expected_func_selector.0); assert_eq!(selectors.1, expected_func_selector.1); } } - From 54ac232194c05e4abf748dab178a397fd758915b Mon Sep 17 00:00:00 2001 From: willco-1 Date: Mon, 11 Nov 2024 11:43:40 -0500 Subject: [PATCH 3/9] fix --- .DS_Store | Bin 0 -> 6148 bytes crates/.DS_Store | Bin 0 -> 6148 bytes crates/ast/src/util.rs | 67 +++++++---------------------------------- examples/.DS_Store | Bin 0 -> 6148 bytes 4 files changed, 11 insertions(+), 56 deletions(-) create mode 100644 .DS_Store create mode 100644 crates/.DS_Store create mode 100644 examples/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4c23e3f0ae4de961267722538664f1a7897f0423 GIT binary patch literal 6148 zcmeHKyGjE=6g`uy8ng*kmiq;P{J|R5FGy#ld5{FMY|sQO7yJi*z$)0-rWLWa@(%>X zQn2>kJCkH5o1_#8_rlECy^oo*XW5w@0H!hN)PX913N^;ykh(R-ac%`GIS&^b9%I<6 zH`{44DrBld6;K8KqXP2bqlO*^7<=Du>EVe82lH5x#&K(yw#ZkRmcKvFyDz7Hyt6ev z>gU#m;FYyFn2(J$a6UU%CcEUIIN75q)R57vphbs{$U?&T;UR9baCym zF}G7<HG0bK9|8@K$_6 bO^jk8Ul2wPGmGRQ(;oqmK|598PZjtDCIpll literal 0 HcmV?d00001 diff --git a/crates/.DS_Store b/crates/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ae96ee35677366ffb4bfbb16876585e345e0c6ca GIT binary patch literal 6148 zcmeHKJ5Iwu5S=9{BGN=61*MNbE`UsAghZPQkdFjGb{r`|h|X{aO0GbOL`TI*H~J z2+T<-P)eO%F`SfRJkq>au@IDUa(el2%Ix%p;ygR%k9<10SkPKiz!V4-XvkxS&;R4i z_y4fSo=gE#V5<~x&18`D@k)BO)?SX!+6aCIXXCs=(3ham0WX6!rof*n@CDq&kNW@s literal 0 HcmV?d00001 diff --git a/crates/ast/src/util.rs b/crates/ast/src/util.rs index 09fad43..b082052 100644 --- a/crates/ast/src/util.rs +++ b/crates/ast/src/util.rs @@ -59,18 +59,13 @@ pub fn u256_as_push(value: U256) -> Opcode { type Selector = (FixedBytes<4>, FixedBytes<4>); -pub fn compute_selector( - func: SolFunction, - err: SolError, -) -> Option<(FixedBytes<4>, FixedBytes<4>)> { +pub fn compute_selector(name: &Spanned<&str>, args: &Box<[Spanned]>) -> FixedBytes<4> { let build_signature = |name: &Spanned<&str>, args: &Box<[Spanned]>| -> Vec { - let arg_types: Vec<_> = args + let arg_types: Vec = args .iter() - .map(|arg| match arg.0 { - DynSolType::Address => "address", - DynSolType::Uint(_) => "uint256", - DynSolType::String => "string", - _ => panic!("Unsupported type: {:?}", arg.0), + .map(|arg| { + let type_str = arg.0.to_string(); + type_str }) .collect(); @@ -79,56 +74,16 @@ pub fn compute_selector( signature.push('('); signature.push_str(&arg_types.join(",")); signature.push(')'); + signature.into_bytes() }; - let build_selector = - |name: &Spanned<&str>, args: &Box<[Spanned]>| -> FixedBytes<4> { - let signature = build_signature(name, args); - let hash = keccak256(signature); - FixedBytes::<4>::from_slice(&hash[..4]) - }; - - let func_selector = build_selector(&func.name, &func.args); - let err_selector = build_selector(&err.name, &err.args); + let signature = build_signature(name, args); - Some((func_selector, err_selector)) -} + let hash = keccak256(signature); -#[cfg(test)] -mod tests { - use super::*; - use crate::ast::*; - use alloy_dyn_abi::DynSolType; - use alloy_primitives::keccak256; - use chumsky::span::Span; + let selector = FixedBytes::<4>::from_slice(&hash[..4]); - #[test] - fn test_compute_selector() { - let func = SolFunction { - name: Spanned::new("transfer", 0..8), - args: Box::new([ - Spanned::new(DynSolType::Address, 9..17), - Spanned::new(DynSolType::Uint(256), 18..26), - ]), - rets: Box::new([]), - }; - let err = SolError { - name: Spanned::new("TransferFailed", 0..15), - args: Box::new([ - Spanned::new(DynSolType::String, 16..21), - Spanned::new(DynSolType::Uint(256), 22..30), - ]), - }; - let selectors = compute_selector(func.clone(), err.clone()).unwrap(); - let expected_func_hash = keccak256(selectors.0.clone()); - let expected_err_hash = keccak256(selectors.1.clone()); - //println!("{}", &selectors); - let expected_func_selector: Selector = ( - FixedBytes::from_slice(&expected_func_hash[..4]), - FixedBytes::from_slice(&expected_err_hash[..4]), - ); - assert_eq!(selectors.0, expected_func_selector.0); - assert_eq!(selectors.1, expected_func_selector.1); - } + selector } + diff --git a/examples/.DS_Store b/examples/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..04ee5af5e96d399b327b58360b13a6ab9d71b4af GIT binary patch literal 6148 zcmeHKOHRW;47E!IL2SBYIY*#32vs;iF90P47L8IBx*xHFJ0Nilwk$Xdr{H;Pg(fMm zt59V}o;UH>6X)gQ86x7zx*QXYh$w>!4vx`m5g8Zl$-pc!$Z3uh-7jv()9bog_PpKj z9~qEmcSv(u;i#dV=Xdnk9k1%5m@VoV?Ah7#V|*(=&ig*)pFYdG&G+OLQ{W}LK_*x9 zKxCIKu-#Pu}*Un463m0d=8E^*njsetck?cg#TW7!-a0VI% zuy{Jj5f2l<&Z;0){)13WCI#RRuxwY7J1 tQfmYB5-K8oQLza@CzWFON+~{tCV@Rj2bdd1MOYxd5J)t5;|%PSfiEm3QNI8H literal 0 HcmV?d00001 From f496206e95a0fa700b8d7d267e5dddfa2f9f7f9b Mon Sep 17 00:00:00 2001 From: willco-1 Date: Mon, 11 Nov 2024 11:45:13 -0500 Subject: [PATCH 4/9] remove --- .DS_Store | Bin 6148 -> 0 bytes crates/.DS_Store | Bin 6148 -> 0 bytes examples/.DS_Store | Bin 6148 -> 0 bytes 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store delete mode 100644 crates/.DS_Store delete mode 100644 examples/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 4c23e3f0ae4de961267722538664f1a7897f0423..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKyGjE=6g`uy8ng*kmiq;P{J|R5FGy#ld5{FMY|sQO7yJi*z$)0-rWLWa@(%>X zQn2>kJCkH5o1_#8_rlECy^oo*XW5w@0H!hN)PX913N^;ykh(R-ac%`GIS&^b9%I<6 zH`{44DrBld6;K8KqXP2bqlO*^7<=Du>EVe82lH5x#&K(yw#ZkRmcKvFyDz7Hyt6ev z>gU#m;FYyFn2(J$a6UU%CcEUIIN75q)R57vphbs{$U?&T;UR9baCym zF}G7<HG0bK9|8@K$_6 bO^jk8Ul2wPGmGRQ(;oqmK|598PZjtDCIpll diff --git a/crates/.DS_Store b/crates/.DS_Store deleted file mode 100644 index ae96ee35677366ffb4bfbb16876585e345e0c6ca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKJ5Iwu5S=9{BGN=61*MNbE`UsAghZPQkdFjGb{r`|h|X{aO0GbOL`TI*H~J z2+T<-P)eO%F`SfRJkq>au@IDUa(el2%Ix%p;ygR%k9<10SkPKiz!V4-XvkxS&;R4i z_y4fSo=gE#V5<~x&18`D@k)BO)?SX!+6aCIXXCs=(3ham0WX6!rof*n@CDq&kNW@s diff --git a/examples/.DS_Store b/examples/.DS_Store deleted file mode 100644 index 04ee5af5e96d399b327b58360b13a6ab9d71b4af..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKOHRW;47E!IL2SBYIY*#32vs;iF90P47L8IBx*xHFJ0Nilwk$Xdr{H;Pg(fMm zt59V}o;UH>6X)gQ86x7zx*QXYh$w>!4vx`m5g8Zl$-pc!$Z3uh-7jv()9bog_PpKj z9~qEmcSv(u;i#dV=Xdnk9k1%5m@VoV?Ah7#V|*(=&ig*)pFYdG&G+OLQ{W}LK_*x9 zKxCIKu-#Pu}*Un463m0d=8E^*njsetck?cg#TW7!-a0VI% zuy{Jj5f2l<&Z;0){)13WCI#RRuxwY7J1 tQfmYB5-K8oQLza@CzWFON+~{tCV@Rj2bdd1MOYxd5J)t5;|%PSfiEm3QNI8H From 7e4cf14913cf10a6d4ebc18d1e268eeb373ad5dd Mon Sep 17 00:00:00 2001 From: willco-1 Date: Tue, 12 Nov 2024 08:57:34 -0500 Subject: [PATCH 5/9] rm unused --- crates/ast/src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ast/src/util.rs b/crates/ast/src/util.rs index b082052..233638e 100644 --- a/crates/ast/src/util.rs +++ b/crates/ast/src/util.rs @@ -57,7 +57,7 @@ pub fn u256_as_push(value: U256) -> Opcode { } } -type Selector = (FixedBytes<4>, FixedBytes<4>); + pub fn compute_selector(name: &Spanned<&str>, args: &Box<[Spanned]>) -> FixedBytes<4> { let build_signature = |name: &Spanned<&str>, args: &Box<[Spanned]>| -> Vec { From 94cc2434331d58faa59d8f7120d971b4d873b7b6 Mon Sep 17 00:00:00 2001 From: willco-1 Date: Thu, 14 Nov 2024 12:45:05 -0500 Subject: [PATCH 6/9] rm unused --- crates/ast/src/util.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/ast/src/util.rs b/crates/ast/src/util.rs index 233638e..7b93c15 100644 --- a/crates/ast/src/util.rs +++ b/crates/ast/src/util.rs @@ -1,4 +1,4 @@ -use crate::ast::{SolError, SolFunction}; + use crate::Spanned; use alloy_dyn_abi::DynSolType; use alloy_primitives::{keccak256, FixedBytes, U256}; @@ -57,8 +57,6 @@ pub fn u256_as_push(value: U256) -> Opcode { } } - - pub fn compute_selector(name: &Spanned<&str>, args: &Box<[Spanned]>) -> FixedBytes<4> { let build_signature = |name: &Spanned<&str>, args: &Box<[Spanned]>| -> Vec { let arg_types: Vec = args @@ -86,4 +84,3 @@ pub fn compute_selector(name: &Spanned<&str>, args: &Box<[Spanned]>) selector } - From d59f77c38b6f31ab34fcd472b9cf5770c1b17105 Mon Sep 17 00:00:00 2001 From: willco-1 Date: Fri, 15 Nov 2024 12:46:50 -0500 Subject: [PATCH 7/9] fix: redudant closure / put test back --- crates/ast/src/lib.rs | 2 +- crates/ast/src/util.rs | 62 ++++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/crates/ast/src/lib.rs b/crates/ast/src/lib.rs index 2696f3e..b7273c7 100644 --- a/crates/ast/src/lib.rs +++ b/crates/ast/src/lib.rs @@ -5,4 +5,4 @@ mod util; pub use ast::*; pub use parser::parse; -pub use util::u256_as_push; +pub use util::*; diff --git a/crates/ast/src/util.rs b/crates/ast/src/util.rs index 7b93c15..a2fb7da 100644 --- a/crates/ast/src/util.rs +++ b/crates/ast/src/util.rs @@ -1,4 +1,3 @@ - use crate::Spanned; use alloy_dyn_abi::DynSolType; use alloy_primitives::{keccak256, FixedBytes, U256}; @@ -58,29 +57,52 @@ pub fn u256_as_push(value: U256) -> Opcode { } pub fn compute_selector(name: &Spanned<&str>, args: &Box<[Spanned]>) -> FixedBytes<4> { - let build_signature = |name: &Spanned<&str>, args: &Box<[Spanned]>| -> Vec { - let arg_types: Vec = args - .iter() - .map(|arg| { - let type_str = arg.0.to_string(); - type_str - }) - .collect(); + let arg_types: Vec = args.iter().map(|arg| arg.0.to_string()).collect(); + + let signature = format!("{}({})", name.0, arg_types.join(",")); + let hash = keccak256(signature.as_bytes()); + FixedBytes::<4>::from_slice(&hash[..4]) +} + +#[cfg(test)] +mod tests { + use super::*; + use chumsky::span::Span; + use crate::ast::{SolFunction, SolError}; - let mut signature = String::new(); - signature.push_str(name.0); - signature.push('('); - signature.push_str(&arg_types.join(",")); - signature.push(')'); + #[test] - signature.into_bytes() - }; + fn test_compute_selector() { + let func = SolFunction { + name: Spanned::new("transfer", 0..8), + args: Box::new([ + Spanned::new(DynSolType::Address, 9..17), + Spanned::new(DynSolType::Uint(256), 18..26), + ]), + rets: Box::new([]), + }; - let signature = build_signature(name, args); + let err = SolError { + name: Spanned::new("TransferFailed", 0..15), + args: Box::new([ + Spanned::new(DynSolType::String, 16..21), + Spanned::new(DynSolType::Uint(256), 22..30), + ]), + }; - let hash = keccak256(signature); + let func_selector = compute_selector(&func.name, &func.args); + let err_selector = compute_selector(&err.name, &err.args); - let selector = FixedBytes::<4>::from_slice(&hash[..4]); + let expected_func_signature = "transfer(address,uint256)"; + let expected_err_signature = "TransferFailed(string,uint256)"; - selector + let expected_func_hash = keccak256(expected_func_signature.as_bytes()); + let expected_err_hash = keccak256(expected_err_signature.as_bytes()); + + let expected_func_selector = FixedBytes::<4>::from_slice(&expected_func_hash[..4]); + let expected_err_selector = FixedBytes::<4>::from_slice(&expected_err_hash[..4]); + + assert_eq!(func_selector, expected_func_selector); + assert_eq!(err_selector, expected_err_selector); + } } From be40c435f41e079a57182a5e89791600c231ee71 Mon Sep 17 00:00:00 2001 From: willco-1 Date: Fri, 15 Nov 2024 12:50:05 -0500 Subject: [PATCH 8/9] clippy --- crates/ast/src/util.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ast/src/util.rs b/crates/ast/src/util.rs index a2fb7da..4c55dd0 100644 --- a/crates/ast/src/util.rs +++ b/crates/ast/src/util.rs @@ -56,7 +56,7 @@ pub fn u256_as_push(value: U256) -> Opcode { } } -pub fn compute_selector(name: &Spanned<&str>, args: &Box<[Spanned]>) -> FixedBytes<4> { +pub fn compute_selector(name: &Spanned<&str>, args: Box<[&Spanned]>) -> FixedBytes<4> { let arg_types: Vec = args.iter().map(|arg| arg.0.to_string()).collect(); let signature = format!("{}({})", name.0, arg_types.join(",")); @@ -67,8 +67,8 @@ pub fn compute_selector(name: &Spanned<&str>, args: &Box<[Spanned]>) #[cfg(test)] mod tests { use super::*; + use crate::ast::{SolError, SolFunction}; use chumsky::span::Span; - use crate::ast::{SolFunction, SolError}; #[test] From 04f7a3a0124d92e19f0abd36bab9006bd12654b8 Mon Sep 17 00:00:00 2001 From: willco-1 Date: Sat, 16 Nov 2024 10:28:57 -0500 Subject: [PATCH 9/9] accidentally broke the test, whoops --- crates/ast/src/util.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ast/src/util.rs b/crates/ast/src/util.rs index 4c55dd0..38d91f9 100644 --- a/crates/ast/src/util.rs +++ b/crates/ast/src/util.rs @@ -90,8 +90,8 @@ mod tests { ]), }; - let func_selector = compute_selector(&func.name, &func.args); - let err_selector = compute_selector(&err.name, &err.args); + let func_selector = compute_selector(&func.name, func.args.iter().collect::>()); + let err_selector = compute_selector(&err.name, err.args.iter().collect::>()); let expected_func_signature = "transfer(address,uint256)"; let expected_err_signature = "TransferFailed(string,uint256)";