Skip to content

Commit 30df2e5

Browse files
authored
fix: remove payable from external functions where it was used to save gas (#145)
1 parent 574e5d9 commit 30df2e5

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

Diff for: .gas-snapshot

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
BundleRegistryGasUsageTest:testGasRegister() (gas: 1882173)
2-
BundleRegistryGasUsageTest:testGasTrustedRegister() (gas: 1747817)
3-
IdRegistryGasUsageTest:testGasRegisterAndRecover() (gas: 2078840)
4-
IdRegistryGasUsageTest:testGasRegisterFromTrustedCaller() (gas: 839504)
5-
NameRegistryGasUsageTest:testGasRegister() (gas: 2119333)
6-
NameRegistryGasUsageTest:testGasTrustedRegister() (gas: 1122592)
1+
BundleRegistryGasUsageTest:testGasRegister() (gas: 1882701)
2+
BundleRegistryGasUsageTest:testGasTrustedRegister() (gas: 1748537)
3+
IdRegistryGasUsageTest:testGasRegisterAndRecover() (gas: 2081451)
4+
IdRegistryGasUsageTest:testGasRegisterFromTrustedCaller() (gas: 840128)
5+
NameRegistryGasUsageTest:testGasRegister() (gas: 2119544)
6+
NameRegistryGasUsageTest:testGasTrustedRegister() (gas: 1122616)

Diff for: src/IdRegistry.sol

+10-10
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ contract IdRegistry is ERC2771Context, Ownable {
194194
address to,
195195
address recovery,
196196
string calldata url
197-
) external payable {
197+
) external {
198198
// Perf: Don't check to == address(0) to save 29 gas since 0x0 can only register 1 fid
199199

200200
if (trustedOnly == 1) revert Invitable();
@@ -217,7 +217,7 @@ contract IdRegistry is ERC2771Context, Ownable {
217217
address to,
218218
address recovery,
219219
string calldata url
220-
) external payable {
220+
) external {
221221
// Perf: Don't check to == address(0) to save 29 gas since 0x0 can only register 1 fid
222222

223223
if (trustedOnly == 0) revert Registrable();
@@ -238,7 +238,7 @@ contract IdRegistry is ERC2771Context, Ownable {
238238
*
239239
* @param url The new home url for the fid
240240
*/
241-
function changeHome(string calldata url) external payable {
241+
function changeHome(string calldata url) external {
242242
uint256 id = idOf[_msgSender()];
243243
if (id == 0) revert HasNoId();
244244

@@ -272,7 +272,7 @@ contract IdRegistry is ERC2771Context, Ownable {
272272
*
273273
* @param to The address to transfer the fid to.
274274
*/
275-
function transfer(address to) external payable {
275+
function transfer(address to) external {
276276
address sender = _msgSender();
277277
uint256 id = idOf[sender];
278278

@@ -342,7 +342,7 @@ contract IdRegistry is ERC2771Context, Ownable {
342342
*
343343
* @param recovery The address which can recover the fid (set to 0x0 to disable recovery)
344344
*/
345-
function changeRecoveryAddress(address recovery) external payable {
345+
function changeRecoveryAddress(address recovery) external {
346346
uint256 id = idOf[_msgSender()];
347347
if (id == 0) revert HasNoId();
348348

@@ -362,7 +362,7 @@ contract IdRegistry is ERC2771Context, Ownable {
362362
* @param from The address that owns the fid
363363
* @param to The address where the fid should be sent
364364
*/
365-
function requestRecovery(address from, address to) external payable {
365+
function requestRecovery(address from, address to) external {
366366
uint256 id = idOf[from];
367367
if (_msgSender() != recoveryOf[id]) revert Unauthorized();
368368

@@ -384,7 +384,7 @@ contract IdRegistry is ERC2771Context, Ownable {
384384
*
385385
* @param from The address that owns the id.
386386
*/
387-
function completeRecovery(address from) external payable {
387+
function completeRecovery(address from) external {
388388
uint256 id = idOf[from];
389389

390390
if (_msgSender() != recoveryOf[id]) revert Unauthorized();
@@ -415,7 +415,7 @@ contract IdRegistry is ERC2771Context, Ownable {
415415
*
416416
* @param from The address that owns the id.
417417
*/
418-
function cancelRecovery(address from) external payable {
418+
function cancelRecovery(address from) external {
419419
uint256 id = idOf[from];
420420
address sender = _msgSender();
421421

@@ -442,7 +442,7 @@ contract IdRegistry is ERC2771Context, Ownable {
442442
*
443443
* @param _trustedCaller The address of the new trusted caller
444444
*/
445-
function changeTrustedCaller(address _trustedCaller) external payable onlyOwner {
445+
function changeTrustedCaller(address _trustedCaller) external onlyOwner {
446446
trustedCaller = _trustedCaller;
447447
emit ChangeTrustedCaller(_trustedCaller);
448448
}
@@ -451,7 +451,7 @@ contract IdRegistry is ERC2771Context, Ownable {
451451
* @notice Disable trustedRegister() and let anyone get an fid by calling register(). This must
452452
* be called by the contract's owner.
453453
*/
454-
function disableTrustedOnly() external payable onlyOwner {
454+
function disableTrustedOnly() external onlyOwner {
455455
delete trustedOnly;
456456
emit DisableTrustedOnly();
457457
}

Diff for: src/NameRegistry.sol

+13-13
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ contract NameRegistry is
388388
*
389389
* @param commit The commitment hash to be persisted on-chain
390390
*/
391-
function makeCommit(bytes32 commit) external payable {
391+
function makeCommit(bytes32 commit) external {
392392
if (trustedOnly == 1) revert Invitable();
393393

394394
unchecked {
@@ -818,7 +818,7 @@ contract NameRegistry is
818818
* @param tokenId The uint256 representation of the fname
819819
* @param recovery The address which can recover the fname (set to 0x0 to disable recovery)
820820
*/
821-
function changeRecoveryAddress(uint256 tokenId, address recovery) external payable whenNotPaused {
821+
function changeRecoveryAddress(uint256 tokenId, address recovery) external whenNotPaused {
822822
if (ownerOf(tokenId) != _msgSender()) revert Unauthorized();
823823

824824
recoveryOf[tokenId] = recovery;
@@ -838,7 +838,7 @@ contract NameRegistry is
838838
* @param tokenId The uint256 representation of the fname
839839
* @param to The address to transfer the fname to, which cannot be address(0)
840840
*/
841-
function requestRecovery(uint256 tokenId, address to) external payable whenNotPaused {
841+
function requestRecovery(uint256 tokenId, address to) external whenNotPaused {
842842
if (to == address(0)) revert InvalidRecovery();
843843

844844
// Invariant 3 ensures that a request cannot be made after ownership change without consent
@@ -865,7 +865,7 @@ contract NameRegistry is
865865
*
866866
* @param tokenId The uint256 representation of the fname
867867
*/
868-
function completeRecovery(uint256 tokenId) external payable {
868+
function completeRecovery(uint256 tokenId) external {
869869
if (block.timestamp >= expiryOf[tokenId]) revert Expired();
870870

871871
// Invariant 3 ensures that a request cannot be completed after ownership change without consent
@@ -890,7 +890,7 @@ contract NameRegistry is
890890
*
891891
* @param tokenId The uint256 representation of the fname
892892
*/
893-
function cancelRecovery(uint256 tokenId) external payable {
893+
function cancelRecovery(uint256 tokenId) external {
894894
address sender = _msgSender();
895895

896896
// Perf: super.ownerOf is called instead of ownerOf since cancellation has no undesirable
@@ -945,7 +945,7 @@ contract NameRegistry is
945945
*
946946
* @param _trustedCaller The address of the new trusted caller
947947
*/
948-
function changeTrustedCaller(address _trustedCaller) external payable {
948+
function changeTrustedCaller(address _trustedCaller) external {
949949
// avoid _msgSender() since meta-tx are unnecessary here and increase attack surface area
950950
if (!hasRole(ADMIN_ROLE, msg.sender)) revert NotAdmin();
951951
trustedCaller = _trustedCaller;
@@ -955,7 +955,7 @@ contract NameRegistry is
955955
/**
956956
* @notice Disables registerTrusted and enables register calls from any address.
957957
*/
958-
function disableTrustedOnly() external payable {
958+
function disableTrustedOnly() external {
959959
// avoid _msgSender() since meta-tx are unnecessary here and increase attack surface area
960960
if (!hasRole(ADMIN_ROLE, msg.sender)) revert NotAdmin();
961961
delete trustedOnly;
@@ -967,7 +967,7 @@ contract NameRegistry is
967967
*
968968
* @param _vault The address of the new vault
969969
*/
970-
function changeVault(address _vault) external payable {
970+
function changeVault(address _vault) external {
971971
// avoid _msgSender() since meta-tx are unnecessary here and increase attack surface area
972972
if (!hasRole(ADMIN_ROLE, msg.sender)) revert NotAdmin();
973973
vault = _vault;
@@ -979,7 +979,7 @@ contract NameRegistry is
979979
*
980980
* @param _pool The address of the new pool
981981
*/
982-
function changePool(address _pool) external payable {
982+
function changePool(address _pool) external {
983983
// avoid _msgSender() since meta-tx are unnecessary here and increase attack surface area
984984
if (!hasRole(ADMIN_ROLE, msg.sender)) revert NotAdmin();
985985
pool = _pool;
@@ -995,7 +995,7 @@ contract NameRegistry is
995995
*
996996
* @param _fee The new yearly fee
997997
*/
998-
function changeFee(uint256 _fee) external payable {
998+
function changeFee(uint256 _fee) external {
999999
// avoid _msgSender() since meta-tx are unnecessary here and increase attack surface area
10001000
if (!hasRole(TREASURER_ROLE, msg.sender)) revert NotTreasurer();
10011001

@@ -1009,7 +1009,7 @@ contract NameRegistry is
10091009
*
10101010
* @param amount The amount of ether to withdraw
10111011
*/
1012-
function withdraw(uint256 amount) external payable {
1012+
function withdraw(uint256 amount) external {
10131013
// avoid _msgSender() since meta-tx are unnecessary here and increase attack surface area
10141014
if (!hasRole(TREASURER_ROLE, msg.sender)) revert NotTreasurer();
10151015

@@ -1028,7 +1028,7 @@ contract NameRegistry is
10281028
/**
10291029
* @notice pause the contract and prevent registrations, renewals, recoveries and transfers of names.
10301030
*/
1031-
function pause() external payable {
1031+
function pause() external {
10321032
// avoid _msgSender() since meta-tx are unnecessary here and increase attack surface area
10331033
if (!hasRole(OPERATOR_ROLE, msg.sender)) revert NotOperator();
10341034
_pause();
@@ -1037,7 +1037,7 @@ contract NameRegistry is
10371037
/**
10381038
* @notice unpause the contract and resume registrations, renewals, recoveries and transfers of names.
10391039
*/
1040-
function unpause() external payable {
1040+
function unpause() external {
10411041
// avoid _msgSender() since meta-tx are unnecessary here and increase attack surface area
10421042
if (!hasRole(OPERATOR_ROLE, msg.sender)) revert NotOperator();
10431043
_unpause();

0 commit comments

Comments
 (0)