Skip to content

[Bug]: Missing "Unlimited" as value for the DAI permit #28964

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

Closed
bschorchit opened this issue Dec 5, 2024 · 6 comments · Fixed by #29597
Closed

[Bug]: Missing "Unlimited" as value for the DAI permit #28964

bschorchit opened this issue Dec 5, 2024 · 6 comments · Fixed by #29597
Assignees
Labels
regression-RC-12.9.0 Regression bug that was found in release candidate (RC) for release 12.9.0 release-12.12.0 Issue or pull request that will be included in release 12.12.0 Sev2-normal Normal severity; minor loss of service or inconvenience. team-confirmations Push issues to confirmations team type-bug Something isn't working

Comments

@bschorchit
Copy link

bschorchit commented Dec 5, 2024

Describe the bug

For DAI permit, we're currently displaying no value for DAI permits.

Expected behavior

For DAI permit, we should display Unlimited as the value within estimated changes.

Screenshots/Recordings

image
image

Steps to reproduce

Payload:

{
  "types": {
    "EIP712Domain": [
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "version",
        "type": "string"
      },
      {
        "name": "chainId",
        "type": "uint256"
      },
      {
        "name": "verifyingContract",
        "type": "address"
      }
    ],
    "Permit": [
      {
        "name": "holder",
        "type": "address"
      },
      {
        "name": "spender",
        "type": "address"
      },
      {
        "name": "nonce",
        "type": "uint256"
      },
      {
        "name": "expiry",
        "type": "uint256"
      },
      {
        "name": "allowed",
        "type": "bool"
      }
    ]
  },
  "domain": {
    "name": "Dai Stablecoin",
    "version": "1",
    "verifyingContract": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
    "chainId": "0x1"
  },
  "primaryType": "Permit",
  "message": {
    "holder": "0xD2C44F28eC4C7eF686f587FADdb204da3aEFa827",
    "spender": "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
    "allowed": true,
    "nonce": 0,
    "expiry": 1660916504
  }
}

API response:

{
	"stateChanges": [
		{
			"assetType": "ERC20",
			"changeType": "APPROVE",
			"address": "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
			"amount": "115792089237316195423570985008687907853269984665640564039457584007913129639935",
			"contractAddress": "0x6B175474E89094C44Da98b954EedeAC495271d0F"
		}
	]
}

Error messages or log output

No response

Detection stage

During release testing

Version

12.9.0

Build type

None

Browser

Brave

Operating system

MacOS

Hardware wallet

No response

Additional context

No response

Severity

No response

@bschorchit bschorchit added type-bug Something isn't working Sev2-normal Normal severity; minor loss of service or inconvenience. release-blocker This bug is blocking the next release team-confirmations Push issues to confirmations team labels Dec 5, 2024
@github-project-automation github-project-automation bot moved this to To be fixed in Bugs by severity Dec 5, 2024
@github-project-automation github-project-automation bot moved this to To be fixed in Bugs by team Dec 5, 2024
@metamaskbot metamaskbot added the regression-RC-12.9.0 Regression bug that was found in release candidate (RC) for release 12.9.0 label Dec 5, 2024
@bschorchit bschorchit changed the title [Bug]: Missing "All" as value for the DAI permit [Bug]: Missing "Unlimited" as value for the DAI permit Dec 5, 2024
@digiwand
Copy link
Contributor

digiwand commented Dec 5, 2024

created a ticket to add this support here some time ago. Fixing this bug should resolve this ticket:
#27269

unrelated to the ticket, but related to 2612 backwards compatibility support, we will also need to support:
#27357

@jpuri
Copy link
Contributor

jpuri commented Dec 6, 2024

Hey @bschorchit : the simulation displayed above are not returned by decoding api but they are implemented by us in UI.

Decoding api for request above is returning NotSupported:

Image

Reason could be that request body does not comply to 712 format.

@bschorchit bschorchit removed the release-blocker This bug is blocking the next release label Dec 6, 2024
@imblue-dabadee
Copy link
Contributor

Ah, the correct payload would be:

