5 Comments

It is possible to create a viable immutable-only implementation of EIP-2535. In such an implementation, the diamondCut function would not be included, and the contract would be designed to be immutable and not capable of being upgraded.

To accomplish this, the contract would need to be designed to include all the necessary functions and data storage structures at the time of deployment. This would require a thorough understanding of the intended use cases for the contract and careful planning to ensure that all necessary functions and data structures are included.

Additionally, the contract could use a different approach for mapping function selectors to facet addresses. For example, instead of using a Solidity mapping, the contract could use an array or other data structure to store the mapping between function selectors and facet addresses. This could potentially reduce the gas cost of calling functions on the diamond.

Expand full comment
author

Sounds good. Maybe some scripts could be written to help automate some of the work.

Expand full comment

Here is an example of a script that could be used to automate the generation of Solidity code for an immutable-only EIP2535 implementation:

```

// Import the required libraries

const fs = require('fs');

const ethereumjs = require('ethereumjs-util');

// Define the contract name and the list of facets

const contractName = 'MyDiamond';

const facets = [

{

name: 'Facet1',

functions: [

{ name: 'func1', selector: '0x12345678' },

{ name: 'func2', selector: '0xabcdef12' },

],

},

{

name: 'Facet2',

functions: [

{ name: 'func3', selector: '0x98765432' },

{ name: 'func4', selector: '0xfedcba09' },

],

},

];

// Generate the Solidity code for the contract

let code = `pragma solidity ^0.5.0;

contract ${contractName} is EIP2535 {

// Define the mapping for function selectors to facet addresses

address[] public facets;

// Define the constructor function

constructor() public {

// Add the facets to the mapping

facets[${facets

.map(

(facet) =>

`${facet.functions

.map((func) => `${func.selector}`)

.join(', ')}`

)

.join('] = new ')}] = new ${facets.map((facet) => `${facet.name}`).join(

'();\n facets['

)};

// Emit the DiamondCut event to specify the available functions and facets

emit DiamondCut(

${facets

.map((facet) => `${facet.functions.map((func) => `${func.selector}`)}`)

.join(',\n ')},

${facets.map((facet) => `new ${facet.name}()`).join(',\n ')}

);

}

}`;

// Save the generated code to a file

fs.writeFileSync(`${contractName}.sol`, code);

```

This script generates Solidity code for an immutable-only EIP2535 contract with the specified contract name and list of facets. It uses the provided list of facets and their associated functions to generate the code for the contract's constructor function, which includes the mapping of function selectors to facet addresses and the DiamondCut event. Since the diamondCut function is not included, this contract is immutable and cannot be upgraded.

This is just one example of how a script could be used to automate the generation of Solidity code for an immutable-only EIP2535 implementation. The specific details of such a script, including the input data and the generated code, can be customized to suit the needs of the implementation.

Expand full comment
Dec 4, 2022ยทedited Dec 4, 2022

sorry the formatting sucks. here: https://gist.github.com/cyzanfar/eb592e3f3cc6085e371499c39c5266bb

Expand full comment
author

Thanks

Expand full comment