Skip to content

Commit

Permalink
Merge branch 'release/1.12.2' into feature/mq
Browse files Browse the repository at this point in the history
  • Loading branch information
chopin-fan committed Jan 9, 2025
2 parents 4a47613 + 3688493 commit c63f5eb
Show file tree
Hide file tree
Showing 50 changed files with 301 additions and 770 deletions.
14 changes: 0 additions & 14 deletions AElf.All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureDisable.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Kernel.FeatureDisable.Core", "src\AElf.Kernel.FeatureDisable.Core\AElf.Kernel.FeatureDisable.Core.csproj", "{659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Sdk.CSharp.Spec", "src\AElf.Sdk.CSharp.Spec\AElf.Sdk.CSharp.Spec.csproj", "{45A77C41-142E-4296-A14A-D53067EC8B75}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AElf.Sdk.CSharp.Internal", "src\AElf.Sdk.CSharp.Internal\AElf.Sdk.CSharp.Internal.csproj", "{A77380A7-E425-45A3-BF3F-F865DA4F3F4E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1117,14 +1113,6 @@ Global
{659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{659A7C7A-44C9-424E-B4F6-D1D3656F7AD4}.Release|Any CPU.Build.0 = Release|Any CPU
{45A77C41-142E-4296-A14A-D53067EC8B75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45A77C41-142E-4296-A14A-D53067EC8B75}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45A77C41-142E-4296-A14A-D53067EC8B75}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45A77C41-142E-4296-A14A-D53067EC8B75}.Release|Any CPU.Build.0 = Release|Any CPU
{A77380A7-E425-45A3-BF3F-F865DA4F3F4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A77380A7-E425-45A3-BF3F-F865DA4F3F4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A77380A7-E425-45A3-BF3F-F865DA4F3F4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A77380A7-E425-45A3-BF3F-F865DA4F3F4E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1320,7 +1308,5 @@ Global
{A4ACE6D2-4CF8-4B52-93C9-BB8BEC0C098E} = {90B310B4-C2DB-419E-B5EE-97FA096B62CC}
{8C0D86A4-D1A7-4B61-AC44-755F5AC75D67} = {4E54480A-D155-43ED-9736-1A5BE7957211}
{659A7C7A-44C9-424E-B4F6-D1D3656F7AD4} = {90B310B4-C2DB-419E-B5EE-97FA096B62CC}
{45A77C41-142E-4296-A14A-D53067EC8B75} = {798BAA50-825B-4DD9-83E2-77A9EE6EBE09}
{A77380A7-E425-45A3-BF3F-F865DA4F3F4E} = {798BAA50-825B-4DD9-83E2-77A9EE6EBE09}
EndGlobalSection
EndGlobal
8 changes: 1 addition & 7 deletions contract/AElf.Contracts.MultiToken/TokenContract_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,10 @@ private Address ExtractTokenContractAddress(ByteString bytes)
private void AssertCrossChainTransaction(Transaction originalTransaction, Address validAddress,
params string[] validMethodNames)
{
var validateResult = validMethodNames.Contains(MaybeRecoverInlineTransactionFunctionName(originalTransaction.MethodName))
var validateResult = validMethodNames.Contains(originalTransaction.MethodName)
&& originalTransaction.To == validAddress;
Assert(validateResult, "Invalid transaction.");
}

private static string MaybeRecoverInlineTransactionFunctionName(string methodName)
{
var parts = methodName.Split('.');
return parts.Length > 1 ? parts[^2] : methodName;
}

private void RegisterTokenInfo(TokenInfo tokenInfo)
{
Expand Down
15 changes: 0 additions & 15 deletions protobuf/inline_transaction.proto

This file was deleted.

6 changes: 0 additions & 6 deletions protobuf/test_virtual_address_contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ service VirtualAddressContract {
option (aelf.base) = "acs1.proto";

rpc VirtualAddressVote(VirtualAddressVoteInput) returns (google.protobuf.Empty);
rpc VirtualAddressVoteWithInline(VirtualAddressVoteWithCountInput) returns (google.protobuf.Empty);
rpc VirtualAddressWithdraw(aelf.Hash) returns (google.protobuf.Empty);
rpc VirtualAddressChangeVotingOption(VirtualAddressChangeVotingOptionInput) returns (google.protobuf.Empty);
rpc VirtualAddressClaimProfit(VirtualAddressClaimProfitInput) returns (google.protobuf.Empty);
Expand All @@ -33,11 +32,6 @@ message VirtualAddressVoteInput {
aelf.Hash token = 4;
}

message VirtualAddressVoteWithCountInput {
VirtualAddressVoteInput vote_input = 1; // Existing input type
int32 count = 2; // Additional count input
}

message VirtualAddressChangeVotingOptionInput {
bool is_reset = 1;
aelf.Hash vote_id = 2;
Expand Down
1 change: 0 additions & 1 deletion src/AElf.CSharp.CodeOps/AElf.CSharp.CodeOps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<PackageReference Include="Basic.Reference.Assemblies.Net80" Version="1.5.0" />
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
<PackageReference Include="Groth16.Net" Version="1.1.2" />
<PackageReference Include="Poseidon.Net" Version="0.1.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Patch(ModuleDefinition module)
return;

// ReSharper disable once IdentifierTypo
var nmspace = module.Types.Where(IsContractType).Single().Namespace;
var nmspace = module.Types.Single(m => m.BaseType is TypeDefinition).Namespace;

var proxyBuilder = new Patch(module, nmspace);

Expand All @@ -28,20 +28,6 @@ public void Patch(ModuleDefinition module)

module.Types.Add(proxyBuilder.ObserverType);
}
private static bool IsContractType(TypeDefinition type)
{
if (type.FullName.StartsWith("AElf.Sdk.CSharp.CSharpSmartContract`1"))
return true;
if (type.BaseType is TypeDefinition baseType)
return IsContractType(baseType);
if(type.BaseType is GenericInstanceType baseType0)
return IsContractType(baseType0);
return false;
}
private static bool IsContractType(GenericInstanceType type)
{
return type.FullName.StartsWith("AElf.Sdk.CSharp.CSharpSmartContract`1");
}
}

internal class MethodPatcher
Expand Down
26 changes: 26 additions & 0 deletions src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using AElf.Cryptography.Bn254;
using AElf.Cryptography.EdDSA;
using AElf.Cryptography.Keccak;
using AElf.Cryptography.SecretSharing;
using AElf.CSharp.Core;
using AElf.Kernel.SmartContract;
Expand Down Expand Up @@ -49,6 +52,7 @@ private void WhitelistAssemblies(Whitelist whitelist)
.Assembly(typeof(IMethod).Assembly, Trust.Full) // AElf.CSharp.Core
.Assembly(typeof(SecretSharingHelper).Assembly, Trust.Partial) // AElf.Cryptography
.Assembly(typeof(ISmartContractBridgeContext).Assembly, Trust.Full) // AElf.Kernel.SmartContract.Shared
.Assembly(typeof(Groth16.Net.Verifier).Assembly, Trust.Full) // AElf.Cryptography.ECDSA
;
}

Expand Down Expand Up @@ -167,6 +171,27 @@ private void WhitelistOthers(Whitelist whitelist)
)
;
}