{
	"method": "eth_signTypedData_v4",
	"params": [
		"0xD2C44F28eC4C7eF686f587FADdb204da3aEFa827",
		{
			"types": {
				"EIP712Domain": [
					{
						"name": "name",
						"type": "string"
					},
					{
						"name": "version",
						"type": "string"
					},
					{
						"name": "chainId",
						"type": "uint256"
					},
					{
						"name": "verifyingContract",
						"type": "address"
					}
				],
				"Permit": [
					{
						"name": "holder",
						"type": "address"
					},
					{
						"name": "spender",
						"type": "address"
					},
					{
						"name": "nonce",
						"type": "uint256"
					},
					{
						"name": "expiry",
						"type": "uint256"
					},
					{
						"name": "allowed",
						"type": "bool"
					}
				]
			},
			"domain": {
				"name": "Dai Stablecoin",
				"version": "1",
				"verifyingContract": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
				"chainId": "0x1"
			},
			"primaryType": "Permit",
			"message": {
				"holder": "0xD2C44F28eC4C7eF686f587FADdb204da3aEFa827",
				"spender": "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
				"allowed": true,
				"nonce": 0,
				"expiry": 2060916504
			}
		}
	]
}

I should've clarified that I was simply pasting the params field.

@jpuri
Copy link
Contributor

jpuri commented Dec 11, 2024

Hey @imblue-dabadee , @bschorchit : I used the sample request above and it is giving me this error:

Image

@jpuri
Copy link
Contributor

jpuri commented Dec 12, 2024

Additionally displaying Unlimited for very large values will be addressed by this issue: https://github.com/MetaMask/MetaMask-planning/issues/3763

@jpuri jpuri removed their assignment Dec 12, 2024
@jpuri
Copy link
Contributor

jpuri commented Jan 7, 2025

For DAI we need to fix our default implementation to display UNLIMITED is user is granted access. Take into account value of allowed field for displaying this. : https://eips.ethereum.org/EIPS/eip-2612. True for allowed is unlimited approval and false is revoke.

Note: our default implementation for permit is displayed when decoding api result is not available.

@pedronfigueiredo pedronfigueiredo self-assigned this Jan 7, 2025
github-merge-queue bot pushed a commit that referenced this issue Jan 17, 2025
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Introduces a new logical path for displaying "Unlimited" in the permit
simulation, for when the `allowed` property in the signature message is
set and the permit is for the token DAI. This is as is specified in
[ERC-2612](https://eips.ethereum.org/EIPS/eip-2612)'s "Backwards
Compatibility" section:

> There are already a couple of permit functions in token contracts
implemented in contracts in the wild, most notably the one introduced in
the dai.sol.

> Its implementation differs slightly from the presentation here in
that:

> instead of taking a value argument, it takes a bool allowed, setting
approval to 0 or uint(-1).

This PR also fixes a bug that prevents boolean values from being
displayed in the key value display in the message section of signatures.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29597?quickstart=1)

## **Related issues**

Fixes: #28964

## **Manual testing steps**

1. Open the browser console and execute the following code:

```javascript
async function connectMetaMask() {
  try {
    const accounts = await window.ethereum.request({
      method: 'eth_requestAccounts',
    });
    console.log('Connected account:', accounts[0]);
    return accounts[0];
  } catch (error) {
    console.error('User rejected the request:', error);
    throw error;
  }
}
async function signPermit() {
  try {
    const fromAddress = await connectMetaMask();
    const msgParams = {
      types: {
        EIP712Domain: [
          { name: 'name', type: 'string' },
          { name: 'version', type: 'string' },
          { name: 'chainId', type: 'uint256' },
          { name: 'verifyingContract', type: 'address' },
        ],
        Permit: [
          { name: 'holder', type: 'address' },
          { name: 'spender', type: 'address' },
          { name: 'nonce', type: 'uint256' },
          { name: 'expiry', type: 'uint256' },
          { name: 'allowed', type: 'bool' },
        ],
      },
      domain: {
        name: 'Dai Stablecoin',
        version: '1',
        verifyingContract: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
        chainId: '0x1',
      },
      primaryType: 'Permit',
      message: {
        holder: '0xD2C44F28eC4C7eF686f587FADdb204da3aEFa827',
        spender: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
        allowed: true,
        nonce: 0,
        expiry: 1660916504,
      },
    };

    const signature = await window.ethereum.request({
      method: 'eth_signTypedData_v4',
      params: [fromAddress, JSON.stringify(msgParams)],
    });
    console.log('Signature:', signature);
    return signature;
  } catch (error) {
    console.error('Error signing permit:', error);
  }
}
signPermit();
```

2. Change `"allowed": true` to `"allowed": false` in the aforementioned
code and execute it to see the revocation screen.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

<img width="472" alt="Screenshot 2025-01-08 at 18 30 35"
src="https://github.com/user-attachments/assets/93e5f295-7b75-4e1d-88c0-aaa1d11ff01d"
/>
<img width="472" alt="Screenshot 2025-01-08 at 18 30 37"
src="https://github.com/user-attachments/assets/59e8b129-df26-4f24-bcd2-a978f974eedd"
/>

