Skip to content

Commit ace685c

Browse files
authored
Fix EIP 712 - Data of the struct should be concatenated after type hash (#1054)
1 parent 0d29b1a commit ace685c

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

batcher/aligned-sdk/src/core/types.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,17 @@ impl Eip712 for NoncedVerificationData {
232232

233233
let mut hasher = Keccak256::new();
234234

235-
// As per the EIP, first we generate the type hash
236235
// hashStruct(s : 𝕊) = keccak256(typeHash ‖ encodeData(s))
236+
237+
// We first generate the type hash
237238
hasher.update(NONCED_VERIFICATION_DATA_TYPE);
238239
let type_hash = hasher.finalize_reset();
239240

240-
// Then hash is resetted, so we start hashing the second term of the encodedData(s)
241+
// Then we hash it with the rest of the data in the struct
242+
hasher.update(type_hash);
241243
hasher.update(verification_data_hash);
242244
hasher.update(nonce_bytes);
243245
hasher.update(max_fee_bytes);
244-
let encoded_data_hash = hasher.finalize_reset();
245-
246-
// Now we do the actual final
247-
// keccak256(typeHash ‖ encodeData(s))
248-
hasher.update(type_hash);
249-
hasher.update(encoded_data_hash);
250246
let hash_struct = hasher.finalize_reset();
251247

252248
Ok(hash_struct.into())

contracts/scripts/anvil/state/alignedlayer-deployed-anvil-state.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

contracts/src/core/BatcherPaymentService.sol

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ contract BatcherPaymentService is
7979
noncedVerificationDataTypeHash = _noncedVerificationDataTypeHash;
8080
}
8181

82+
// Defined in types.rs
83+
// keccak256("NoncedVerificationData(bytes32 verification_data_hash,uint256 nonce,uint256 max_fee)")
8284
function initializeNoncedVerificationDataTypeHash(
8385
bytes32 _noncedVerificationDataTypeHash
8486
) public reinitializer(2) onlyOwner {
@@ -280,15 +282,12 @@ contract BatcherPaymentService is
280282
revert InvalidMaxFee(signatureData.maxFee, feePerProof);
281283
}
282284

283-
bytes32 encodedDataHash = keccak256(
284-
abi.encode(
285-
leaf,
286-
signatureData.nonce,
287-
signatureData.maxFee
288-
)
289-
);
290-
291-
bytes32 structHash = keccak256(abi.encode(noncedVerificationDataTypeHash, encodedDataHash));
285+
bytes32 structHash = keccak256(abi.encode(
286+
noncedVerificationDataTypeHash,
287+
leaf,
288+
signatureData.nonce,
289+
signatureData.maxFee
290+
));
292291

293292
bytes32 hash = _hashTypedDataV4(structHash);
294293

0 commit comments

Comments
 (0)