Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fail to serialize custom structs with i128 when using TypedData::from_struct #625

Open
JNP777 opened this issue May 13, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@JNP777
Copy link

JNP777 commented May 13, 2024

Component

primitives

What version of Alloy are you on?

alloy-core 0.7.2

Operating System

Linux

Describe the bug

Having this custom sol struct with i128 numbers, i find that snippet 1 works and it results in a correct hash, but snippet 2 doesnt, showing a "number out of range" error. i think this is cause snippet2 function will use serde::json serialization while first 1 wont

struct Order {
    bytes32 sender;  
    int128 priceX18;  
    int128 amount;
    uint64 expiration;
    uint64 nonce;                
}

Snippet 1
let sig: FixedBytes<32> = msg.eip712_signing_hash(&(domain.clone()));
info!("sig 1 {:?}", sig);
Snippet 1
info!("st {:?} {:?}", TypedData::from_struct(&msg, Some(domain)).eip712_signing_hash(), sig);
info!("sig 2 {:?}", sig);

@JNP777 JNP777 added the bug Something isn't working label May 13, 2024
@prestwich
Copy link
Member

what values are your props set to? I am having trouble reproducing

@JNP777
Copy link
Author

JNP777 commented May 13, 2024

what values are your props set to? I am having trouble reproducing

solstruct: { sender: {your_evm_addy}64656661756c740000000000, priceX18: 2985200000000000000000, amount: 220000000000000000, expiration: 1715602468793, nonce: 1798939553346618344 }

domain: { name: Some("Vertex"), version: Some("0.0.1"), chain_id: Some(0x000000000000000000000000000000000000000000000000000000000000a4b1_U256), verifying_contract: Some(0xfe653438a1a4a7f56e727509c341d60a7b54fa91), salt: None }

@prestwich
Copy link
Member

oh yeah, you're definitely running into underlying serde_json i/u128 precision limitations. This will likely require changes to the sol macro or the sol-types data model 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants