Skip to content

Commit

Permalink
Merge pull request #1 from euler-xyz/cantina-41
Browse files Browse the repository at this point in the history
Cantina 41: Contracts cannot be upgraded
  • Loading branch information
kasperpawlowski authored Jul 6, 2024
2 parents 1601566 + c7e6fd9 commit 7cb707d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
8 changes: 2 additions & 6 deletions src/EthereumVaultConnector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ contract EthereumVaultConnector is Events, Errors, TransientStorage, IEVC {
/// @notice Name of the Ethereum Vault Connector.
string public constant name = "Ethereum Vault Connector";

/// @notice Version of the Ethereum Vault Connector.
string public constant version = "1";

uint160 internal constant ACCOUNT_ID_OFFSET = 8;
bytes32 internal constant HASHED_NAME = keccak256(bytes(name));
bytes32 internal constant HASHED_VERSION = keccak256(bytes(version));

bytes32 internal constant TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

bytes32 internal constant PERMIT_TYPEHASH = keccak256(
"Permit(address signer,address sender,uint256 nonceNamespace,uint256 nonce,uint256 deadline,uint256 value,bytes data)"
Expand Down Expand Up @@ -1148,7 +1144,7 @@ contract EthereumVaultConnector is Events, Errors, TransientStorage, IEVC {
/// @notice Calculates the EIP-712 domain separator for the contract.
/// @return The calculated EIP-712 domain separator as a bytes32 value.
function calculateDomainSeparator() internal view returns (bytes32) {
return keccak256(abi.encode(TYPE_HASH, HASHED_NAME, HASHED_VERSION, block.chainid, address(this)));
return keccak256(abi.encode(TYPE_HASH, HASHED_NAME, block.chainid, address(this)));
}

// Auxiliary functions
Expand Down
21 changes: 7 additions & 14 deletions test/unit/EthereumVaultConnector/Permit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,26 @@ abstract contract EIP712 {
using ShortStrings for *;

bytes32 internal constant _TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

bytes32 internal immutable _hashedName;
bytes32 internal immutable _hashedVersion;

ShortString private immutable _name;
ShortString private immutable _version;
string private _nameFallback;
string private _versionFallback;

/**
* @dev Initializes the domain separator.
*
* The meaning of `name` and `version` is specified in
* The meaning of `name` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
constructor(string memory name) {
_name = name.toShortStringWithFallback(_nameFallback);
_version = version.toShortStringWithFallback(_versionFallback);
_hashedName = keccak256(bytes(name));
_hashedVersion = keccak256(bytes(version));
}

/**
Expand Down Expand Up @@ -80,7 +73,7 @@ contract SignerECDSA is EIP712, Test {
"Permit(address signer,address sender,uint256 nonceNamespace,uint256 nonce,uint256 deadline,uint256 value,bytes data)"
);

constructor(EthereumVaultConnector _evc) EIP712(_evc.name(), _evc.version()) {
constructor(EthereumVaultConnector _evc) EIP712(_evc.name()) {
evc = _evc;
}

Expand All @@ -89,7 +82,7 @@ contract SignerECDSA is EIP712, Test {
}

function _buildDomainSeparator() internal view override returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(evc)));
return keccak256(abi.encode(_TYPE_HASH, _hashedName, block.chainid, address(evc)));
}

function signPermit(
Expand Down Expand Up @@ -118,12 +111,12 @@ contract SignerERC1271 is EIP712, IERC1271 {
"Permit(address signer,address sender,uint256 nonceNamespace,uint256 nonce,uint256 deadline,uint256 value,bytes data)"
);

constructor(EthereumVaultConnector _evc) EIP712(_evc.name(), _evc.version()) {
constructor(EthereumVaultConnector _evc) EIP712(_evc.name()) {
evc = _evc;
}

function _buildDomainSeparator() internal view override returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(evc)));
return keccak256(abi.encode(_TYPE_HASH, _hashedName, block.chainid, address(evc)));
}

function setSignatureHash(bytes calldata signature) external {
Expand Down

0 comments on commit 7cb707d

Please sign in to comment.