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

♻️ Rename LibRLP convenience functions #1070

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -790,26 +790,26 @@ LibPRNGTest:testPRNGShuffleGas() (gas: 1610927)
LibPRNGTest:testPRNGUniform() (gas: 559430)
LibPRNGTest:testStandardNormalWad() (gas: 4425913)
LibPRNGTest:test__codesize() (gas: 14420)
LibRLPTest:testComputeAddressDifferential(address,uint256) (runs: 325, μ: 4473, ~: 4291)
LibRLPTest:testComputeAddressDifferential(address,uint256) (runs: 325, μ: 4435, ~: 4287)
LibRLPTest:testComputeAddressForLargeNonces() (gas: 1760)
LibRLPTest:testComputeAddressForSmallNonces() (gas: 1007)
LibRLPTest:testComputeAddressOriginalForLargeNonces() (gas: 3766)
LibRLPTest:testComputeAddressOriginalForSmallNonces() (gas: 2185)
LibRLPTest:testRLPEncodeAddressDifferential(address) (runs: 325, μ: 234508, ~: 26224)
LibRLPTest:testRLPEncodeAddressViaList(address,address) (runs: 325, μ: 193006, ~: 28079)
LibRLPTest:testRLPEncodeAddressDifferential(address) (runs: 325, μ: 259410, ~: 26287)
LibRLPTest:testRLPEncodeAddressViaList(address,address) (runs: 325, μ: 151542, ~: 28016)
LibRLPTest:testRLPEncodeBool(bool) (runs: 325, μ: 27681, ~: 27818)
LibRLPTest:testRLPEncodeBytes() (gas: 382181)
LibRLPTest:testRLPEncodeBytes2() (gas: 156293)
LibRLPTest:testRLPEncodeBytesDifferential(bytes32) (runs: 325, μ: 275263, ~: 29815)
LibRLPTest:testRLPEncodeBytesDifferential(bytes32) (runs: 325, μ: 268614, ~: 29815)
LibRLPTest:testRLPEncodeList() (gas: 2738950)
LibRLPTest:testRLPEncodeList2() (gas: 803256)
LibRLPTest:testRLPEncodeListDifferential(bytes,uint256) (runs: 325, μ: 431157, ~: 39250)
LibRLPTest:testRLPEncodeListDifferential(bytes,uint256) (runs: 325, μ: 439934, ~: 645895)
LibRLPTest:testRLPEncodeUint() (gas: 1291481)
LibRLPTest:testRLPEncodeUint(uint256) (runs: 325, μ: 99409, ~: 24993)
LibRLPTest:testRLPEncodeUintDifferential(uint256) (runs: 325, μ: 258532, ~: 27097)
LibRLPTest:testRLPMemory(bytes32) (runs: 325, μ: 298767, ~: 33387)
LibRLPTest:testRLPEncodeUint(uint256) (runs: 325, μ: 106907, ~: 24956)
LibRLPTest:testRLPEncodeUintDifferential(uint256) (runs: 325, μ: 239049, ~: 27052)
LibRLPTest:testRLPMemory(bytes32) (runs: 325, μ: 328746, ~: 35782)
LibRLPTest:testRLPPUint256() (gas: 364901)
LibRLPTest:testSmallLog256Equivalence(uint256) (runs: 325, μ: 23678, ~: 23700)
LibRLPTest:testSmallLog256Equivalence(uint256) (runs: 325, μ: 23669, ~: 23700)
LibRLPTest:test__codesize() (gas: 15520)
LibSortTest:testClean(uint256) (runs: 325, μ: 3132, ~: 2891)
LibSortTest:testCopy(uint256) (runs: 325, μ: 69684, ~: 25754)
Expand Down
24 changes: 12 additions & 12 deletions src/utils/LibRLP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ library LibRLP {
/// (e.g. no dirty bits after packing / unpacking).
///
/// This is equivalent to:
/// `address(uint160(uint256(keccak256(LibRLP.l(deployer).p(nonce).encode()))))`.
/// `address(uint160(uint256(keccak256(LibRLP.p(deployer).p(nonce).encode()))))`.
///
/// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly.
function computeAddress(address deployer, uint256 nonce)
Expand Down Expand Up @@ -98,30 +98,30 @@ library LibRLP {
// with `abi.encodePacked(x)` before encoding.

/// @dev Returns a new empty list.
function l() internal pure returns (List memory result) {}
function p() internal pure returns (List memory result) {}

/// @dev Returns a new list with `x` as the only element. Equivalent to `LibRLP.l().p(x)`.
function l(uint256 x) internal pure returns (List memory result) {
/// @dev Returns a new list with `x` as the only element. Equivalent to `LibRLP.p().p(x)`.
function p(uint256 x) internal pure returns (List memory result) {
p(result, x);
}

/// @dev Returns a new list with `x` as the only element. Equivalent to `LibRLP.l().p(x)`.
function l(address x) internal pure returns (List memory result) {
/// @dev Returns a new list with `x` as the only element. Equivalent to `LibRLP.p().p(x)`.
function p(address x) internal pure returns (List memory result) {
p(result, x);
}

/// @dev Returns a new list with `x` as the only element. Equivalent to `LibRLP.l().p(x)`.
function l(bool x) internal pure returns (List memory result) {
/// @dev Returns a new list with `x` as the only element. Equivalent to `LibRLP.p().p(x)`.
function p(bool x) internal pure returns (List memory result) {
p(result, x);
}

/// @dev Returns a new list with `x` as the only element. Equivalent to `LibRLP.l().p(x)`.
function l(bytes memory x) internal pure returns (List memory result) {
/// @dev Returns a new list with `x` as the only element. Equivalent to `LibRLP.p().p(x)`.
function p(bytes memory x) internal pure returns (List memory result) {
p(result, x);
}

/// @dev Returns a new list with `x` as the only element. Equivalent to `LibRLP.l().p(x)`.
function l(List memory x) internal pure returns (List memory result) {
/// @dev Returns a new list with `x` as the only element. Equivalent to `LibRLP.p().p(x)`.
function p(List memory x) internal pure returns (List memory result) {
p(result, x);
}

Expand Down
16 changes: 8 additions & 8 deletions test/LibRLP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contract LibRLPTest is SoladyTest {
pure
returns (address)
{
return address(uint160(uint256(keccak256(LibRLP.l(deployer).p(nonce).encode()))));
return address(uint160(uint256(keccak256(LibRLP.p(deployer).p(nonce).encode()))));
}

function computeAddressOriginal(address deployer, uint256 nonce)
Expand Down Expand Up @@ -242,16 +242,16 @@ contract LibRLPTest is SoladyTest {

function testRLPEncodeAddressViaList(address a0, address a1) public {
_maybeBzztMemory();
bytes memory computed = LibRLP.l(_brutalized(a0)).p(_brutalized(a1)).encode();
bytes memory computed = LibRLP.p(_brutalized(a0)).p(_brutalized(a1)).encode();
_checkMemory(computed);
_maybeBzztMemory();
bytes memory expected = LibRLP.l(abi.encodePacked(a0)).p(abi.encodePacked(a1)).encode();
bytes memory expected = LibRLP.p(abi.encodePacked(a0)).p(abi.encodePacked(a1)).encode();
assertEq(computed, expected);
}

function testRLPEncodeListDifferential(bytes memory x0, uint256 x1) public {
_maybeBzztMemory();
LibRLP.List memory list = LibRLP.l(x0).p(x1).p(x1).p(x0);
LibRLP.List memory list = LibRLP.p(x0).p(x1).p(x1).p(x0);
_checkMemory(list);
_maybeBzztMemory();
bytes memory computed = LibRLP.encode(list);
Expand Down Expand Up @@ -304,7 +304,7 @@ contract LibRLPTest is SoladyTest {
bytes memory expected = bytes(x ? hex"01" : hex"80");
assertEq(computed, expected);
uint256 y = x ? 1 : 0;
assertEq(LibRLP.l(y).p(y ^ 1).p(y).encode(), LibRLP.l(x).p(!x).p(x).encode());
assertEq(LibRLP.p(y).p(y ^ 1).p(y).encode(), LibRLP.p(x).p(!x).p(x).encode());
}

function _maybeBzztMemory() internal {
Expand Down Expand Up @@ -476,11 +476,11 @@ contract LibRLPTest is SoladyTest {
LibRLP.List memory l;
_bzztMemory();
assertEq(LibRLP.encode(l), hex"c0");
l.p(LibRLP.l());
l.p(LibRLP.p());
_checkMemory(l);
l.p(LibRLP.l(LibRLP.l()));
l.p(LibRLP.p(LibRLP.p()));
_checkMemory(l);
l.p(LibRLP.l(LibRLP.l()).p(LibRLP.l(LibRLP.l())));
l.p(LibRLP.p(LibRLP.p()).p(LibRLP.p(LibRLP.p())));
_checkMemory(l);
_bzztMemory();
bytes memory computed = LibRLP.encode(l);
Expand Down