Address Contract Verified
Address
0xa2ca14c7d625895e6939961B87CE378836ca840F
Balance
0.098328 ETH
Nonce
1
Code Size
5302 bytes
Creator
0xcaFe2eF5...f7e3 at tx 0x811f1610...c9e3fa
Indexed Transactions
0
Contract Bytecode
5302 bytes
0x6080806040526004361015610049575b50361561001b57600080fd5b6040513481527f543ba50a5eec5e6178218e364b1d0f396157b3c8fa278522c2cb7fd99407d47460203392a2005b60003560e01c90816301ffc9a714610b78575080630716326d14610b0857806312065fe014610aec578063248a9ca314610ab75780632e1a7d4d14610a835780632f2ff15d146109c757806336568abe146109355780633b6db66f1461087d578063492f90241461083f5780634c69c00f146107b65780636d955b24146105f757806375b238fc146105bc578063853828b61461054457806391d14854146104f7578063a217fddf146104db578063a2359af9146102af578063a89ae4ba14610286578063c86283c8146101cf578063d0e30db01461017e5763d547741f14610132573861000f565b3461017957604036600319011261017957610177600435610151610bcb565b9061017261016d82600052600060205260016040600020015490565b610e36565b610e78565b005b600080fd5b60003660031901126101795734156101be576040513481527f543ba50a5eec5e6178218e364b1d0f396157b3c8fa278522c2cb7fd99407d47460203392a2005b63d73ab2e160e01b60005260046000fd5b34610179576040366003190112610179576024356001600160a01b038116906004359082900361017957610201610d08565b81156102755747811161026457600080808084865af161021f610cbb565b5015610253576040519081527f8b192dc173e314b16d9067e45c2afbdcdc1713fc4fe1a95aff9076249648abc060203392a3005b6312171d8360e31b60005260046000fd5b631e9acf1760e31b60005260046000fd5b634e46966960e11b60005260046000fd5b34610179576000366003190112610179576002546040516001600160a01b039091168152602090f35b60a03660031901126101795760043567ffffffffffffffff8111610179576102db903690600401610c8a565b9060243567ffffffffffffffff8111610179576102fc903690600401610c8a565b9060443567ffffffffffffffff81116101795761031d903690600401610c8a565b94909260643567ffffffffffffffff811161017957610340903690600401610c8a565b909660843567ffffffffffffffff811161017957610362903690600401610c8a565b94909281156104ca578185148015906104c0575b80156104b6575b80156104ac575b61049b576000805b8381106104665750340361045557939736849003601e1901949060005b8381106103b257005b808a8a6103e88f948f6103e1828c6103da828d958f828f916103d392610cf8565b3599610cf8565b3597610cf8565b3596610cf8565b358b84101561043f578360051b8a01358b811215610179578a019485359567ffffffffffffffff87116101795760200193863603851361017957610433610439956001983691610c35565b93610efa565b016103a9565b634e487b7160e01b600052603260045260246000fd5b635c3ef66b60e01b60005260046000fd5b9061047282868c610cf8565b358101809111610485579060010161038c565b634e487b7160e01b600052601160045260246000fd5b63512509d360e11b60005260046000fd5b5081861415610384565b508181141561037d565b5081831415610376565b63c2e5347d60e01b60005260046000fd5b3461017957600036600319011261017957602060405160008152f35b3461017957604036600319011261017957610510610bcb565b600435600052600060205260406000209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b346101795760003660031901126101795761055d610d08565b4780156105ab57600080808084335af1610575610cbb565b50156102535760405190815233907f8b192dc173e314b16d9067e45c2afbdcdc1713fc4fe1a95aff9076249648abc060203392a3005b63177b02e160e31b60005260046000fd5b346101795760003660031901126101795760206040517fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217758152f35b346101795760603660031901126101795760243560043560443567ffffffffffffffff81116101795761062e903690600401610c6c565b816000526001602052604060002090600482019384549283156107a557600581019283549260ff8416610794574281116107835761025861066f8242610ceb565b11610772576106dd916106d59160405160208101918a83524660408301526060820152606081526106a1608082610be1565b5190207f19457468657265756d205369676e6564204d6573736167653a0a333200000000600052601c52603c6000206110a5565b9190916110dd565b6002546001600160a01b039081169116036107615760ff1990911660011790915560030180549091600091829182918291906001600160a01b03165af1610722610cbb565b50156102535760207ff8590cd6b8c44be7a2bc57131f10e203ec5f7d7f2f761e1508a8cc964ecb9eb79160018060a01b039054169354604051908152a3005b638baa579f60e01b60005260046000fd5b638c56028160e01b60005260046000fd5b6347860b9760e01b60005260046000fd5b63542f378d60e11b60005260046000fd5b636f8e482b60e11b60005260046000fd5b34610179576020366003190112610179576004356001600160a01b03811690819003610179576107e4610d08565b801561082e57600280546001600160a01b0319811683179091556001600160a01b03167f078c3b417dadf69374a59793b829c52001247130433427049317bde56607b1b7600080a3005b635521068160e01b60005260046000fd5b60803660031901126101795760643567ffffffffffffffff81116101795761086e610177913690600401610c6c565b60443534602435600435610efa565b3461017957602036600319011261017957600435610899610d08565b806000526001602052604060002090600482019182549081156107a557600581019081549060ff82166107945760ff1990911660011790915560030180549091600091829182918291906001600160a01b03165af16108f6610cbb565b50156102535760207fccdfebe0ad5ff1f4324838983b07306895b2d10a6ff48a4f0a588b1e90001e5c9160018060a01b039054169354604051908152a3005b346101795760403660031901126101795761094e610bcb565b336001600160a01b0382160361096a5761017790600435610e78565b60405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608490fd5b34610179576040366003190112610179576004356109e3610bcb565b906109ff61016d82600052600060205260016040600020015490565b6000818152602081815260408083206001600160a01b038616845290915290205460ff1615610a2a57005b6000818152602081815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4005b3461017957602036600319011261017957600435610a9f610d08565b47811161026457600080808084335af1610575610cbb565b34610179576020366003190112610179576020610ae4600435600052600060205260016040600020015490565b604051908152f35b3461017957600036600319011261017957602047604051908152f35b3461017957602036600319011261017957600435600052600160205260c06040600020805490600181015490600281015460018060a01b036003830154169060ff6005600485015494015416936040519586526020860152604085015260608401526080830152151560a0820152f35b34610179576020366003190112610179576004359063ffffffff60e01b821680920361017957602091637965db0b60e01b8114908115610bba575b5015158152f35b6301ffc9a760e01b14905083610bb3565b602435906001600160a01b038216820361017957565b90601f8019910116810190811067ffffffffffffffff821117610c0357604052565b634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff8111610c0357601f01601f191660200190565b929192610c4182610c19565b91610c4f6040519384610be1565b829481845281830111610179578281602093846000960137010152565b9080601f8301121561017957816020610c8793359101610c35565b90565b9181601f840112156101795782359167ffffffffffffffff8311610179576020808501948460051b01011161017957565b3d15610ce6573d90610ccc82610c19565b91610cda6040519384610be1565b82523d6000602084013e565b606090565b9190820391821161048557565b919081101561043f5760051b0190565b3360009081527f7d7ffb7a348e1c6a02869081a26547b49160dd3df72d1d75a570eb9b698292ec602052604090205460ff1615610d4157565b610e2860446037610d5133611208565b610e006011610d7f7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775611348565b60405194859160208301957f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008752610dc08151809260208688019101611082565b83017001034b99036b4b9b9b4b733903937b6329607d1b83820152610def825180936020604885019101611082565b01010301601f198101845283610be1565b60405193849262461bcd60e51b84526020600485015251809281602486015285850190611082565b601f01601f19168101030190fd5b60008181526020818152604080832033845290915290205460ff1615610e595750565b60446037610e2892610e006011610d7f610e7233611208565b93611348565b6000818152602081815260408083206001600160a01b038616845290915290205460ff16610ea4575050565b6000818152602081815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4565b929390919384156110715783600052600160205260046040600020015461106057428111610783576301e13380610f318242610ceb565b1161077257610f6f916106d591604051602081019188835287604083015286606083015246608083015260a082015260a081526106a160c082610be1565b6002546001600160a01b039081169116036107615760405160c0810181811067ffffffffffffffff821117610c0357604052828152600560208201918383526040810142815260608201338152608083019188835260a084019560008752886000526001602052604060002094518555516001850155516002840155600383019060018060a01b039051166bffffffffffffffffffffffff60a01b825416179055516004820155019051151560ff8019835416911617905560405192835260208301524260408301527f2633172e71e9b8235f10e566d444af24a2c2db9d80bcdb85a4ea0c8470b188a960603393a3565b630ce5576360e11b60005260046000fd5b63162908e360e11b60005260046000fd5b60005b8381106110955750506000910152565b8181015183820152602001611085565b9060418151146000146110d3576110cf916020820151906060604084015193015160001a906113f4565b9091565b5050600090600290565b60058110156111e157806110ee5750565b6001810361113b5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606490fd5b600281036111885760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606490fd5b60031461119157565b60405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608490fd5b634e487b7160e01b600052602160045260246000fd5b90815181101561043f570160200190565b600090611215602a610c19565b916112236040519384610be1565b602a8352611231602a610c19565b6020840190601f19013682378351156113345760309053825160011015611320576078602184015350602960005b600182116112b45750506112705790565b606460405162461bcd60e51b815260206004820152602060248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152fd5b9091600f8116601081101561130c576f181899199a1a9b1b9c1cb0b131b232b360811b901a6112e384866111f7565b5360041c9180156112f857600019019061125f565b634e487b7160e01b82526011600452602482fd5b634e487b7160e01b83526032600452602483fd5b634e487b7160e01b81526032600452602490fd5b634e487b7160e01b82526032600452602482fd5b6000906113556042610c19565b916113636040519384610be1565b604283526113716042610c19565b6020840190601f19013682378351156113345760309053825160011015611320576078602184015350604160005b600182116113b05750506112705790565b9091600f8116601081101561130c576f181899199a1a9b1b9c1cb0b131b232b360811b901a6113df84866111f7565b5360041c9180156112f857600019019061139f565b7f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a084116114745760209360009360ff60809460405194855216868401526040830152606082015282805260015afa15611468576000516001600160a01b0381161561145f5790600090565b50600090600190565b6040513d6000823e3d90fd5b5050505060009060039056fea26469706673582212209226e9ab0cf04c3cc554edfe8a757199d0ba75917eb0c4f4b56b3aac4eb8251464736f6c634300081e0033
Verified Source Code Full Match
Compiler: v0.8.30+commit.73712a01
EVM: paris
Optimization: Yes (200 runs)
AccessControl.sol 248 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Strings.sol 85 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
ECDSA.sol 217 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV // Deprecated in v4.8
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, hash)
message := keccak256(0x00, 0x3c)
}
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, "\x19\x01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
data := keccak256(ptr, 0x42)
}
}
/**
* @dev Returns an Ethereum Signed Data with intended validator, created from a
* `validator` and `data` according to the version 0 of EIP-191.
*
* See {recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x00", validator, data));
}
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Math.sol 339 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
SignedMath.sol 43 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
HumanIDPayments.sol 326 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
/**
* @title HumanIDPayments
* @notice Part of the Human ID payment system
*/
contract HumanIDPayments is AccessControl {
using ECDSA for bytes32;
// Custom errors
error InvalidOracleAddress();
error PaymentAlreadyExists();
error InvalidAmount();
error TimestampInFuture();
error SignatureTooOld();
error InvalidSignature();
error PaymentDoesNotExist();
error AlreadyRefunded();
error TransferFailed();
error InsufficientBalance();
error InvalidRecipient();
error NoBalanceToWithdraw();
error MustSendETH();
error EmptyBatch();
error ArrayLengthMismatch();
error IncorrectTotalAmount();
// Roles
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
// Payment struct
struct Payment {
bytes32 commitment;
bytes32 service;
uint256 timestamp;
address sender;
uint256 amount;
bool refunded;
}
// State variables
mapping(bytes32 => Payment) public payments;
address public oracleAddress;
// Events
event PaymentReceived(
bytes32 indexed commitment,
address indexed sender,
uint256 amount,
bytes32 service,
uint256 timestamp
);
event RefundIssued(
bytes32 indexed commitment,
address indexed recipient,
uint256 amount
);
event RefundIssuedByAdmin(
bytes32 indexed commitment,
address indexed recipient,
uint256 amount
);
event AdminWithdrawal(
address indexed admin,
address indexed to,
uint256 amount
);
event OracleUpdated(
address indexed oldOracle,
address indexed newOracle
);
event FundsDeposited(
address indexed sender,
uint256 amount
);
/**
* @notice Constructor
* @param _oracleAddress Address of the oracle that signs payment and refund requests
*/
constructor(address _oracleAddress) {
if (_oracleAddress == address(0)) revert InvalidOracleAddress();
oracleAddress = _oracleAddress;
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(ADMIN_ROLE, msg.sender);
}
/**
* @notice Make a payment for a service using a commitment
* @param commitment The commitment hash (user's secret)
* @param service The service identifier
* @param timestamp The timestamp from the signature
* @param signature oracle's EIP-191 signature of the payment
*/
function pay(
bytes32 commitment,
bytes32 service,
uint256 timestamp,
bytes memory signature
) external payable {
_processPayment(commitment, service, msg.value, timestamp, signature);
}
/**
* @notice Make multiple payments in a single transaction
* @param commitments Array of commitment hashes
* @param services Array of service identifiers
* @param amounts Array of payment amounts
* @param timestamps Array of timestamps from signatures
* @param signatures Array of oracle's EIP-191 signatures
*/
function batchPay(
bytes32[] calldata commitments,
bytes32[] calldata services,
uint256[] calldata amounts,
uint256[] calldata timestamps,
bytes[] calldata signatures
) external payable {
uint256 length = commitments.length;
// Validate arrays
if (length == 0) revert EmptyBatch();
if (services.length != length || amounts.length != length ||
timestamps.length != length || signatures.length != length) {
revert ArrayLengthMismatch();
}
// Verify total amount matches msg.value
uint256 totalAmount = 0;
for (uint256 i = 0; i < length; i++) {
totalAmount += amounts[i];
}
if (msg.value != totalAmount) revert IncorrectTotalAmount();
// Process each payment
for (uint256 i = 0; i < length; i++) {
_processPayment(commitments[i], services[i], amounts[i], timestamps[i], signatures[i]);
}
}
/**
* @notice Internal function to process a single payment
* @param commitment The commitment hash
* @param service The service identifier
* @param amount The payment amount
* @param timestamp The timestamp from the signature
* @param signature Oracle's EIP-191 signature
*/
function _processPayment(
bytes32 commitment,
bytes32 service,
uint256 amount,
uint256 timestamp,
bytes memory signature
) internal {
// Validate amount
if (amount == 0) revert InvalidAmount();
// Check payment doesn't already exist
if (payments[commitment].amount != 0) revert PaymentAlreadyExists();
// Verify timestamp is within the last year. Why so long? Companies might want to use batch payments to pay
// for their users over a longer period of time (e.g. a month). We should be able to support this.
if (timestamp > block.timestamp) revert TimestampInFuture();
if (block.timestamp - timestamp > 365 days) revert SignatureTooOld();
// Verify EIP-191 signature from oracle
bytes32 messageHash = keccak256(
abi.encode(amount, commitment, service, block.chainid, timestamp)
);
address signer = messageHash.toEthSignedMessageHash().recover(signature);
if (signer != oracleAddress) revert InvalidSignature();
// Store payment
payments[commitment] = Payment({
commitment: commitment,
service: service,
timestamp: block.timestamp,
sender: msg.sender,
amount: amount,
refunded: false
});
emit PaymentReceived(commitment, msg.sender, amount, service, block.timestamp);
}
/**
* @notice Refund a payment using oracle signature
* @param commitment The commitment hash
* @param timestamp The timestamp from the signature
* @param signature oracle's EIP-191 signature authorizing the refund
* @dev REENTRANCY NOTICE: This function is protected by CEI pattern.
* payment.refunded is set before external call. DO NOT add functions
* that can modify payment state without reentrancy protection.
*/
function refund(bytes32 commitment, uint256 timestamp, bytes memory signature) external {
Payment storage payment = payments[commitment];
if (payment.amount == 0) revert PaymentDoesNotExist();
if (payment.refunded) revert AlreadyRefunded();
// Verify timestamp is within the last year
if (timestamp > block.timestamp) revert TimestampInFuture();
if (block.timestamp - timestamp > 10 minutes) revert SignatureTooOld();
// Verify EIP-191 refund signature from oracle
bytes32 messageHash = keccak256(abi.encode(commitment, block.chainid, timestamp));
address signer = messageHash.toEthSignedMessageHash().recover(signature);
if (signer != oracleAddress) revert InvalidSignature();
// Mark as refunded and send funds
payment.refunded = true;
(bool success, ) = payment.sender.call{value: payment.amount}("");
if (!success) revert TransferFailed();
emit RefundIssued(commitment, payment.sender, payment.amount);
}
/**
* @notice Get contract balance
* @return Current balance in wei
*/
function getBalance() external view returns (uint256) {
return address(this).balance;
}
/**
* @notice Deposit funds into contract (useful for maintaining refund reserves)
*/
function deposit() external payable {
if (msg.value == 0) revert MustSendETH();
emit FundsDeposited(msg.sender, msg.value);
}
/**
* @notice Receive function for direct ETH transfers
*/
receive() external payable {
emit FundsDeposited(msg.sender, msg.value);
}
// ---------------------------------------------------------------------
// Admin functions.
//
// A note about our design decisions:
// Admins are granted significant authority. While this is potentially
// risky, we do not consider it a problem here. Why? This contract is
// not meant to handle significant amounts of funds. The actual amount
// of money in this contract at any point in time should be just enough
// to handle refunds. All funds are regularly swept into more secure
// wallets. If one of the admin accounts were compromised, we would
// simply deploy a new contract with new admins and update our frontend.
// ---------------------------------------------------------------------
/**
* @notice Force refund a payment (admin only, for customer support)
* @param commitment The commitment hash to refund
*/
function forceRefund(bytes32 commitment) external onlyRole(ADMIN_ROLE) {
Payment storage payment = payments[commitment];
if (payment.amount == 0) revert PaymentDoesNotExist();
if (payment.refunded) revert AlreadyRefunded();
// Mark as refunded and send funds
payment.refunded = true;
(bool success, ) = payment.sender.call{value: payment.amount}("");
if (!success) revert TransferFailed();
emit RefundIssuedByAdmin(commitment, payment.sender, payment.amount);
}
/**
* @notice Withdraw specific amount to admin (admin only)
* @param amount Amount to withdraw
*/
function withdraw(uint256 amount) external onlyRole(ADMIN_ROLE) {
if (amount > address(this).balance) revert InsufficientBalance();
(bool success, ) = msg.sender.call{value: amount}("");
if (!success) revert TransferFailed();
emit AdminWithdrawal(msg.sender, msg.sender, amount);
}
/**
* @notice Withdraw specific amount to specified address (admin only)
* @param amount Amount to withdraw
* @param to Recipient address
*/
function withdrawTo(uint256 amount, address payable to) external onlyRole(ADMIN_ROLE) {
if (to == address(0)) revert InvalidRecipient();
if (amount > address(this).balance) revert InsufficientBalance();
(bool success, ) = to.call{value: amount}("");
if (!success) revert TransferFailed();
emit AdminWithdrawal(msg.sender, to, amount);
}
/**
* @notice Withdraw all funds to admin (admin only)
*/
function withdrawAll() external onlyRole(ADMIN_ROLE) {
uint256 amount = address(this).balance;
if (amount == 0) revert NoBalanceToWithdraw();
(bool success, ) = msg.sender.call{value: amount}("");
if (!success) revert TransferFailed();
emit AdminWithdrawal(msg.sender, msg.sender, amount);
}
/**
* @notice Update oracle address (admin only)
* @param newOracle New oracle address
*/
function setOracleAddress(address newOracle) external onlyRole(ADMIN_ROLE) {
if (newOracle == address(0)) revert InvalidOracleAddress();
address oldOracle = oracleAddress;
oracleAddress = newOracle;
emit OracleUpdated(oldOracle, newOracle);
}
}
Read Contract
ADMIN_ROLE 0x75b238fc → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
getBalance 0x12065fe0 → uint256
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
oracleAddress 0xa89ae4ba → address
payments 0x0716326d → bytes32, bytes32, uint256, address, uint256, bool
supportsInterface 0x01ffc9a7 → bool
Write Contract 12 functions
These functions modify contract state and require a wallet transaction to execute.
batchPay 0xa2359af9
bytes32[] commitments
bytes32[] services
uint256[] amounts
uint256[] timestamps
bytes[] signatures
deposit 0xd0e30db0
No parameters
forceRefund 0x3b6db66f
bytes32 commitment
grantRole 0x2f2ff15d
bytes32 role
address account
pay 0x492f9024
bytes32 commitment
bytes32 service
uint256 timestamp
bytes signature
refund 0x6d955b24
bytes32 commitment
uint256 timestamp
bytes signature
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setOracleAddress 0x4c69c00f
address newOracle
withdraw 0x2e1a7d4d
uint256 amount
withdrawAll 0x853828b6
No parameters
withdrawTo 0xc86283c8
uint256 amount
address to
Recent Transactions
No transactions found for this address