Skip to content

Commit

Permalink
Merge f19c45b into 0d29b1a
Browse files Browse the repository at this point in the history
  • Loading branch information
MauroToscano committed Sep 23, 2024
2 parents 0d29b1a + f19c45b commit 8e7d46c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
12 changes: 4 additions & 8 deletions batcher/aligned-sdk/src/core/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,17 @@ impl Eip712 for NoncedVerificationData {

let mut hasher = Keccak256::new();

// As per the EIP, first we generate the type hash
// hashStruct(s : 𝕊) = keccak256(typeHash ‖ encodeData(s))

// We first generate the type hash
hasher.update(NONCED_VERIFICATION_DATA_TYPE);
let type_hash = hasher.finalize_reset();

// Then hash is resetted, so we start hashing the second term of the encodedData(s)
// Then we hash it with the rest of the data in the struct
hasher.update(type_hash);
hasher.update(verification_data_hash);
hasher.update(nonce_bytes);
hasher.update(max_fee_bytes);
let encoded_data_hash = hasher.finalize_reset();

// Now we do the actual final
// keccak256(typeHash ‖ encodeData(s))
hasher.update(type_hash);
hasher.update(encoded_data_hash);
let hash_struct = hasher.finalize_reset();

Ok(hash_struct.into())
Expand Down

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions contracts/src/core/BatcherPaymentService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ contract BatcherPaymentService is
noncedVerificationDataTypeHash = _noncedVerificationDataTypeHash;
}

// Defined in types.rs
// keccak256("NoncedVerificationData(bytes32 verification_data_hash,uint256 nonce,uint256 max_fee)")
function initializeNoncedVerificationDataTypeHash(
bytes32 _noncedVerificationDataTypeHash
) public reinitializer(2) onlyOwner {
Expand Down Expand Up @@ -280,15 +282,12 @@ contract BatcherPaymentService is
revert InvalidMaxFee(signatureData.maxFee, feePerProof);
}

bytes32 encodedDataHash = keccak256(
abi.encode(
leaf,
signatureData.nonce,
signatureData.maxFee
)
);

bytes32 structHash = keccak256(abi.encode(noncedVerificationDataTypeHash, encodedDataHash));
bytes32 structHash = keccak256(abi.encode(
noncedVerificationDataTypeHash,
leaf,
signatureData.nonce,
signatureData.maxFee
));

bytes32 hash = _hashTypedDataV4(structHash);

Expand Down

0 comments on commit 8e7d46c

Please sign in to comment.