Skip to content

Commit

Permalink
Fix permit hash (#1283)
Browse files Browse the repository at this point in the history
* fix permit hash

* fix message hash

* add changelog entry

* update changelog entry
  • Loading branch information
andrew-fleming authored Jan 6, 2025
1 parent 742d3af commit 39950b7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fixed message type hash in SNIP12 doc (#1274)
- Permit and Message SNIP12 hashes (#1283)

## 0.20.0 (2024-12-06)

Expand Down
19 changes: 11 additions & 8 deletions packages/token/src/erc20/snip12_utils/permit.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ pub struct Permit {

// Since there's no u64 type in SNIP-12, the type used for `deadline` parameter is u128
// selector!(
// "\"Permit\"(
// \"token\":\"ContractAddress\",
// \"spender\":\"ContractAddress\",
// \"amount\":\"u256\",
// \"nonce\":\"felt\",
// \"deadline\":\"u128\"
// )"
// "\"Permit\"(
// \"token\":\"ContractAddress\",
// \"spender\":\"ContractAddress\",
// \"amount\":\"u256\",
// \"nonce\":\"felt\",
// \"deadline\":\"u128\"
// )\"u256\"(
// \"low\":\"u128\",
// \"high\":\"u128\"
// )"
// );
pub const PERMIT_TYPE_HASH: felt252 =
0x2a8eb238e7cde741a544afcc79fe945d4292b089875fd068633854927fd5a96;
0x3210d4fa611411fccef9213585061fbd533f82d1ea2bd3c1b3b6b589448d5cf;

impl StructHashImpl of StructHash<Permit> {
fn hash_struct(self: @Permit) -> felt252 {
Expand Down
2 changes: 1 addition & 1 deletion packages/token/src/tests/erc20/test_erc20_permit.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ fn test_domain_separator() {
#[test]
fn test_permit_type_hash() {
let expected_type_hash = selector!(
"\"Permit\"(\"token\":\"ContractAddress\",\"spender\":\"ContractAddress\",\"amount\":\"u256\",\"nonce\":\"felt\",\"deadline\":\"u128\")",
"\"Permit\"(\"token\":\"ContractAddress\",\"spender\":\"ContractAddress\",\"amount\":\"u256\",\"nonce\":\"felt\",\"deadline\":\"u128\")\"u256\"(\"low\":\"u128\",\"high\":\"u128\")",
);
assert_eq!(PERMIT_TYPE_HASH, expected_type_hash);
}
Expand Down
14 changes: 13 additions & 1 deletion packages/utils/src/tests/test_snip12.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ use openzeppelin_testing::constants::{OWNER, RECIPIENT};
use snforge_std::{start_cheat_chain_id, test_address};
use starknet::ContractAddress;

// Since there's no u64 type in SNIP-12, the type used for `expiry` parameter is u128
// selector!(
// "\"Message\"(
// \"recipient\":\"ContractAddress\",
// \"amount\":\"u256\",
// \"nonce\":\"felt\",
// \"expiry\":\"u128\"
// )\"u256\"(
// \"low\":\"u128\",
// \"high\":\"u128\"
// )"
// );
const MESSAGE_TYPE_HASH: felt252 =
0x120ae1bdaf7c1e48349da94bb8dad27351ca115d6605ce345aee02d68d99ec1;
0x28bf13f11bba405c77ce010d2781c5903cbed100f01f72fcff1664f98343eb6;

#[derive(Copy, Drop, Hash)]
struct Message {
Expand Down

0 comments on commit 39950b7

Please sign in to comment.