-
Notifications
You must be signed in to change notification settings - Fork 68
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
[SC] Contract libraries (proposal) #506
[SC] Contract libraries (proposal) #506
Conversation
@mrtpain would be great to hear your thoughts on this! |
If this is accepted then I will update #414 and stratisproject/Stratis.SmartContracts#14 and revert stratisproject/Stratis.SmartContracts#13 |
ee1a467
to
09c54d2
Compare
It is possible to implement these features inside main library without modifying SmartContract class like you do with static classes. Also sometimes modification is unavoidable like we supported uint128/uint256 types and we needed to modify persistent state and other classes. In some cases we may need to update both library if we add another library. IMO it would be better to go with single library dependency because i don't see clear benefits. I am open to hear other ideas . |
Thanks @YakupIpek. Definitely some modification is unavoidable. The goal of this is mainly so we can add additional "library-style" functionality more easily in the future. Eg. if we need more support for manipulating byte arrays or converting an enum to a byte 😃 Are you just suggesting that this functionality be moved to My preference is therefore to separate concerns and create a new namespace for this and add it to the whitelist. |
I think this is a good idea, it'll help keep the SmartContract class clean and let developers choose which added functionality they want to bring into their contracts or keep out entirely. |
I only see separation concerns on this. Adding another library bring more work. If i update Stratis.SCL library then i have to update I would like to know @quantumagi idea on this. This is just my suggestion and it is still up to you @rowandh |
One of the goals with this is that we don't have to update For example the EcRecover functionality can be exposed through this library, meaning we don't need a |
@@ -17,6 +17,7 @@ | |||
</ItemGroup> | |||
|
|||
<ItemGroup> | |||
<ProjectReference Include="..\Stratis.SCL\Stratis.SCL.csproj" /> |
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.
This reference should be removed as Stratis.SCL
should only ever be referenced by SCs (see #506 (comment)). Here it should be dynamically loaded, perhaps into a custom AssemblyLoadContext
. Also, it would be very robust if SCs are always provided with the version of the library that they were originally validated with (if possible).
Stratis.SCL (Package)
<- Stratis.SmartContracts.CLR (Package)
<- Stratis.Bitcoin.Features.Interop (Package)
<- Stratis.Bitcoin.Features.SmartContracts (Package)
<- Stratis.Benchmark (Package)
<- Stratis.Bitcoin.Networks (Package)
<- Stratis.Features.Collateral (Package)
<- Stratis.Features.FederatedPeg (Package)
<- Stratis.SmartContracts.Networks (Package)
<- Stratis.StraxD
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.
Unused reference, I have removed it
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.
The reference still exists implicitly. See #506 (comment).
The main benefit of this library is that, if done in a certain way, it could avoid scenarios such as: Package A uses B which is not a package, and The guaranteed way to accomplish this is to only ever reference the |
src/Stratis.SmartContracts.CLR.Validation.Tests/SmartContractDeterminismValidatorTests.cs
Show resolved
Hide resolved
@@ -23,7 +23,8 @@ public static class FormatPolicy | |||
Core, | |||
typeof(SmartContract).Assembly, | |||
typeof(Enumerable).Assembly, | |||
typeof(IStandardToken).Assembly | |||
typeof(IStandardToken).Assembly, | |||
typeof(SCL.Base.Operations).Assembly |
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.
Should SCL.Crypto.ECRecover
be added here? Ah wait it's the same assembly as Base
right? It probably won't hurt adding it anyway if the list is made distinct as well (if required). Actually the SCL typeof
references here may be problematic.
@@ -23,7 +23,8 @@ public static class ReferencedAssemblyResolver | |||
Core, | |||
typeof(SmartContract).Assembly, | |||
typeof(Enumerable).Assembly, | |||
typeof(IStandardToken).Assembly | |||
typeof(IStandardToken).Assembly, | |||
typeof(SCL.Base.Operations).Assembly |
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.
See previous comment.
src/Stratis.SmartContracts.IntegrationTests/SmartContracts/EcRecoverContract.cs
Outdated
Show resolved
Hide resolved
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.
LGTM. Just a few minor comments.
@@ -13,4 +13,8 @@ | |||
<PackageReference Include="Stratis.SmartContracts.Standards" Version="2.0.0" /> | |||
</ItemGroup> | |||
|
|||
<ItemGroup> | |||
<ProjectReference Include="..\Stratis.SCL\Stratis.SCL.csproj" /> |
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.
Should not have this reference.
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.
The validator needs to access types from it.
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.
Yes, I noticed that. Could it access types by name (instead of typeof
) or is there some other workaround? Otherwise we will have an avalanche of version updates each time Stratis.SCL
is changed as shown here: #506 (comment). That would defeat the purpose of this library. I think that is what @YakupIpek's concern is. We need to handle this library in a special way to see any undeniable benefits,
Please ensure that all packages that have been changed or that have project reference to other packages that have updated versions have their versions bumped iff their versions are still the same as the latest package release. The new |
To avoid the various versioning issues noted by @quantumagi, I've moved everything into the I have also moved validation policy definitions out of Lastly I will note that this does not solve the 'library upgradeability problem', which is also present with #414. This just makes it possible to add new library functionality without lumping it on the base |
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.
This PR shows 58 files changed. That does not seem right.
Can you resubmit your changes on top of the latest "infracontracts" branch or after first merging with it?
aee15c5
to
c0e45cf
Compare
c0e45cf
to
b4393f9
Compare
Retargeted to infracontracts |
There's an architectural flaw in the original smart contracts design. Functionality such as hashing, serialization and now ecrecover are exposed via methods on the base
SmartContract
class.This is not easily extensible as the
SmartContracts
class must be updated every time new functionality is added. Additionally it pollutes theSmartContracts
class with unnecessary functionality.This PR adds the beginning of a Smart Contract Library
Stratis.SCL
. The library is whitelisted for use in contracts. To add additional functionality, only the library module needs to be updated.I've added EcRecover to demonstrate the proposed idea.