Skip to content

Commit e0727c2

Browse files
authored
fix: eip712 string interface prefix (#954)
1 parent e55993f commit e0727c2

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

crates/sol-types/tests/macros/sol/eip712.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,30 @@ fn encode_data_nesting() {
6363
"25c3d40a39e639a4d0b6e4d2ace5e1281e039c88494d97d8d08f99a6ea75d775".parse::<B256>().unwrap()
6464
)
6565
}
66+
67+
#[test]
68+
fn test_eip712_interface_prefix() {
69+
sol! {
70+
interface IParentInterfaceA {
71+
struct ParentStructA {
72+
uint256 numberA;
73+
}
74+
}
75+
76+
interface IParentInterfaceB {
77+
struct ParentStructB {
78+
uint256 numberB;
79+
}
80+
}
81+
82+
struct MyStruct {
83+
IParentInterfaceA.ParentStructA structA;
84+
IParentInterfaceB.ParentStructB structB;
85+
}
86+
}
87+
88+
assert_eq!(
89+
MyStruct::eip712_encode_type(),
90+
"MyStruct(ParentStructA structA,ParentStructB structB)ParentStructA(uint256 numberA)ParentStructB(uint256 numberB)"
91+
);
92+
}

crates/syn-solidity/src/variable/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,15 @@ impl VariableDeclaration {
7878

7979
/// Formats `self` as an EIP-712 field: `<ty> <name>`
8080
pub fn fmt_eip712(&self, f: &mut impl Write) -> fmt::Result {
81-
write!(f, "{}", self.ty)?;
81+
// According to EIP-712, type strings should only contain struct name, not interface prefix
82+
match &self.ty {
83+
crate::Type::Custom(path) => {
84+
write!(f, "{}", path.last())?;
85+
}
86+
_ => {
87+
write!(f, "{}", self.ty)?;
88+
}
89+
}
8290
if let Some(name) = &self.name {
8391
write!(f, " {name}")?;
8492
}

0 commit comments

Comments
 (0)