<img width="472" alt="Screenshot 2025-01-09 at 10 22 09"
src="https://github.com/user-attachments/assets/10064bde-2e65-43de-b624-1c0a04d6eea4"
/>
<img width="472" alt="Screenshot 2025-01-09 at 10 22 13"
src="https://github.com/user-attachments/assets/22ecff23-71de-4293-9fba-fab74b52a42c"
/>



## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@github-project-automation github-project-automation bot moved this from To be fixed to Fixed in Bugs by severity Jan 17, 2025
@github-project-automation github-project-automation bot moved this from To be fixed to Fixed in Bugs by team Jan 17, 2025
@metamaskbot metamaskbot added the release-12.12.0 Issue or pull request that will be included in release 12.12.0 label Jan 17, 2025
Akaryatrh pushed a commit that referenced this issue Jan 23, 2025
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Introduces a new logical path for displaying "Unlimited" in the permit
simulation, for when the `allowed` property in the signature message is
set and the permit is for the token DAI. This is as is specified in
[ERC-2612](https://eips.ethereum.org/EIPS/eip-2612)'s "Backwards
Compatibility" section:

> There are already a couple of permit functions in token contracts
implemented in contracts in the wild, most notably the one introduced in
the dai.sol.

> Its implementation differs slightly from the presentation here in
that:

> instead of taking a value argument, it takes a bool allowed, setting
approval to 0 or uint(-1).

This PR also fixes a bug that prevents boolean values from being
displayed in the key value display in the message section of signatures.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29597?quickstart=1)

## **Related issues**

Fixes: #28964

## **Manual testing steps**

1. Open the browser console and execute the following code:

```javascript
async function connectMetaMask() {
  try {
    const accounts = await window.ethereum.request({
      method: 'eth_requestAccounts',
    });
    console.log('Connected account:', accounts[0]);
    return accounts[0];
  } catch (error) {
    console.error('User rejected the request:', error);
    throw error;
  }
}
async function signPermit() {
  try {
    const fromAddress = await connectMetaMask();
    const msgParams = {
      types: {
        EIP712Domain: [
          { name: 'name', type: 'string' },
          { name: 'version', type: 'string' },
          { name: 'chainId', type: 'uint256' },
          { name: 'verifyingContract', type: 'address' },
        ],
        Permit: [
          { name: 'holder', type: 'address' },
          { name: 'spender', type: 'address' },
          { name: 'nonce', type: 'uint256' },
          { name: 'expiry', type: 'uint256' },
          { name: 'allowed', type: 'bool' },
        ],
      },
      domain: {
        name: 'Dai Stablecoin',
        version: '1',
        verifyingContract: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
        chainId: '0x1',
      },
      primaryType: 'Permit',
      message: {
        holder: '0xD2C44F28eC4C7eF686f587FADdb204da3aEFa827',
        spender: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
        allowed: true,
        nonce: 0,
        expiry: 1660916504,
      },
    };

    const signature = await window.ethereum.request({
      method: 'eth_signTypedData_v4',
      params: [fromAddress, JSON.stringify(msgParams)],
    });
    console.log('Signature:', signature);
    return signature;
  } catch (error) {
    console.error('Error signing permit:', error);
  }
}
signPermit();
```

2. Change `"allowed": true` to `"allowed": false` in the aforementioned
code and execute it to see the revocation screen.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

<img width="472" alt="Screenshot 2025-01-08 at 18 30 35"
src="https://github.com/user-attachments/assets/93e5f295-7b75-4e1d-88c0-aaa1d11ff01d"
/>
<img width="472" alt="Screenshot 2025-01-08 at 18 30 37"
src="https://github.com/user-attachments/assets/59e8b129-df26-4f24-bcd2-a978f974eedd"
/>

<img width="472" alt="Screenshot 2025-01-09 at 10 22 09"
src="https://github.com/user-attachments/assets/10064bde-2e65-43de-b624-1c0a04d6eea4"
/>
<img width="472" alt="Screenshot 2025-01-09 at 10 22 13"
src="https://github.com/user-attachments/assets/22ecff23-71de-4293-9fba-fab74b52a42c"
/>



## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-RC-12.9.0 Regression bug that was found in release candidate (RC) for release 12.9.0 release-12.12.0 Issue or pull request that will be included in release 12.12.0 Sev2-normal Normal severity; minor loss of service or inconvenience. team-confirmations Push issues to confirmations team type-bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants