-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: implement CommunityTokenDeployer
contract
#2
Conversation
@gravityblast this is a first version that I've put up for early feedback. |
contracts/CommunityTokenDeployer.sol
Outdated
|| bytes(_masterToken.symbol).length == 0 || bytes(_masterToken.baseURI).length == 0 | ||
) { | ||
revert CommunityTokenDeployer_InvalidTokenMetadata(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although EIP721
token metadata is optional, I think it's still good to require it here as Status clients make heavy use of metadata.
contracts/CommunityTokenDeployer.sol
Outdated
function _verifySignature(DeploymentSignature calldata signature) internal view returns (bool) { | ||
bytes32 digest = _hashTypedDataV4( | ||
keccak256( | ||
abi.encode(DEPLOYMENT_SIGNATURE_TYPEHASH, signature.signer, signature.deployer, signature.deadline) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically, we'd want to maintain and a put a signer
nonce in here to protect against signature replay attacks.
However, we already ensure in earlier checks that only one contract can be deployed for a given community.
So if a signature was successfully used, even if it was used for a replay attack, the contract will throw an error.
address[] memory addresses = new address[](1); | ||
addresses[0] = msg.sender; | ||
// addresses[0] = msg.sender; | ||
addresses[0] = _receiver; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
msg.sender
will now be the CommunityTokenDeployer
contract, so we have to pass receiver
separately, which will be the deployer of the contracts.
4007ad6
to
94a80bb
Compare
94a80bb
to
4327202
Compare
CommunityTokenDeployer
contractCommunityTokenDeployer
contract
0ae5c28
to
f14b1f4
Compare
6fe5791
to
69eda28
Compare
f14b1f4
to
7f5d8f7
Compare
69eda28
to
74e0bb9
Compare
cd1e184
to
0c4e1d1
Compare
7f5d8f7
to
770e715
Compare
CI has uncovered an issue with this contract.
The issue is most likely that it includes the source of
I need to think about how to overcome this. One thing that comes to mind atm is that we use the Minimal Proxy Contract pattern, which would require separate deployment of Another option would be to look into other dependency sources and see if we can extract only the bits and pieces we need, however, if we look at the sizes of library dependencies we have (e.g A third option I see is exploring what shared functionality of |
770e715
to
e7e7221
Compare
Did a quick experiment and removed the dependency of I could reduce the contract size of
Tests are still green. In fact, I could remove a few for This was just a quick experiment and I'd like to double check this with @gravityblast before proposing these changes. Right now, even with the changes I've done |
Update: In another discussion with @3esmit, he threw in the option to introduce factory contracts for both This can then be combined with additional minimal contract proxy pattern to squeeze out more gas. Will explore these ideas and update the PR accordingly. |
Following up on the exploration described above, after introducing a factory for Factory contracts now carry the biggest baggage.
|
e7e7221
to
070ac11
Compare
@3esmit I've updated the pull request such that it includes a As described in the comment above, that alone enables us to get past the ~24kb contract size limit. I've added tests and docs accordingly. I'd appreciate if you could take a look here and leave any feedback you might have! |
b4aaee5
to
5f0974c
Compare
070ac11
to
77d8504
Compare
77d8504
to
b9e0ebc
Compare
Looking into using EIP1167 in the token factories to make deployment of tokens cheaper. Then I realized this conflicts with how the token contracts need to be initialized at the moment. For EIP1167 to work, we'll have to deploy Unless we want to rewrite how these tokens work completely, I'm not sure it makes sense to further pursue that idea. |
98912f0
to
c2f500c
Compare
61c79a5
to
0602ce4
Compare
LGTM! |
This commit introduces the `CommunityTokenDeployer` contract discussed in status-im/status-desktop#11954. The idea is that, instead of having accounts deploy `OwnerToken` and `MasterToken` directly, they'd use a deployer contract instead, which maintains a registry of known `OwnerToken` addresses, mapped to Status community addresses. The following changes have been made: It was, and still is, a requirement that both, `OwnerToken` and `MasterToken` are deployed within a single transaction, so that when something goes wrong, we don't end up in an inconsistent state. That's why `OwnerToken` used to instantiated `MasterToken` and required all of its constructor arguments as well. Unfortunately, this resulted in compilation issues in the context of the newly introduce deployer contract, where there are too many function arguments. Because we now delegate deployment to a dedicated contract, we can instantiate both `OwnerToken` and `MasterToken` in a single transaction, without having `OwnerToken` being responsible to instantiate `MasterToken`. This fixes the compilation issues and simplifies the constructor of `OwnerToken`. The new `CommunityTokenDeployer` contract is now responsble for deploying the aforementioned tokens and ensures that they are deployed within a single transaction. To deploy an `OwnerToken` and `MasterToken` accounts can now call `CommunityDeloyerToken.deploy(TokenConfig, TokenConfig, DeploymentSignature)`. The `DeploymentSignature` uses `EIP712` structured type hash data to let the contract verify that the deployer is allowed to deploy the contracts on behalf of a community account.
0602ce4
to
5542cc0
Compare
uint8 v; | ||
bytes32 r; | ||
bytes32 s; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gravityblast I have removed the deadline
field here.
@endulab has correctly pointed out that, given that the deployer creates the signature on behalf of the community via the community's private key, she can also set a deadline that far in the future, which renders the deadline useless.
Unless only the community controls the signature creation there's very little benefit in having it.
This commit introduces the
CommunityTokenDeployer
contract discussed in status-im/status-desktop#11954.The idea is that, instead of having accounts deploy
OwnerToken
andMasterToken
directly, they'd use a deployer contract instead, which maintains a registry of knownOwnerToken
addresses, mapped to Status community addresses.The following changes have been made:
OwnerToken
no longer instantiatesMasterToken
It was, and still is, a requirement that both,
OwnerToken
andMasterToken
are deployed within a single transaction, so that when something goes wrong, we don't end up in an inconsistent state.That's why
OwnerToken
used to instantiatedMasterToken
and required all of its constructor arguments as well.Unfortunately, this resulted in compilation issues in the context of the newly introduce deployer contract, where there are too many function arguments.
Because we now delegate deployment to a dedicated contract, we can instantiate both
OwnerToken
andMasterToken
in a single transaction, without havingOwnerToken
being responsible to instantiateMasterToken
.This fixes the compilation issues and simplifies the constructor of
OwnerToken
.Deployments via
CommunityTokenDeployer
contractThe new
CommunityTokenDeployer
contract is now responsble for deploying the aforementioned tokens and ensures that they are deployed within a single transaction.To deploy an
OwnerToken
andMasterToken
accounts can now callCommunityDeloyerToken.deploy(TokenConfig, TokenConfig, DeploymentSignature)
.The
DeploymentSignature
usesEIP712
structured type hash data to let the contract verify that the deployer is allowed to deploy the contracts on behalf of a community account.