private void WhitelistCryptographyHelpers(Whitelist whitelist)
{
whitelist
// Selectively allowed types and members
.Namespace("AElf.Cryptography.Bn254", Permission.Denied, type => type
.Type(typeof(Bn254Helper), Permission.Denied, member => member
.Member(nameof(Bn254Helper.Bn254Pairing), Permission.Allowed)
.Member(nameof(Bn254Helper.Bn254G1Add), Permission.Allowed)
.Member(nameof(Bn254Helper.Bn254G1Mul), Permission.Allowed)
))
.Namespace("AElf.Cryptography.EdDSA", Permission.Denied, type => type
.Type(typeof(EdDsaHelper), Permission.Denied, member => member
.Member(nameof(EdDsaHelper.Ed25519Verify), Permission.Allowed)
))
.Namespace("AElf.Cryptography.Keccak", Permission.Denied, type => type
.Type(typeof(KeccakHelper), Permission.Denied, member => member
.Member(nameof(KeccakHelper.Keccak256), Permission.Allowed)
))
;
}

private Whitelist CreateWhitelist()
{
Expand All @@ -176,6 +201,7 @@ private Whitelist CreateWhitelist()
WhitelistReflectionTypes(whitelist);
WhitelistLinqAndCollections(whitelist);
WhitelistOthers(whitelist);
WhitelistCryptographyHelpers(whitelist);
return whitelist;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Threading;
using System.Threading.Tasks;
using AElf.Kernel;
using AElf.Kernel.Blockchain.Application;
using AElf.Kernel.FeatureDisable.Core;
using AElf.Kernel.SmartContract;
using AElf.Kernel.SmartContract.Application;
Expand All @@ -14,8 +13,8 @@ public class UnitTestPlainTransactionExecutingService : PlainTransactionExecutin
{
public UnitTestPlainTransactionExecutingService(ISmartContractExecutiveService smartContractExecutiveService,
IEnumerable<IPostExecutionPlugin> postPlugins, IEnumerable<IPreExecutionPlugin> prePlugins,
ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService,IBlockchainService blockchainService) : base(
smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService,blockchainService)
ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService) : base(
smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService)
{
}

Expand Down
3 changes: 3 additions & 0 deletions src/AElf.Cryptography/AElf.Cryptography.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<PackageReference Include="Secp256k1.Net" Version="1.2.0" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Secp256k1.Native" Version="0.1.24-alpha" />
<PackageReference Include="Bn254.Net" Version="0.1.0" />
<PackageReference Include="Rebex.Elliptic.Ed25519" Version="1.2.1" />
<PackageReference Include="Nethereum.Web3" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AElf.Types\AElf.Types.csproj" />
Expand Down
38 changes: 38 additions & 0 deletions src/AElf.Cryptography/Bn254/Bn254Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Bn254.Net;
using NetBn254 = Bn254.Net;

namespace AElf.Cryptography.Bn254
{
public static class Bn254Helper
{
public static (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s)
{
var (xUInt256, yUInt256) = NetBn254.Bn254.Mul(UInt256.FromBigEndianBytes(x1),
UInt256.FromBigEndianBytes(y1),
UInt256.FromBigEndianBytes(s));
return (xUInt256.ToBigEndianBytes(), yUInt256.ToBigEndianBytes());
}

public static (byte[] x3, byte[] y3) Bn254G1Add(byte[] x1, byte[] y1, byte[] x2, byte[] y2)
{
var (x3UInt256, y3UInt256) = NetBn254.Bn254.Add(UInt256.FromBigEndianBytes(x1),
UInt256.FromBigEndianBytes(y1),
UInt256.FromBigEndianBytes(x2), UInt256.FromBigEndianBytes(y2));
return (x3UInt256.ToBigEndianBytes(), y3UInt256.ToBigEndianBytes());
}

public static bool Bn254Pairing((byte[], byte[], byte[], byte[], byte[], byte[])[] input)
{
var elements = new (UInt256, UInt256, UInt256, UInt256, UInt256, UInt256)[input.Length];
for (var i = 0; i < input.Length; i++)
{
var (x1, y1, x2, y2, x3, y3) = input[i];
elements[i] = (UInt256.FromBigEndianBytes(x1), UInt256.FromBigEndianBytes(y1),
UInt256.FromBigEndianBytes(x2), UInt256.FromBigEndianBytes(y2),
UInt256.FromBigEndianBytes(x3), UInt256.FromBigEndianBytes(y3));
}

return NetBn254.Bn254.Pairing(elements);
}
}
}
22 changes: 22 additions & 0 deletions src/AElf.Cryptography/EdDSA/EdDsaHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Rebex.Security.Cryptography;

namespace AElf.Cryptography.EdDSA
{
public static class EdDsaHelper
{
public static bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey)
{
try
{
var instance = new Ed25519();
instance.FromPublicKey(publicKey);
return instance.VerifyMessage(message, signature);
}
catch (Exception e)
{
return false;
}
}
}
}
12 changes: 12 additions & 0 deletions src/AElf.Cryptography/Keccak/KeccakHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Nethereum.Util;

