Skip to content

Commit

Permalink
test EIP-170 limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Aug 28, 2024
1 parent 054aa6a commit 959b36a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions contracts/proxy/Clones.sol
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ library Clones {
* `mcopy`. Unfortunately, that opcode is not available before cancun. A pure solidity implementation using
* abi.encodePacked is more expensive but also more portable and easier to review.
*
* NOTE: https://eips.ethereum.org/EIPS/eip-3860[EIP-3860] limits the length of the `initcode` to 49152 bytes.
* With the proxy code taking 45 bytes, that limits the length of the immutable args to 49107 bytes.
* NOTE: https://eips.ethereum.org/EIPS/eip-170[EIP-170] limits the length of the contract code to 24576 bytes.
* With the proxy code taking 45 bytes, that limits the length of the immutable args to 24531 bytes.
*/
function _cloneCodeWithImmutableArgs(
address implementation,
bytes memory args
) private pure returns (bytes memory) {
if (args.length > 49107) revert ImmutableArgsTooLarge();
if (args.length > 0x5fd3) revert ImmutableArgsTooLarge();
return
abi.encodePacked(
hex"61",
Expand Down
18 changes: 18 additions & 0 deletions test/proxy/Clones.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const { ethers } = require('hardhat');
const { expect } = require('chai');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');

const { generators } = require('../helpers/random');

const shouldBehaveLikeClone = require('./Clones.behaviour');

const cloneInitCode = (instance, args = undefined) =>
Expand Down Expand Up @@ -154,4 +156,20 @@ describe('Clones', function () {
});
});
}

it('EIP-170 limit on immutable args', async function () {
// EIP-170 limits the contract code size to 0x60000
// This limits the length of immutable args to 0x5fd3
const args = generators.hexBytes(0x5fd4);
const salt = ethers.randomBytes(32);

await expect(
this.factory.$predictDeterministicAddressWithImmutableArgs(this.implementation, args, salt),
).to.be.revertedWithCustomError(this.factory, 'ImmutableArgsTooLarge');

await expect(this.factory.$cloneWithImmutableArgs(this.implementation, args)).to.be.revertedWithCustomError(
this.factory,
'ImmutableArgsTooLarge',
);
});
});

0 comments on commit 959b36a

Please sign in to comment.