argotorg / argotorg/solidity

Encoding Struct directly gives different output than encoding variables of struct in spread out manner

Open
#14,286 1 comment 0 reactions 0 assignees View on GitHub
bug :bug:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

The output of both of these functions are different why? How to make them equal. I am trying to use this in EIP712 signature checking. But the returned address doesn't match. It seems like encoding struct directly is done in some different manner than when done manually.

```

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;
pragma abicoder v2;

contract testabi {

struct DATA {
address a1;
uint256 num;
bytes nom;
}

bytes32 constant public DATA_TYPEHASH = keccak256("DATA(address a1,uint256 num,bytes nom)");

DATA data1 = DATA(0x782DDbeBcCA0aC1952e6f8CD525f707B4e2B3077, 100, "0x0000000000000000000000000000000000000000000000000000000000011170000000000000000000000000420000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000");

function encodeDecode1() public view returns(bytes32 ) {
return keccak256(abi.encode(
DATA_TYPEHASH,
data1
));
}

function encodeDecode2() public view returns(bytes32 ) {
return keccak256(abi.encode(
DATA_TYPEHASH,
data1.a1,
data1.num,
keccak256(data1.nom)
));
}


}

```

```
JS code for generating signature

const signature = await wallet._signTypedData(
domain,
{
DATA: [
{ name: 'a1', type: 'address' },
{ name: 'num', type: 'uint256' },
{ name: 'nom', type: 'bytes' }
]
},
data
)
return signature
}

```

Contributor guide

Open the contributing guide

Research direction

Start with the Solidity contract's encodeDecode1 and encodeDecode2 entry points, then compare their abi.encode inputs with ethers' _signTypedData call. Done means the encoding discrepancy and its effect on the EIP-712 signature are explained, with a reproducible expected match or a clearly identified issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, solidity
Domain
blockchain
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.