namespace AElf.Cryptography.Keccak
{
public static class KeccakHelper
{
public static byte[] Keccak256(byte[] message)
{
return Sha3Keccack.Current.CalculateHash(message);
}
}
}
13 changes: 0 additions & 13 deletions src/AElf.Kernel.Core/Extensions/TransactionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ public static int Size(this Transaction transaction)

public static bool VerifySignature(this Transaction transaction)
{
if (transaction.IsInlineWithTransactionId())
{
return true;
}
if (!transaction.VerifyFields())
return false;

Expand All @@ -31,16 +27,7 @@ public static bool VerifySignature(this Transaction transaction)

public static bool VerifyExpiration(this Transaction transaction, long chainBranchBlockHeight)
{
if (transaction.IsInlineWithTransactionId())
{
return true;
}
return transaction.RefBlockNumber <= chainBranchBlockHeight &&
transaction.GetExpiryBlockNumber() > chainBranchBlockHeight;
}

public static bool IsInlineWithTransactionId(this Transaction transaction)
{
return transaction.MethodName.Contains(".");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,5 @@
<ContractMessage Include="..\..\protobuf\virtual_transaction.proto">
<Link>Protobuf\Proto\virtual_transaction.proto</Link>
</ContractMessage>
<ContractMessage Include="..\..\protobuf\inline_transaction.proto">
<Link>Protobuf\Proto\inline_transaction.proto</Link>
</ContractMessage>
</ItemGroup>
</Project>
Loading

0 comments on commit c63f5eb

Please sign in to comment.