Skip to content
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

Wrong DOMAIN_SEPARATOR definition #173

Closed
code423n4 opened this issue May 28, 2022 · 1 comment
Closed

Wrong DOMAIN_SEPARATOR definition #173

code423n4 opened this issue May 28, 2022 · 1 comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate This issue or pull request already exists

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L199-L210

Vulnerability details

Impact

Broke the EIP 2612

Proof of Concept

Some contract or dapp/backend could building the DOMAIN_SEPARATOR consulting the "rigth" name to the BathToken and build the signature with "rigth" digest message
When these try to use the permit function (L713), with the "rigth" signature(v, r, s), the permit function will revert with the message "bathToken: INVALID_SIGNATURE" because the expect DOMAIN_SEPARATOR in the BathToken.sol contract was built with "wrong" name

Recommended Mitigation Steps

In the initialize function(L181) move the name definition before the DOMAIN_SEPARATOR definition

function initialize(
    ERC20 token,
    address market,
    address _feeTo
) external {
    require(!initialized);
    string memory _symbol = string(
        abi.encodePacked(("bath"), token.symbol())
    );
    symbol = _symbol;
    underlyingToken = token;
    RubiconMarketAddress = market;
    bathHouse = msg.sender; //NOTE: assumed admin is creator on BathHouse

    uint256 chainId;
    assembly {
        chainId := chainid()
    }
    name = string(abi.encodePacked(_symbol, (" v1")));
    DOMAIN_SEPARATOR = keccak256(
        abi.encode(
            keccak256(
                "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
            ),
            keccak256(bytes(name)),
            keccak256(bytes("1")),
            chainId,
            address(this)
        )
    );
    decimals = token.decimals(); // v1 Change - 4626 Adherence

    // Add infinite approval of Rubicon Market for this asset
    IERC20(address(token)).approve(RubiconMarketAddress, 2**256 - 1);
    emit LogInit(block.timestamp);

    feeTo = address(this); //This contract is the fee recipient, rewarding HODLers
    feeBPS = 3; //Fee set to 3 BPS initially

    // Complete constract instantiation
    initialized = true;
}
@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels May 28, 2022
code423n4 added a commit that referenced this issue May 28, 2022
@bghughes bghughes added the duplicate This issue or pull request already exists label Jun 3, 2022
@bghughes
Copy link
Collaborator

bghughes commented Jun 3, 2022

Duplicate of #38

@bghughes bghughes marked this as a duplicate of #38 Jun 3, 2022
@bghughes bghughes closed this as completed Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants