Skip to content

Commit

Permalink
Split BytecodeStorage into public/internal libraries (#684)
Browse files Browse the repository at this point in the history
* basic MVP of split library (with tests)

* Adjusted tests for split library setup

* minor modifier adjustment

* Adjust optimizer runs

* optimizer order

* nit

* get interface from deployed contract

* get interface from deployed contract

* ensure libraries are linked

* library linkkinnnn

* More linking fixes in tests

* update Engine Flex as PoC (#688)

* fix the rest of the test bindingsgit diff

* OPTIMIZOOOOOR

* remove unnecessary using for

* Fixed comment

* public constants

* Update library naming convention

* DEPLOYOOOOOR

* DEPLOYOOOOOR

* format

* Address nits

---------

Co-authored-by: ryley-o <30364988+ryley-o@users.noreply.github.com>
  • Loading branch information
jakerockland and ryley-o authored May 5, 2023
1 parent b2c121c commit 3122452
Show file tree
Hide file tree
Showing 33 changed files with 808 additions and 282 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ erDiagram
ADMIN_ACL ||--o{ CORE_V3_V3_FLEX : manages
ADMIN_ACL ||--o{ MINTERFILTER : manages
CORE_V3_V3_FLEX ||--|| MINTERFILTER : uses
CORE_V3_V3_FLEX }o--|| BYTECODESTORAGEREADER : uses
MINTERFILTER ||--o{ MINTER_1 : uses
MINTERFILTER ||--o{ MINTER_2 : uses
MINTERFILTER ||--o{ MINTER_N : uses
Expand Down Expand Up @@ -141,6 +142,15 @@ The following represents the current set of flagship core contracts deployed on

For deployed core contracts, see the deployment details in the `/deployments/engine/[V2|V3]/<engine-partner>/` directories. For V2 core contracts, archived source code is available in the `/posterity/engine/` directory.

## BytecodeStorageReader

BytecodeStorageReader (currently on V1 version) is public library for reading from storage contracts. This library is intended to be deployed as a standalone contract, and provides all _read_ functionality by being used as an externally linked library within the Art Blocks ecosystem contracts that use contract storage for writes.

Given that it is an externally linked library with a shared public deployment, the deployment addresses for these shared deployments are referenced in our shared deployments `constants.ts` util (in the `BYTECODE_STORAGE_READER_LIBRARY_ADDRESSES` constant) so that they may be linked at time of deployment and are also linked here below for shared reference:

- V1 `BytecodeStorageReader` (goerli): https://goerli.etherscan.io/address/0xB8B806A10d16cc80dB788552B54B3ECb4A2A3C3D#code
- V1 `BytecodeStorageReader` (mainnet): https://etherscan.io/address/0xf0585dF582A0ad119F1616FB82f3b449a98EeCd5#code

## Minter Suite

For details on the Flagship and Engine Minter Suite, see the [minter suite documenation](./MINTER_SUITE.md).
Expand Down
15 changes: 12 additions & 3 deletions contracts/DependencyRegistryV0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ contract DependencyRegistryV0 is
OwnableUpgradeable,
IDependencyRegistryV0
{
using BytecodeStorage for string;
using BytecodeStorage for address;
using BytecodeStorageWriter for string;
using Bytes32Strings for bytes32;
using Strings for uint256;
using EnumerableSet for EnumerableSet.Bytes32Set;
Expand Down Expand Up @@ -735,7 +734,7 @@ contract DependencyRegistryV0 is
return "";
}

return dependency.scriptBytecodeAddresses[_index].readFromBytecode();
return _readFromBytecode(dependency.scriptBytecodeAddresses[_index]);
}

/**
Expand Down Expand Up @@ -829,4 +828,14 @@ contract DependencyRegistryV0 is
OwnableUpgradeable._transferOwnership(newOwner);
adminACLContract = IAdminACLV0(newOwner);
}

/**
* Helper for calling `BytecodeStorageReader` external library reader method,
* added for bytecode size reduction purposes.
*/
function _readFromBytecode(
address _address
) internal view returns (string memory) {
return BytecodeStorageReader.readFromBytecode(_address);
}
}
15 changes: 12 additions & 3 deletions contracts/GenArt721CoreV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ contract GenArt721CoreV3 is
IGenArt721CoreContractV3,
IGenArt721CoreContractExposesHashSeed
{
using BytecodeStorage for string;
using BytecodeStorage for address;
using BytecodeStorageWriter for string;
using Bytes32Strings for bytes32;
using Strings for uint256;
uint256 constant ONE_HUNDRED = 100;
Expand Down Expand Up @@ -1493,7 +1492,7 @@ contract GenArt721CoreV3 is
if (_index >= project.scriptCount) {
return "";
}
return project.scriptBytecodeAddresses[_index].readFromBytecode();
return _readFromBytecode(project.scriptBytecodeAddresses[_index]);
}

/**
Expand Down Expand Up @@ -1945,4 +1944,14 @@ contract GenArt721CoreV3 is
(block.timestamp - projectCompletedTimestamp <
FOUR_WEEKS_IN_SECONDS);
}

/**
* Helper for calling `BytecodeStorageReader` external library reader method,
* added for bytecode size reduction purposes.
*/
function _readFromBytecode(
address _address
) internal view returns (string memory) {
return BytecodeStorageReader.readFromBytecode(_address);
}
}
15 changes: 12 additions & 3 deletions contracts/engine/V3/GenArt721CoreV3_Engine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ contract GenArt721CoreV3_Engine is
IGenArt721CoreContractV3_Engine,
IGenArt721CoreContractExposesHashSeed
{
using BytecodeStorage for string;
using BytecodeStorage for address;
using BytecodeStorageWriter for string;
using Bytes32Strings for bytes32;
using Strings for uint256;
using Strings for address;
Expand Down Expand Up @@ -1577,7 +1576,7 @@ contract GenArt721CoreV3_Engine is
if (_index >= project.scriptCount) {
return "";
}
return project.scriptBytecodeAddresses[_index].readFromBytecode();
return _readFromBytecode(project.scriptBytecodeAddresses[_index]);
}

/**
Expand Down Expand Up @@ -1996,4 +1995,14 @@ contract GenArt721CoreV3_Engine is
(block.timestamp - projectCompletedTimestamp <
FOUR_WEEKS_IN_SECONDS);
}

/**
* Helper for calling `BytecodeStorageReader` external library reader method,
* added for bytecode size reduction purposes.
*/
function _readFromBytecode(
address _address
) internal view returns (string memory) {
return BytecodeStorageReader.readFromBytecode(_address);
}
}
17 changes: 13 additions & 4 deletions contracts/engine/V3/GenArt721CoreV3_Engine_Flex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ contract GenArt721CoreV3_Engine_Flex is
IGenArt721CoreContractV3_Engine_Flex,
IGenArt721CoreContractExposesHashSeed
{
using BytecodeStorage for string;
using BytecodeStorage for address;
using BytecodeStorageWriter for string;
using Bytes32Strings for bytes32;
uint256 constant ONE_HUNDRED = 100;
uint256 constant ONE_MILLION = 1_000_000;
Expand Down Expand Up @@ -1763,7 +1762,7 @@ contract GenArt721CoreV3_Engine_Flex is
if (_index >= project.scriptCount) {
return "";
}
return project.scriptBytecodeAddresses[_index].readFromBytecode();
return _readFromBytecode(project.scriptBytecodeAddresses[_index]);
}

/**
Expand Down Expand Up @@ -1994,7 +1993,7 @@ contract GenArt721CoreV3_Engine_Flex is
bytecodeAddress: _bytecodeAddress,
data: (_dependency.dependencyType ==
ExternalAssetDependencyType.ONCHAIN)
? _bytecodeAddress.readFromBytecode()
? _readFromBytecode(_bytecodeAddress)
: ""
});
}
Expand Down Expand Up @@ -2217,6 +2216,16 @@ contract GenArt721CoreV3_Engine_Flex is
FOUR_WEEKS_IN_SECONDS);
}

/**
* Helper for calling `BytecodeStorageReader` external library reader method,
* added for bytecode size reduction purposes.
*/
function _readFromBytecode(
address _address
) internal view returns (string memory) {
return BytecodeStorageReader.readFromBytecode(_address);
}

// strings library from OpenZeppelin, modified for no constants

bytes16 private _HEX_SYMBOLS = "0123456789abcdef";
Expand Down
17 changes: 13 additions & 4 deletions contracts/engine/V3/forks/GenArt721CoreV3_Engine_Flex_PROOF.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ contract GenArt721CoreV3_Engine_Flex_PROOF is
IManifold,
IGenArt721CoreContractV3_Engine_Flex
{
using BytecodeStorage for string;
using BytecodeStorage for address;
using BytecodeStorageWriter for string;
using Bytes32Strings for bytes32;

uint256 constant ONE_HUNDRED = 100;
Expand Down Expand Up @@ -1773,7 +1772,7 @@ contract GenArt721CoreV3_Engine_Flex_PROOF is
if (_index >= project.scriptCount) {
return "";
}
return project.scriptBytecodeAddresses[_index].readFromBytecode();
return _readFromBytecode(project.scriptBytecodeAddresses[_index]);
}

/**
Expand Down Expand Up @@ -2004,7 +2003,7 @@ contract GenArt721CoreV3_Engine_Flex_PROOF is
bytecodeAddress: _bytecodeAddress,
data: (_dependency.dependencyType ==
ExternalAssetDependencyType.ONCHAIN)
? _bytecodeAddress.readFromBytecode()
? _readFromBytecode(_bytecodeAddress)
: ""
});
}
Expand Down Expand Up @@ -2227,6 +2226,16 @@ contract GenArt721CoreV3_Engine_Flex_PROOF is
FOUR_WEEKS_IN_SECONDS);
}

/**
* Helper for calling `BytecodeStorageReader` external library reader method,
* added for bytecode size reduction purposes.
*/
function _readFromBytecode(
address _address
) internal view returns (string memory) {
return BytecodeStorageReader.readFromBytecode(_address);
}

// strings library from OpenZeppelin, modified for no constants

bytes16 private _HEX_SYMBOLS = "0123456789abcdef";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ contract GenArt721CoreV3_Engine_Flex_PROHIBITION is
IManifold,
IGenArt721CoreContractV3_Engine_Flex_PROHIBITION
{
using BytecodeStorage for string;
using BytecodeStorage for address;
using BytecodeStorageWriter for string;
using Bytes32Strings for bytes32;
uint256 constant ONE_HUNDRED = 100;
uint256 constant ONE_MILLION = 1_000_000;
Expand Down Expand Up @@ -1781,7 +1780,7 @@ contract GenArt721CoreV3_Engine_Flex_PROHIBITION is
if (_index >= project.scriptCount) {
return "";
}
return project.scriptBytecodeAddresses[_index].readFromBytecode();
return _readFromBytecode(project.scriptBytecodeAddresses[_index]);
}

/**
Expand Down Expand Up @@ -2012,7 +2011,7 @@ contract GenArt721CoreV3_Engine_Flex_PROHIBITION is
bytecodeAddress: _bytecodeAddress,
data: (_dependency.dependencyType ==
ExternalAssetDependencyType.ONCHAIN)
? _bytecodeAddress.readFromBytecode()
? _readFromBytecode(_bytecodeAddress)
: ""
});
}
Expand Down Expand Up @@ -2276,6 +2275,16 @@ contract GenArt721CoreV3_Engine_Flex_PROHIBITION is
FOUR_WEEKS_IN_SECONDS);
}

/**
* Helper for calling `BytecodeStorageReader` external library reader method,
* added for bytecode size reduction purposes.
*/
function _readFromBytecode(
address _address
) internal view returns (string memory) {
return BytecodeStorageReader.readFromBytecode(_address);
}

// strings library from OpenZeppelin, modified for no constants

bytes16 private _HEX_SYMBOLS = "0123456789abcdef";
Expand Down
15 changes: 12 additions & 3 deletions contracts/explorations/GenArt721CoreV3_Explorations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ contract GenArt721CoreV3_Explorations is
IGenArt721CoreContractV3,
IGenArt721CoreContractExposesHashSeed
{
using BytecodeStorage for string;
using BytecodeStorage for address;
using BytecodeStorageWriter for string;
using Bytes32Strings for bytes32;
using Strings for uint256;
using Strings for address;
Expand Down Expand Up @@ -1499,7 +1498,7 @@ contract GenArt721CoreV3_Explorations is
if (_index >= project.scriptCount) {
return "";
}
return project.scriptBytecodeAddresses[_index].readFromBytecode();
return _readFromBytecode(project.scriptBytecodeAddresses[_index]);
}

/**
Expand Down Expand Up @@ -1951,4 +1950,14 @@ contract GenArt721CoreV3_Explorations is
(block.timestamp - projectCompletedTimestamp <
FOUR_WEEKS_IN_SECONDS);
}

/**
* Helper for calling `BytecodeStorageReader` external library reader method,
* added for bytecode size reduction purposes.
*/
function _readFromBytecode(
address _address
) internal view returns (string memory) {
return BytecodeStorageReader.readFromBytecode(_address);
}
}
Loading

0 comments on commit 3122452

Please sign in to comment.