Skip to content

Commit

Permalink
Merge branch 'release/1.12.2' into feature/mq-designate-height
Browse files Browse the repository at this point in the history
  • Loading branch information
chopin-fan committed Jan 9, 2025
2 parents bd303c5 + 3688493 commit d901456
Show file tree
Hide file tree
Showing 44 changed files with 568 additions and 391 deletions.
40 changes: 20 additions & 20 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Azure Pipelines configuration file
jobs:
# - template: templates/build-template-window.yml
# parameters:
# parts: 3
# n: 1
# codecoverage: true
# - template: templates/build-template-window.yml
# parameters:
# parts: 3
# n: 2
# codecoverage: false
# - template: templates/build-template-window.yml
# parameters:
# parts: 3
# n: 3
# codecoverage: false
# - template: templates/build-template-window.yml
# parameters:
# parts: 3
# n: 1
# codecoverage: true
# - template: templates/build-template-window.yml
# parameters:
# parts: 3
# n: 2
# codecoverage: false
# - template: templates/build-template-window.yml
# parameters:
# parts: 3
# n: 3
# codecoverage: false
- template: templates/build-template-linux.yml
parameters:
parts: 3
Expand All @@ -40,9 +40,9 @@ jobs:
parts: 3
n: 2
codecoverage: true
# - template: templates/build-template-macos.yml
# parameters:
# parts: 3
# n: 3
# codecoverage: true
# - template: templates/build-template-macos.yml
# parameters:
# parts: 3
# n: 3
# codecoverage: true

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
3 changes: 3 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
<add key="aelf" value="https://www.myget.org/F/aelf-project-dev/api/v3/index.json" protocolVersion="3"/>
<add key="Nuget Test" value="https://int.nugettest.org/api/v2" />
<add key="nexus" value="https://nexus-poc.test.aelf.dev/repository/nuget-group/index.json" protocolVersion="3" />
</packageSources>
</configuration>
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
3 changes: 1 addition & 2 deletions src/AElf.CSharp.CodeOps/AElf.CSharp.CodeOps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<ItemGroup>
<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.0" />
<PackageReference Include="Poseidon.Net" Version="0.1.1" />
<PackageReference Include="Groth16.Net" Version="1.1.2" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/AElf.CSharp.CodeOps/Validators/Method/ArrayValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading;
using AElf.CSharp.Core;
using AElf.Types;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Volo.Abp.DependencyInjection;
Expand All @@ -24,7 +25,7 @@ public class ArrayValidator : IValidator<MethodDefinition>, ITransientDependency
.LimitByTotalSize(typeof(decimal), sizeof(decimal))
.LimitByTotalSize(typeof(char), sizeof(char))
.LimitByTotalSize(typeof(String), 128) // Need to limit the size of strings by disallowing String.Concat
.LimitByTotalSize(typeof(BigIntValue), 128)
// It isn't possible to estimate runtime sizes for below, so limit by count
.LimitByCount(typeof(Type), 5)
.LimitByCount(typeof(Object), 5) // Support object in Linq queries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ private bool IsBadStateField(FieldDefinition field)
if (_allowedStateTypes.Contains(field.FieldType.FullName))
return false;

if(field.FieldType.Resolve().BaseType.FullName == typeof(StructuredState).FullName)
return false;
// If not ContractReferenceState then it is not allowed
return field.FieldType.Resolve().BaseType.FullName != typeof(ContractReferenceState).FullName;
}
Expand Down
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 @@ -50,7 +53,6 @@ private void WhitelistAssemblies(Whitelist whitelist)
.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
.Assembly(typeof(Poseidon.Net.Poseidon).Assembly, Trust.Full)
;
}

Expand All @@ -64,6 +66,15 @@ private void WhitelistSystemTypes(Whitelist whitelist)
.Type("Func`1", Permission.Allowed) // Required for protobuf generated code
.Type("Func`2", Permission.Allowed) // Required for protobuf generated code
.Type("Func`3", Permission.Allowed) // Required for protobuf generated code
.Type("Func`4", Permission.Allowed)
.Type("ValueTuple`1", Permission.Allowed)
.Type("ValueTuple`2", Permission.Allowed)
.Type("ValueTuple`3", Permission.Allowed)
.Type("ValueTuple`4", Permission.Allowed)
.Type("ValueTuple`5", Permission.Allowed)
.Type("ValueTuple`6", Permission.Allowed)
.Type("ValueTuple`7", Permission.Allowed)
.Type("ValueTuple`8", Permission.Allowed)
.Type("Nullable`1", Permission.Allowed) // Required for protobuf generated code
.Type(typeof(BitConverter), Permission.Denied, member => member
.Member(nameof(BitConverter.GetBytes), Permission.Allowed))
Expand Down Expand Up @@ -160,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 @@ -169,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 @@ -4,6 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Configuration>Release</Configuration>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Configuration>Release</Configuration>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
Expand Down
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>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public IExecutionObserverThreshold GetExecutionObserverThreshold(IBlockIndex blo
var branchCountObserverThreshold = GetBlockExecutedData(blockIndex, BranchCountThresholdKey)?.Value ??
SmartContractConstants.ExecutionBranchThreshold;
var callCountObserverThreshold = GetBlockExecutedData(blockIndex, CallCountThresholdKey)?.Value ??
SmartContractConstants.ExecutionBranchThreshold;
SmartContractConstants.ExecutionCallThreshold;
return new ExecutionObserverThreshold
{
ExecutionBranchThreshold = branchCountObserverThreshold,
Expand Down
Loading

0 comments on commit d901456

Please sign in to comment.