From 6008ea59dcaf9711e1f154478c34850d77f75cb4 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Tue, 17 Dec 2024 11:47:11 +0800 Subject: [PATCH 01/24] Revert code --- .../Module/CallAndBranchCounts/Patcher.cs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/AElf.CSharp.CodeOps/Patchers/Module/CallAndBranchCounts/Patcher.cs b/src/AElf.CSharp.CodeOps/Patchers/Module/CallAndBranchCounts/Patcher.cs index 09b8581feb..bdac2a7575 100644 --- a/src/AElf.CSharp.CodeOps/Patchers/Module/CallAndBranchCounts/Patcher.cs +++ b/src/AElf.CSharp.CodeOps/Patchers/Module/CallAndBranchCounts/Patcher.cs @@ -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); @@ -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 From 77ed70a6aeada6d12433715849ea542663900972 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Wed, 18 Dec 2024 10:57:56 +0800 Subject: [PATCH 02/24] try to skip issue that node can not produce --- src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs index 6c42b3605c..d4762479c6 100644 --- a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs +++ b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs @@ -44,6 +44,7 @@ public Task HandleEventAsync(ConsensusRequestMiningEventData eventData) var chain = await _blockchainService.GetChainAsync(); if (eventData.PreviousBlockHash != chain.BestChainHash) { + await TriggerConsensusEventAsync(chain.BestChainHash, chain.BestChainHeight); Logger.LogDebug("Mining canceled because best chain already updated"); return; } From 334079102e2912a6129a3acf9306484060db2563 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Wed, 18 Dec 2024 14:12:34 +0800 Subject: [PATCH 03/24] Remove TriggerConsensusEventAsync --- src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs index d4762479c6..6c42b3605c 100644 --- a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs +++ b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs @@ -44,7 +44,6 @@ public Task HandleEventAsync(ConsensusRequestMiningEventData eventData) var chain = await _blockchainService.GetChainAsync(); if (eventData.PreviousBlockHash != chain.BestChainHash) { - await TriggerConsensusEventAsync(chain.BestChainHash, chain.BestChainHeight); Logger.LogDebug("Mining canceled because best chain already updated"); return; } From a584079519275183de74588eb20efde57cf7d674 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Wed, 18 Dec 2024 15:53:03 +0800 Subject: [PATCH 04/24] Add TriggerConsensusEventAsync for image --- src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs index 6c42b3605c..d4762479c6 100644 --- a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs +++ b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs @@ -44,6 +44,7 @@ public Task HandleEventAsync(ConsensusRequestMiningEventData eventData) var chain = await _blockchainService.GetChainAsync(); if (eventData.PreviousBlockHash != chain.BestChainHash) { + await TriggerConsensusEventAsync(chain.BestChainHash, chain.BestChainHeight); Logger.LogDebug("Mining canceled because best chain already updated"); return; } From 6bf28b9d2f0f1919a5f9422c5bd635ba9a633832 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Wed, 18 Dec 2024 16:53:47 +0800 Subject: [PATCH 05/24] remove TriggerConsensusEventAsync --- src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs index d4762479c6..6c42b3605c 100644 --- a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs +++ b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs @@ -44,7 +44,6 @@ public Task HandleEventAsync(ConsensusRequestMiningEventData eventData) var chain = await _blockchainService.GetChainAsync(); if (eventData.PreviousBlockHash != chain.BestChainHash) { - await TriggerConsensusEventAsync(chain.BestChainHash, chain.BestChainHeight); Logger.LogDebug("Mining canceled because best chain already updated"); return; } From 745b32666a73ae522bff9f94d017fff789be25ba Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Thu, 19 Dec 2024 05:11:10 +0800 Subject: [PATCH 06/24] add TriggerConsensusEventAsync --- src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs index 6c42b3605c..e39230885c 100644 --- a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs +++ b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs @@ -44,7 +44,8 @@ public Task HandleEventAsync(ConsensusRequestMiningEventData eventData) var chain = await _blockchainService.GetChainAsync(); if (eventData.PreviousBlockHash != chain.BestChainHash) { - Logger.LogDebug("Mining canceled because best chain already updated"); + await TriggerConsensusEventAsync(chain.BestChainHash, chain.BestChainHeight); + Logger.LogDebug("Mining canceled because best chain already updated 1"); return; } From 3222d1cba33e332f2d93df034c8690015e19fa7d Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Thu, 19 Dec 2024 07:12:39 +0800 Subject: [PATCH 07/24] Add log --- src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs index e39230885c..11c8937392 100644 --- a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs +++ b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs @@ -44,6 +44,7 @@ public Task HandleEventAsync(ConsensusRequestMiningEventData eventData) var chain = await _blockchainService.GetChainAsync(); if (eventData.PreviousBlockHash != chain.BestChainHash) { + Logger.LogDebug($"PreviousBlockHash:{eventData.PreviousBlockHash},BestChainHash:{chain.BestChainHash}"); await TriggerConsensusEventAsync(chain.BestChainHash, chain.BestChainHeight); Logger.LogDebug("Mining canceled because best chain already updated 1"); return; From c522ab92827a125f76f116e08dedd9722d330ec1 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Thu, 19 Dec 2024 08:24:23 +0800 Subject: [PATCH 08/24] Add log --- src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs index 11c8937392..6df35205e5 100644 --- a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs +++ b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs @@ -44,7 +44,7 @@ public Task HandleEventAsync(ConsensusRequestMiningEventData eventData) var chain = await _blockchainService.GetChainAsync(); if (eventData.PreviousBlockHash != chain.BestChainHash) { - Logger.LogDebug($"PreviousBlockHash:{eventData.PreviousBlockHash},BestChainHash:{chain.BestChainHash}"); + Logger.LogDebug($"PreviousBlockHash:{eventData.PreviousBlockHash},BestChainHash:{chain.BestChainHash},BestChainHeight:{chain.BestChainHeight},preHeight:{eventData.PreviousBlockHeight}"); await TriggerConsensusEventAsync(chain.BestChainHash, chain.BestChainHeight); Logger.LogDebug("Mining canceled because best chain already updated 1"); return; From 692c6b2a3072438c1bd0557b11a616378a44ec00 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Thu, 19 Dec 2024 09:49:16 +0800 Subject: [PATCH 09/24] 1. Remove log and resolve issue --- .../IrreversibleBlockHeightUnacceptableLogEventProcessor.cs | 6 +++++- src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/AElf.Kernel.Consensus.AEDPoS/Application/IrreversibleBlockHeightUnacceptableLogEventProcessor.cs b/src/AElf.Kernel.Consensus.AEDPoS/Application/IrreversibleBlockHeightUnacceptableLogEventProcessor.cs index 5ca2448229..4b5e3cab43 100644 --- a/src/AElf.Kernel.Consensus.AEDPoS/Application/IrreversibleBlockHeightUnacceptableLogEventProcessor.cs +++ b/src/AElf.Kernel.Consensus.AEDPoS/Application/IrreversibleBlockHeightUnacceptableLogEventProcessor.cs @@ -53,12 +53,16 @@ protected override async Task ProcessLogEventAsync(Block block, LogEvent logEven if (distanceToLib.DistanceToIrreversibleBlockHeight > 0) { + var chain = await _blockchainService.GetChainAsync(); Logger.LogDebug($"Distance to lib height: {distanceToLib.DistanceToIrreversibleBlockHeight}"); + if ( block.Height - chain.LastIrreversibleBlockHeight < distanceToLib.DistanceToIrreversibleBlockHeight/2) + { + return; + } Logger.LogDebug("Will rollback to lib height."); _taskQueueManager.Enqueue( async () => { - var chain = await _blockchainService.GetChainAsync(); await _blockchainService.ResetChainToLibAsync(chain); }, KernelConstants.UpdateChainQueueName); } diff --git a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs index 6df35205e5..6c42b3605c 100644 --- a/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs +++ b/src/AElf.Kernel/ConsensusRequestMiningEventHandler.cs @@ -44,9 +44,7 @@ public Task HandleEventAsync(ConsensusRequestMiningEventData eventData) var chain = await _blockchainService.GetChainAsync(); if (eventData.PreviousBlockHash != chain.BestChainHash) { - Logger.LogDebug($"PreviousBlockHash:{eventData.PreviousBlockHash},BestChainHash:{chain.BestChainHash},BestChainHeight:{chain.BestChainHeight},preHeight:{eventData.PreviousBlockHeight}"); - await TriggerConsensusEventAsync(chain.BestChainHash, chain.BestChainHeight); - Logger.LogDebug("Mining canceled because best chain already updated 1"); + Logger.LogDebug("Mining canceled because best chain already updated"); return; } From b8fb0d8aea94c9a6102c1623319c6a79f85d7be5 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Fri, 20 Dec 2024 11:32:14 +0800 Subject: [PATCH 10/24] Remove unused code --- .../Validators/Whitelist/IWhitelistProvider.cs | 1 + .../IrreversibleBlockHeightUnacceptableLogEventProcessor.cs | 6 +----- src/AElf.Types/Types/BigIntValue.cs | 1 - .../MultiTokenContractTestBase.cs | 3 --- 4 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs index 1d50b2d12d..1c7a30fa38 100644 --- a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs +++ b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs @@ -49,6 +49,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 ; } diff --git a/src/AElf.Kernel.Consensus.AEDPoS/Application/IrreversibleBlockHeightUnacceptableLogEventProcessor.cs b/src/AElf.Kernel.Consensus.AEDPoS/Application/IrreversibleBlockHeightUnacceptableLogEventProcessor.cs index 4b5e3cab43..5ca2448229 100644 --- a/src/AElf.Kernel.Consensus.AEDPoS/Application/IrreversibleBlockHeightUnacceptableLogEventProcessor.cs +++ b/src/AElf.Kernel.Consensus.AEDPoS/Application/IrreversibleBlockHeightUnacceptableLogEventProcessor.cs @@ -53,16 +53,12 @@ protected override async Task ProcessLogEventAsync(Block block, LogEvent logEven if (distanceToLib.DistanceToIrreversibleBlockHeight > 0) { - var chain = await _blockchainService.GetChainAsync(); Logger.LogDebug($"Distance to lib height: {distanceToLib.DistanceToIrreversibleBlockHeight}"); - if ( block.Height - chain.LastIrreversibleBlockHeight < distanceToLib.DistanceToIrreversibleBlockHeight/2) - { - return; - } Logger.LogDebug("Will rollback to lib height."); _taskQueueManager.Enqueue( async () => { + var chain = await _blockchainService.GetChainAsync(); await _blockchainService.ResetChainToLibAsync(chain); }, KernelConstants.UpdateChainQueueName); } diff --git a/src/AElf.Types/Types/BigIntValue.cs b/src/AElf.Types/Types/BigIntValue.cs index f65c8897a3..bd8c446065 100644 --- a/src/AElf.Types/Types/BigIntValue.cs +++ b/src/AElf.Types/Types/BigIntValue.cs @@ -207,6 +207,5 @@ private static bool LessThan(in BigIntValue a, in BigIntValue b) } #endregion - } } \ No newline at end of file diff --git a/test/AElf.Contracts.MultiToken.Tests/MultiTokenContractTestBase.cs b/test/AElf.Contracts.MultiToken.Tests/MultiTokenContractTestBase.cs index 62a7f23ec6..232a5f5b8b 100644 --- a/test/AElf.Contracts.MultiToken.Tests/MultiTokenContractTestBase.cs +++ b/test/AElf.Contracts.MultiToken.Tests/MultiTokenContractTestBase.cs @@ -240,7 +240,4 @@ internal async Task> CreateMutiTokenWithExceptionAsync( await CreateSeedNftAsync(stub, createInput); return await stub.Create.SendWithExceptionAsync(createInput); } - - - } \ No newline at end of file From 586a98aa5246aa8806d2300ff467ad596ea21a45 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Mon, 23 Dec 2024 19:35:55 +0800 Subject: [PATCH 11/24] Remove cross-aa code --- .../TokenContract_Helper.cs | 8 +- protobuf/test_virtual_address_contract.proto | 6 -- ...nitTestPlainTransactionExecutingService.cs | 5 +- .../Extensions/TransactionExtensions.cs | 13 --- .../AElf.Kernel.SmartContract.csproj | 3 - .../PlainTransactionExecutingService.cs | 102 +----------------- .../Dto/SingleTransactionExecutingDto.cs | 1 - .../ITransactionContext.cs | 1 - .../InlineWithTransactionIdCounter.cs | 18 ---- .../TransactionContext.cs | 1 - .../Application/BlockExecutingService.cs | 34 ++---- .../TransactionValidationService.cs | 4 - .../Transaction/TransactionTrace.cs | 20 ---- src/AElf.Runtime.CSharp/Executive.cs | 6 -- src/AElf.Runtime.CSharp/TransactionConsts.cs | 6 -- .../Services/TransactionResultAppService.cs | 2 +- .../BVT/ElectionTests.cs | 88 --------------- .../Action.cs | 21 ---- .../Extensions/TransactionExtensionsTests.cs | 10 -- ...lainTransactionExecutingAsPluginService.cs | 4 +- 20 files changed, 21 insertions(+), 332 deletions(-) delete mode 100644 src/AElf.Kernel.SmartContract/InlineWithTransactionIdCounter.cs delete mode 100644 src/AElf.Runtime.CSharp/TransactionConsts.cs diff --git a/contract/AElf.Contracts.MultiToken/TokenContract_Helper.cs b/contract/AElf.Contracts.MultiToken/TokenContract_Helper.cs index f318c9fd27..3a78c60cbe 100644 --- a/contract/AElf.Contracts.MultiToken/TokenContract_Helper.cs +++ b/contract/AElf.Contracts.MultiToken/TokenContract_Helper.cs @@ -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) { diff --git a/protobuf/test_virtual_address_contract.proto b/protobuf/test_virtual_address_contract.proto index 992ad86fbf..cdfb14fa05 100644 --- a/protobuf/test_virtual_address_contract.proto +++ b/protobuf/test_virtual_address_contract.proto @@ -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); @@ -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; diff --git a/src/AElf.ContractTestKit.AEDPoSExtension/UnitTestPlainTransactionExecutingService.cs b/src/AElf.ContractTestKit.AEDPoSExtension/UnitTestPlainTransactionExecutingService.cs index c3eabef06d..37f1b50c43 100644 --- a/src/AElf.ContractTestKit.AEDPoSExtension/UnitTestPlainTransactionExecutingService.cs +++ b/src/AElf.ContractTestKit.AEDPoSExtension/UnitTestPlainTransactionExecutingService.cs @@ -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; @@ -14,8 +13,8 @@ public class UnitTestPlainTransactionExecutingService : PlainTransactionExecutin { public UnitTestPlainTransactionExecutingService(ISmartContractExecutiveService smartContractExecutiveService, IEnumerable postPlugins, IEnumerable prePlugins, - ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService,IBlockchainService blockchainService) : base( - smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService,blockchainService) + ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService) : base( + smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService) { } diff --git a/src/AElf.Kernel.Core/Extensions/TransactionExtensions.cs b/src/AElf.Kernel.Core/Extensions/TransactionExtensions.cs index 6a845b9df4..4c3e8e3242 100644 --- a/src/AElf.Kernel.Core/Extensions/TransactionExtensions.cs +++ b/src/AElf.Kernel.Core/Extensions/TransactionExtensions.cs @@ -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; @@ -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("."); - } } \ No newline at end of file diff --git a/src/AElf.Kernel.SmartContract/AElf.Kernel.SmartContract.csproj b/src/AElf.Kernel.SmartContract/AElf.Kernel.SmartContract.csproj index 2358852342..ab2cf443cf 100644 --- a/src/AElf.Kernel.SmartContract/AElf.Kernel.SmartContract.csproj +++ b/src/AElf.Kernel.SmartContract/AElf.Kernel.SmartContract.csproj @@ -22,8 +22,5 @@ Protobuf\Proto\virtual_transaction.proto - - Protobuf\Proto\inline_transaction.proto - \ No newline at end of file diff --git a/src/AElf.Kernel.SmartContract/Application/PlainTransactionExecutingService.cs b/src/AElf.Kernel.SmartContract/Application/PlainTransactionExecutingService.cs index d3531087cd..79b09034f9 100644 --- a/src/AElf.Kernel.SmartContract/Application/PlainTransactionExecutingService.cs +++ b/src/AElf.Kernel.SmartContract/Application/PlainTransactionExecutingService.cs @@ -3,8 +3,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using AElf.CSharp.Core.Extension; -using AElf.Kernel.Blockchain.Application; using AElf.Kernel.FeatureDisable.Core; using AElf.Kernel.SmartContract.Domain; using AElf.Kernel.SmartContract.Infrastructure; @@ -25,17 +23,14 @@ public class PlainTransactionExecutingService : IPlainTransactionExecutingServic private readonly ISmartContractExecutiveService _smartContractExecutiveService; private readonly ITransactionContextFactory _transactionContextFactory; private readonly IFeatureDisableService _featureDisableService; - private readonly IBlockchainService _blockchainService; public PlainTransactionExecutingService(ISmartContractExecutiveService smartContractExecutiveService, IEnumerable postPlugins, IEnumerable prePlugins, - ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService, - IBlockchainService blockchainService) + ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService) { _smartContractExecutiveService = smartContractExecutiveService; _transactionContextFactory = transactionContextFactory; _featureDisableService = featureDisableService; - _blockchainService = blockchainService; _prePlugins = GetUniquePlugins(prePlugins); _postPlugins = GetUniquePlugins(postPlugins); Logger = NullLogger.Instance; @@ -66,7 +61,6 @@ public async Task> ExecuteAsync(TransactionExecutingDto var singleTxExecutingDto = new SingleTransactionExecutingDto { Depth = 0, - InlineWithTransactionIdCounter = new InlineWithTransactionIdCounter(), ChainContext = groupChainContext, Transaction = transaction, CurrentBlockTime = transactionExecutingDto.BlockHeader.Time, @@ -77,7 +71,7 @@ public async Task> ExecuteAsync(TransactionExecutingDto var transactionExecutionTask = Task.Run(() => ExecuteOneAsync(singleTxExecutingDto, cancellationToken), cancellationToken); - trace = await transactionExecutionTask; + trace = await transactionExecutionTask.WithCancellation(cancellationToken); } catch (OperationCanceledException) { @@ -96,7 +90,7 @@ public async Task> ExecuteAsync(TransactionExecutingDto var result = GetTransactionResult(trace, transactionExecutingDto.BlockHeader.Height); var returnSet = GetReturnSet(trace, result); - returnSets.AddRange(returnSet); + returnSets.Add(returnSet); } return returnSets; @@ -181,22 +175,14 @@ protected virtual async Task ExecuteOneAsync( #endregion - var methodName = txContext.Transaction.MethodName; - var originMethodName = MaybeRecoverInlineTransactionFunctionName(methodName); - txContext.Transaction.MethodName = originMethodName; - await executive.ApplyAsync(txContext); if (txContext.Trace.IsSuccessful()) - { - // Maybe layered method name. - txContext.Transaction.MethodName = methodName; await ExecuteInlineTransactions(singleTxExecutingDto.Depth, singleTxExecutingDto.CurrentBlockTime, txContext, internalStateCache, internalChainContext, singleTxExecutingDto.OriginTransactionId, cancellationToken); - } #region PostTransaction @@ -235,40 +221,11 @@ private async Task ExecuteInlineTransactions(int depth, Timestamp currentBlockTi { var trace = txContext.Trace; internalStateCache.Update(txContext.Trace.GetStateSets()); - - var methodNameCount = new Dictionary(); foreach (var inlineTx in txContext.Trace.InlineTransactions) { - var needTxId = NeedTransactionId(inlineTx.MethodName); - if (needTxId) - { - txContext.InlineWithTransactionIdCounter.Increment(); - if (!methodNameCount.TryAdd(inlineTx.MethodName, 0)) - { - methodNameCount[inlineTx.MethodName]++; - inlineTx.MethodName = - GenerateLayeredMethodNameForInlineTransaction( - txContext.Transaction, - inlineTx.MethodName, - methodNameCount[inlineTx.MethodName] - ); - } - else - { - inlineTx.MethodName = GenerateLayeredMethodNameForInlineTransaction( - txContext.Transaction, - inlineTx.MethodName, - 0 - ); - } - - await _blockchainService.AddTransactionsAsync([inlineTx]); - } - var singleTxExecutingDto = new SingleTransactionExecutingDto { Depth = depth + 1, - InlineWithTransactionIdCounter = txContext.InlineWithTransactionIdCounter, ChainContext = internalChainContext, Transaction = inlineTx, CurrentBlockTime = currentBlockTime, @@ -289,25 +246,6 @@ private async Task ExecuteInlineTransactions(int depth, Timestamp currentBlockTi } } - private static string GenerateLayeredMethodNameForInlineTransaction(Transaction parentTx, string inlineFunctionName, - int index) - { - var parentTxMethodName = parentTx.MethodName; - inlineFunctionName = inlineFunctionName.StartsWith('.') ? inlineFunctionName[1..] : inlineFunctionName; - return $"{parentTx.GetHash().ToHex()}.{parentTxMethodName}.{inlineFunctionName}.{index}"; - } - - private static string MaybeRecoverInlineTransactionFunctionName(string methodName) - { - var parts = methodName.Split('.'); - return parts.Length > 1 ? parts[^2] : methodName; - } - - private static bool NeedTransactionId(string methodName) - { - return methodName.Contains('.'); - } - private async Task ExecutePluginOnPreTransactionStageAsync(IExecutive executive, ITransactionContext txContext, Timestamp currentBlockTime, @@ -455,7 +393,7 @@ private TransactionResult GetTransactionResult(TransactionTrace trace, long bloc return txResult; } - private IEnumerable GetReturnSet(TransactionTrace trace, TransactionResult result) + private ExecutionReturnSet GetReturnSet(TransactionTrace trace, TransactionResult result) { var returnSet = new ExecutionReturnSet { @@ -464,41 +402,12 @@ private IEnumerable GetReturnSet(TransactionTrace trace, Tra Bloom = result.Bloom, TransactionResult = result }; - var returnSets = new List { returnSet }; if (trace.IsSuccessful()) { var transactionExecutingStateSets = trace.GetStateSets(); returnSet = GetReturnSet(returnSet, transactionExecutingStateSets); returnSet.ReturnValue = trace.ReturnValue; - - var inlineTxWithIdList = trace.GetAllInlineTransactions().Where(tx => NeedTransactionId(tx.MethodName)); - foreach (var inlineTx in inlineTxWithIdList) - { - var inlineTxId = inlineTx.GetHash(); - var inlineReturnSet = new ExecutionReturnSet - { - TransactionId = inlineTxId, - Status = TransactionResultStatus.Mined, - TransactionResult = new TransactionResult - { - TransactionId = inlineTxId, - BlockNumber = result.BlockNumber, - Status = TransactionResultStatus.Mined - } - }; - - // No need to execute GetReturnSet method, because changes are already set to `returnSet`. - - returnSets.Add(inlineReturnSet); - - Logger.LogWarning($"Inline tx id: {inlineTx.GetHash().ToHex()}\n{inlineTx}"); - var log = new InlineTransactionCreated() - { - Transaction = inlineTx - }; - returnSet.TransactionResult.Logs.Add(log.ToLogEvent(inlineTx.To)); - } } else { @@ -517,7 +426,7 @@ private IEnumerable GetReturnSet(TransactionTrace trace, Tra var reads = trace.GetFlattenedReads(); foreach (var read in reads) returnSet.StateAccesses[read.Key] = read.Value; - return returnSets; + return returnSet; } private ExecutionReturnSet GetReturnSet(ExecutionReturnSet returnSet, @@ -567,7 +476,6 @@ protected ITransactionContext CreateTransactionContext(SingleTransactionExecutin singleTxExecutingDto.ChainContext, singleTxExecutingDto.OriginTransactionId, origin, singleTxExecutingDto.Depth, singleTxExecutingDto.CurrentBlockTime); - txContext.InlineWithTransactionIdCounter = singleTxExecutingDto.InlineWithTransactionIdCounter; return txContext; } } \ No newline at end of file diff --git a/src/AElf.Kernel.SmartContract/Dto/SingleTransactionExecutingDto.cs b/src/AElf.Kernel.SmartContract/Dto/SingleTransactionExecutingDto.cs index 9c50702cfa..7dfe93020b 100644 --- a/src/AElf.Kernel.SmartContract/Dto/SingleTransactionExecutingDto.cs +++ b/src/AElf.Kernel.SmartContract/Dto/SingleTransactionExecutingDto.cs @@ -13,5 +13,4 @@ public class SingleTransactionExecutingDto public bool IsCancellable { get; set; } = true; public Hash OriginTransactionId { get; set; } - public InlineWithTransactionIdCounter InlineWithTransactionIdCounter { get; set; } } \ No newline at end of file diff --git a/src/AElf.Kernel.SmartContract/ITransactionContext.cs b/src/AElf.Kernel.SmartContract/ITransactionContext.cs index 1d4ab59fbe..0f1a3cecad 100644 --- a/src/AElf.Kernel.SmartContract/ITransactionContext.cs +++ b/src/AElf.Kernel.SmartContract/ITransactionContext.cs @@ -16,5 +16,4 @@ public interface ITransactionContext Transaction Transaction { get; set; } TransactionTrace Trace { get; set; } IStateCache StateCache { get; set; } - InlineWithTransactionIdCounter InlineWithTransactionIdCounter { get; set; } } \ No newline at end of file diff --git a/src/AElf.Kernel.SmartContract/InlineWithTransactionIdCounter.cs b/src/AElf.Kernel.SmartContract/InlineWithTransactionIdCounter.cs deleted file mode 100644 index 1ae06c2504..0000000000 --- a/src/AElf.Kernel.SmartContract/InlineWithTransactionIdCounter.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Threading; - -namespace AElf.Kernel.SmartContract; - -public class InlineWithTransactionIdCounter -{ - private int _count = 0; - - public void Increment() - { - Interlocked.Increment(ref _count); - } - - public int GetCount() - { - return _count; - } -} \ No newline at end of file diff --git a/src/AElf.Kernel.SmartContract/TransactionContext.cs b/src/AElf.Kernel.SmartContract/TransactionContext.cs index 2e76fcf5b1..aaf3fe79e6 100644 --- a/src/AElf.Kernel.SmartContract/TransactionContext.cs +++ b/src/AElf.Kernel.SmartContract/TransactionContext.cs @@ -16,5 +16,4 @@ public class TransactionContext : ITransactionContext public Transaction Transaction { get; set; } public TransactionTrace Trace { get; set; } public IStateCache StateCache { get; set; } - public InlineWithTransactionIdCounter InlineWithTransactionIdCounter { get; set; } } \ No newline at end of file diff --git a/src/AElf.Kernel.SmartContractExecution/Application/BlockExecutingService.cs b/src/AElf.Kernel.SmartContractExecution/Application/BlockExecutingService.cs index e7538a59b0..6dcfca3178 100644 --- a/src/AElf.Kernel.SmartContractExecution/Application/BlockExecutingService.cs +++ b/src/AElf.Kernel.SmartContractExecution/Application/BlockExecutingService.cs @@ -55,13 +55,8 @@ public async Task ExecuteBlockAsync(BlockHeader blockHeader, CancellationToken cancellationToken) { Logger.LogTrace("Entered ExecuteBlockAsync"); - - var nonCancellable = nonCancellableTransactions.ToList() - .Where(tx => !tx.MethodName.Contains('.')).ToList(); - - var cancellable = cancellableTransactions.ToList() - .Where(tx => !tx.MethodName.Contains('.')).ToList(); - + var nonCancellable = nonCancellableTransactions.ToList(); + var cancellable = cancellableTransactions.ToList(); var nonCancellableReturnSets = await _transactionExecutingService.ExecuteAsync( new TransactionExecutingDto { BlockHeader = blockHeader, Transactions = nonCancellable }, @@ -73,16 +68,15 @@ await _transactionExecutingService.ExecuteAsync( if (!cancellationToken.IsCancellationRequested && cancellable.Count > 0) { - var txExecutingDto = new TransactionExecutingDto - { - BlockHeader = blockHeader, - Transactions = cancellable, - PartialBlockStateSet = returnSetCollection.ToBlockStateSet() - }; cancellableReturnSets = await _transactionExecutingService.ExecuteAsync( - txExecutingDto, cancellationToken); + new TransactionExecutingDto + { + BlockHeader = blockHeader, + Transactions = cancellable, + PartialBlockStateSet = returnSetCollection.ToBlockStateSet() + }, + cancellationToken); returnSetCollection.AddRange(cancellableReturnSets); - cancellable = txExecutingDto.Transactions.ToList(); Logger.LogTrace("Executed cancellable txs"); } @@ -125,15 +119,7 @@ private Task FillBlockAfterExecutionAsync(BlockHeader header, var allExecutedTransactionIds = transactions.Select(x => x.GetHash()).ToList(); var orderedReturnSets = executionReturnSetCollection.GetExecutionReturnSetList() - .OrderBy(d => allExecutedTransactionIds.IndexOf(d.TransactionId) >= 0 ? allExecutedTransactionIds.IndexOf(d.TransactionId) : int.MaxValue) - .ThenBy(d => d.TransactionId) - .ToList(); - - var inlineTxIds = orderedReturnSets - .Where(returnSet => !allExecutedTransactionIds.Contains(returnSet.TransactionId)) - .Select(returnSet => returnSet.TransactionId) - .ToList(); - allExecutedTransactionIds.AddRange(inlineTxIds); + .OrderBy(d => allExecutedTransactionIds.IndexOf(d.TransactionId)).ToList(); var block = new Block { diff --git a/src/AElf.Kernel.TransactionPool/Application/TransactionValidationService.cs b/src/AElf.Kernel.TransactionPool/Application/TransactionValidationService.cs index 10c4edc1b3..324cfb14d6 100644 --- a/src/AElf.Kernel.TransactionPool/Application/TransactionValidationService.cs +++ b/src/AElf.Kernel.TransactionPool/Application/TransactionValidationService.cs @@ -49,10 +49,6 @@ public async Task ValidateTransactionWhileCollectingAsync(IChainContext ch public async Task ValidateTransactionWhileSyncingAsync(Transaction transaction) { - if (transaction.IsInlineWithTransactionId()) - { - return true; - } var validationTasks = _transactionValidationProviders.AsParallel() .Where(provider => provider.ValidateWhileSyncing).Select(async provider => { diff --git a/src/AElf.Kernel.Types/Transaction/TransactionTrace.cs b/src/AElf.Kernel.Types/Transaction/TransactionTrace.cs index cd1f080432..fbf78286a0 100644 --- a/src/AElf.Kernel.Types/Transaction/TransactionTrace.cs +++ b/src/AElf.Kernel.Types/Transaction/TransactionTrace.cs @@ -89,24 +89,4 @@ public IEnumerable GetStateSets() foreach (var stateSet in stateSets) yield return stateSet; } } - - public List GetAllInlineTransactions() - { - var transactions = new List(); - var stack = new Stack(); - stack.Push(this); - - while (stack.Count > 0) - { - var currentTrace = stack.Pop(); - transactions.AddRange(currentTrace.InlineTransactions); - if (currentTrace.InlineTraces == null) continue; - foreach (var inlineTrace in currentTrace.InlineTraces) - { - stack.Push(inlineTrace); - } - } - - return transactions; - } } \ No newline at end of file diff --git a/src/AElf.Runtime.CSharp/Executive.cs b/src/AElf.Runtime.CSharp/Executive.cs index 48df0dd737..6cb47187c6 100644 --- a/src/AElf.Runtime.CSharp/Executive.cs +++ b/src/AElf.Runtime.CSharp/Executive.cs @@ -63,12 +63,6 @@ public Task ApplyAsync(ITransactionContext transactionContext) CurrentTransactionContext.Trace.Error = "\n" + "ExceededMaxCallDepth"; return Task.CompletedTask; } - if (CurrentTransactionContext.InlineWithTransactionIdCounter?.GetCount() > TransactionConsts.InlineWithTransactionIdLimit) - { - CurrentTransactionContext.Trace.ExecutionStatus = ExecutionStatus.ExceededMaxCallDepth; - CurrentTransactionContext.Trace.Error = "\n" + "failed.ExceededMaxInlineWithTransactionIdCount"; - return Task.CompletedTask; - } Execute(); } diff --git a/src/AElf.Runtime.CSharp/TransactionConsts.cs b/src/AElf.Runtime.CSharp/TransactionConsts.cs deleted file mode 100644 index 06e85b9d73..0000000000 --- a/src/AElf.Runtime.CSharp/TransactionConsts.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace AElf.Runtime.CSharp; - -public class TransactionConsts -{ - public const int InlineWithTransactionIdLimit = 5; -} \ No newline at end of file diff --git a/src/AElf.WebApp.Application.Chain/Services/TransactionResultAppService.cs b/src/AElf.WebApp.Application.Chain/Services/TransactionResultAppService.cs index 1faccef3bb..1923b9f989 100644 --- a/src/AElf.WebApp.Application.Chain/Services/TransactionResultAppService.cs +++ b/src/AElf.WebApp.Application.Chain/Services/TransactionResultAppService.cs @@ -24,7 +24,7 @@ namespace AElf.WebApp.Application.Chain; public interface ITransactionResultAppService { Task GetTransactionResultAsync(string transactionId); - + Task GetTransactionResultV2Async(string transactionId); Task> GetTransactionResultsAsync(string blockHash, int offset = 0, diff --git a/test/AElf.Contracts.Election.Tests/BVT/ElectionTests.cs b/test/AElf.Contracts.Election.Tests/BVT/ElectionTests.cs index d6e44f057f..2ba363f220 100644 --- a/test/AElf.Contracts.Election.Tests/BVT/ElectionTests.cs +++ b/test/AElf.Contracts.Election.Tests/BVT/ElectionTests.cs @@ -1984,94 +1984,6 @@ await VirtualAddressContractStub.VirtualAddressVote.SendAsync(new VirtualAddress return result.ActiveVotingRecords.First().VoteId; } - [Fact] - public async Task VirtualAddress_Vote_WithInlineTxIdTest() - { - var amount = 100; - const int lockTime = 100 * 60 * 60 * 24; - var candidatesKeyPairs = await ElectionContract_AnnounceElection_Test(); - var candidateKeyPair = candidatesKeyPairs[0]; - - var address = await VirtualAddressContractStub.GetVirtualAddress.CallAsync(new Empty()); - var initBalance = 100000; - - await TokenContractStub.Transfer.SendAsync(new TransferInput - { - Amount = initBalance, - Symbol = "ELF", - To = address, - Memo = "test" - }); - - CheckBalance(address, "ELF", initBalance); - CheckBalance(address, "SHARE", 0); - CheckBalance(address, "VOTE", 0); - - var virtualAddressVoteInput = new VirtualAddressVoteInput - { - PubKey = candidateKeyPair.PublicKey.ToHex(), - Amount = amount, - EndTimestamp = TimestampHelper.GetUtcNow().AddSeconds(lockTime), - Token = HashHelper.ComputeFrom("token A") - }; - - await VirtualAddressContractStub.VirtualAddressVoteWithInline.SendAsync(new VirtualAddressVoteWithCountInput - { - VoteInput = virtualAddressVoteInput, - Count = 1 - }); - - var result = await ElectionContractStub.GetElectorVote.CallAsync(new StringValue - { - Value = address.ToBase58() - }); - result.ActiveVotedVotesAmount.ShouldBe(amount); - result = await ElectionContractStub.GetElectorVoteWithRecords.CallAsync(new StringValue - { - Value = address.ToBase58() - }); - result.ActiveVotedVotesAmount.ShouldBe(amount); - result = await ElectionContractStub.GetElectorVoteWithAllRecords.CallAsync(new StringValue - { - Value = address.ToBase58() - }); - result.AllVotedVotesAmount.ShouldBe(amount); - - CheckBalance(address, "ELF", initBalance - amount); - CheckBalance(address, "SHARE", amount); - CheckBalance(address, "VOTE", amount); - - await VirtualAddressContractStub.VirtualAddressVote.SendAsync(new VirtualAddressVoteInput - { - PubKey = candidateKeyPair.PublicKey.ToHex(), - Amount = amount, - EndTimestamp = TimestampHelper.GetUtcNow().AddSeconds(lockTime), - Token = HashHelper.ComputeFrom("token A") - }); - - result = await ElectionContractStub.GetElectorVote.CallAsync(new StringValue - { - Value = address.ToBase58() - }); - result.ActiveVotedVotesAmount.ShouldBe(amount + amount); - result = await ElectionContractStub.GetElectorVoteWithRecords.CallAsync(new StringValue - { - Value = address.ToBase58() - }); - result.ActiveVotedVotesAmount.ShouldBe(amount + amount); - result = await ElectionContractStub.GetElectorVoteWithAllRecords.CallAsync(new StringValue - { - Value = address.ToBase58() - }); - result.AllVotedVotesAmount.ShouldBe(amount + amount); - - CheckBalance(address, "ELF", initBalance - amount - amount); - CheckBalance(address, "SHARE", amount + amount); - CheckBalance(address, "VOTE", amount + amount); - - return result.ActiveVotingRecords.First().VoteId; - } - [Fact] public async Task VirtualAddress_Withdraw_Test() { diff --git a/test/AElf.Contracts.TestContract.VirtualAddress/Action.cs b/test/AElf.Contracts.TestContract.VirtualAddress/Action.cs index bc8edd7a81..295830ea1c 100644 --- a/test/AElf.Contracts.TestContract.VirtualAddress/Action.cs +++ b/test/AElf.Contracts.TestContract.VirtualAddress/Action.cs @@ -9,27 +9,6 @@ namespace AElf.Contracts.TestContract.VirtualAddress; public partial class Action : VirtualAddressContractContainer.VirtualAddressContractBase { - - public override Empty VirtualAddressVoteWithInline(VirtualAddressVoteWithCountInput input) - { - if (input.Count == null) return new Empty(); - Initialize(); - - for (int i = 0; i < input.Count; i++) - { - Context.SendVirtualInline(HashHelper.ComputeFrom("test"), State.ElectionContract.Value, ".Vote", new VoteMinerInput - { - CandidatePubkey = input.VoteInput.PubKey, - Amount = input.VoteInput.Amount, - EndTimestamp = input.VoteInput.EndTimestamp, - Token = input.VoteInput.Token - }.ToByteString()); - } - - - return new Empty(); - } - public override Empty VirtualAddressVote(VirtualAddressVoteInput input) { Initialize(); diff --git a/test/AElf.Kernel.Core.Tests/Extensions/TransactionExtensionsTests.cs b/test/AElf.Kernel.Core.Tests/Extensions/TransactionExtensionsTests.cs index 2fe628cb1f..daa6331365 100644 --- a/test/AElf.Kernel.Core.Tests/Extensions/TransactionExtensionsTests.cs +++ b/test/AElf.Kernel.Core.Tests/Extensions/TransactionExtensionsTests.cs @@ -46,14 +46,4 @@ public void VerifyExpiration_Test() transaction.VerifyExpiration(100).ShouldBeTrue(); transaction.VerifyExpiration(612).ShouldBeFalse(); } - - [Fact] - public void IsInlineWithTransactionId_Test() - { - var transaction = _kernelTestHelper.GenerateTransaction(100); - transaction.MethodName = ".vote"; - transaction.IsInlineWithTransactionId().ShouldBeTrue(); - transaction.MethodName = "vote"; - transaction.IsInlineWithTransactionId().ShouldBeFalse(); - } } \ No newline at end of file diff --git a/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs b/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs index cdda3f9e59..51d07eafe4 100644 --- a/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs +++ b/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs @@ -22,8 +22,8 @@ public class PlainTransactionExecutingAsPluginService : PlainTransactionExecutin public PlainTransactionExecutingAsPluginService (ISmartContractExecutiveService smartContractExecutiveService, IEnumerable postPlugins, IEnumerable prePlugins, - ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService, IBlockchainService blockchainService) : base( - smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService,blockchainService) + ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService) : base( + smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService) { _smartContractExecutiveService = smartContractExecutiveService; } From ff58f36cc1db3771bc42a507214c05d18b7e8830 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Tue, 24 Dec 2024 16:12:45 +0800 Subject: [PATCH 12/24] Adjust the implementation of zk function --- .../Whitelist/IWhitelistProvider.cs | 8 ++- .../AElf.Cryptography.csproj | 9 ++++ .../SecretSharing/SecretSharingHelper.cs | 48 +++++++++++++++++ .../AElf.Runtime.CSharp.csproj | 6 +-- .../CSharpSmartContractContext.cs | 54 +++++++++---------- 5 files changed, 94 insertions(+), 31 deletions(-) diff --git a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs index 1c7a30fa38..4d525eac88 100644 --- a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs +++ b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs @@ -200,6 +200,12 @@ private void WhitelistAElfTypes(Whitelist whitelist) // Selectively allowed types and members .Namespace("AElf.Cryptography.SecretSharing", Permission.Denied, type => type .Type(typeof(SecretSharingHelper), Permission.Denied, member => member - .Member(nameof(SecretSharingHelper.DecodeSecret), Permission.Allowed))); + .Member(nameof(SecretSharingHelper.DecodeSecret), Permission.Allowed) + .Member(nameof(SecretSharingHelper.Ed25519Verify), Permission.Allowed) + .Member(nameof(SecretSharingHelper.Keccak256), Permission.Allowed) + .Member(nameof(SecretSharingHelper.Bn254G1Mul), Permission.Allowed) + .Member(nameof(SecretSharingHelper.Bn254Pairing), Permission.Allowed) + + )); } } \ No newline at end of file diff --git a/src/AElf.Cryptography/AElf.Cryptography.csproj b/src/AElf.Cryptography/AElf.Cryptography.csproj index 1f5c07064d..d652a84e0c 100644 --- a/src/AElf.Cryptography/AElf.Cryptography.csproj +++ b/src/AElf.Cryptography/AElf.Cryptography.csproj @@ -10,6 +10,15 @@ + + all + + + all + + + all + diff --git a/src/AElf.Cryptography/SecretSharing/SecretSharingHelper.cs b/src/AElf.Cryptography/SecretSharing/SecretSharingHelper.cs index 919db05d9b..fb7d79a58e 100644 --- a/src/AElf.Cryptography/SecretSharing/SecretSharingHelper.cs +++ b/src/AElf.Cryptography/SecretSharing/SecretSharingHelper.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; +using Bn254.Net; +using Nethereum.Util; namespace AElf.Cryptography.SecretSharing { @@ -11,6 +13,52 @@ namespace AElf.Cryptography.SecretSharing /// public static class SecretSharingHelper { + public static bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey) + { + try + { + var instance = new Rebex.Security.Cryptography.Ed25519(); + instance.FromPublicKey(publicKey); + return instance.VerifyMessage(message, signature); + } + catch (Exception e) + { + return false; + } + } + + public static byte[] Keccak256(byte[] message) + { + return Sha3Keccack.Current.CalculateHash(message); + } + + public static (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) + { + var (xUInt256, yUInt256) = Bn254.Net.Bn254.Mul(UInt256.FromBigEndianBytes(x1), UInt256.FromBigEndianBytes(y1), + UInt256.FromBigEndianBytes(s)); + return (xUInt256.ToBigEndianBytes(), yUInt256.ToBigEndianBytes()); + } + + public static (byte[] x3, byte[] y3) Bn254G1Mul(byte[] x1, byte[] y1, byte[] x2, byte[] y2) + { + var (x3UInt256, y3UInt256) = Bn254.Net.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 Bn254.Net.Bn254.Pairing(elements); + } public static List EncodeSecret(byte[] secretMessage, int threshold, int totalParts) { // Polynomial construction. diff --git a/src/AElf.Runtime.CSharp/AElf.Runtime.CSharp.csproj b/src/AElf.Runtime.CSharp/AElf.Runtime.CSharp.csproj index 122d0af0b5..b9c1d1df61 100644 --- a/src/AElf.Runtime.CSharp/AElf.Runtime.CSharp.csproj +++ b/src/AElf.Runtime.CSharp/AElf.Runtime.CSharp.csproj @@ -22,9 +22,9 @@ - - - + + + diff --git a/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs b/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs index 146c0ba31c..caf5cbde5e 100644 --- a/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs +++ b/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs @@ -14,14 +14,14 @@ namespace AElf.Sdk.CSharp; /// base class for smart contracts (Context property). It provides access to properties and methods useful for /// implementing the logic in smart contracts. /// -public class CSharpSmartContractContext : ISmartContractBridgeContext, IBuiltIns +public class CSharpSmartContractContext : ISmartContractBridgeContext { - private IBuiltIns BuiltInsImplementation { get; } + // private IBuiltIns BuiltInsImplementation { get; } public CSharpSmartContractContext(ISmartContractBridgeContext smartContractBridgeContextImplementation) { SmartContractBridgeContextImplementation = smartContractBridgeContextImplementation; - BuiltInsImplementation = new InternalBuiltIns(); + // BuiltInsImplementation = new InternalBuiltIns(); } public ISmartContractBridgeContext SmartContractBridgeContextImplementation { get; } @@ -402,28 +402,28 @@ public bool ECVrfVerify(byte[] pubKey, byte[] alpha, byte[] pi, out byte[] beta) return SmartContractBridgeContextImplementation.ECVrfVerify(pubKey, alpha, pi, out beta); } - public bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey) - { - return BuiltInsImplementation.Ed25519Verify(signature, message, publicKey); - } - - public byte[] Keccak256(byte[] message) - { - return BuiltInsImplementation.Keccak256(message); - } - - public (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) - { - return BuiltInsImplementation.Bn254G1Mul(x1, y1, s); - } - - public (byte[] x3, byte[] y3) Bn254G1Add(byte[] x1, byte[] y1, byte[] x2, byte[] y2) - { - return BuiltInsImplementation.Bn254G1Add(x1, y1, x2, y2); - } - - public bool Bn254Pairing((byte[], byte[], byte[], byte[], byte[], byte[])[] input) - { - return BuiltInsImplementation.Bn254Pairing(input); - } + // public bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey) + // { + // return BuiltInsImplementation.Ed25519Verify(signature, message, publicKey); + // } + // + // public byte[] Keccak256(byte[] message) + // { + // return BuiltInsImplementation.Keccak256(message); + // } + // + // public (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) + // { + // return BuiltInsImplementation.Bn254G1Mul(x1, y1, s); + // } + // + // public (byte[] x3, byte[] y3) Bn254G1Add(byte[] x1, byte[] y1, byte[] x2, byte[] y2) + // { + // return BuiltInsImplementation.Bn254G1Add(x1, y1, x2, y2); + // } + // + // public bool Bn254Pairing((byte[], byte[], byte[], byte[], byte[], byte[])[] input) + // { + // return BuiltInsImplementation.Bn254Pairing(input); + // } } \ No newline at end of file From 4d02f2733fc4cd1f10198637c3bd9ca021c93440 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Wed, 25 Dec 2024 14:13:17 +0800 Subject: [PATCH 13/24] Adjust implementation of ZK function --- .../Whitelist/IWhitelistProvider.cs | 6 +- .../PureFunction/PureFunctionHelper.cs | 57 +++++++++++++++++++ .../SecretSharing/SecretSharingHelper.cs | 48 ---------------- 3 files changed, 58 insertions(+), 53 deletions(-) create mode 100644 src/AElf.Cryptography/PureFunction/PureFunctionHelper.cs diff --git a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs index 4d525eac88..3b9dc807b9 100644 --- a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs +++ b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs @@ -48,6 +48,7 @@ private void WhitelistAssemblies(Whitelist whitelist) .Assembly(typeof(Address).Assembly, Trust.Full) // AElf.Types .Assembly(typeof(IMethod).Assembly, Trust.Full) // AElf.CSharp.Core .Assembly(typeof(SecretSharingHelper).Assembly, Trust.Partial) // AElf.Cryptography + .Assembly(typeof(PureFunctionHelper).Assembly, Trust.Full) // AElf.Cryptography .Assembly(typeof(ISmartContractBridgeContext).Assembly, Trust.Full) // AElf.Kernel.SmartContract.Shared .Assembly(typeof(Groth16.Net.Verifier).Assembly, Trust.Full) // AElf.Cryptography.ECDSA ; @@ -201,11 +202,6 @@ private void WhitelistAElfTypes(Whitelist whitelist) .Namespace("AElf.Cryptography.SecretSharing", Permission.Denied, type => type .Type(typeof(SecretSharingHelper), Permission.Denied, member => member .Member(nameof(SecretSharingHelper.DecodeSecret), Permission.Allowed) - .Member(nameof(SecretSharingHelper.Ed25519Verify), Permission.Allowed) - .Member(nameof(SecretSharingHelper.Keccak256), Permission.Allowed) - .Member(nameof(SecretSharingHelper.Bn254G1Mul), Permission.Allowed) - .Member(nameof(SecretSharingHelper.Bn254Pairing), Permission.Allowed) - )); } } \ No newline at end of file diff --git a/src/AElf.Cryptography/PureFunction/PureFunctionHelper.cs b/src/AElf.Cryptography/PureFunction/PureFunctionHelper.cs new file mode 100644 index 0000000000..01cc9e51c1 --- /dev/null +++ b/src/AElf.Cryptography/PureFunction/PureFunctionHelper.cs @@ -0,0 +1,57 @@ +using System; +using Bn254.Net; +using Nethereum.Util; +using Rebex.Security.Cryptography; + +namespace AElf.Cryptography.SecretSharing +{ + public static class PureFunctionHelper + { + 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; + } + } + + public static byte[] Keccak256(byte[] message) + { + return Sha3Keccack.Current.CalculateHash(message); + } + + public static (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) + { + var (xUInt256, yUInt256) = Bn254.Net.Bn254.Mul(UInt256.FromBigEndianBytes(x1), UInt256.FromBigEndianBytes(y1), + UInt256.FromBigEndianBytes(s)); + return (xUInt256.ToBigEndianBytes(), yUInt256.ToBigEndianBytes()); + } + + public static (byte[] x3, byte[] y3) Bn254G1Mul(byte[] x1, byte[] y1, byte[] x2, byte[] y2) + { + var (x3UInt256, y3UInt256) = Bn254.Net.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 Bn254.Net.Bn254.Pairing(elements); + } + } +} \ No newline at end of file diff --git a/src/AElf.Cryptography/SecretSharing/SecretSharingHelper.cs b/src/AElf.Cryptography/SecretSharing/SecretSharingHelper.cs index fb7d79a58e..919db05d9b 100644 --- a/src/AElf.Cryptography/SecretSharing/SecretSharingHelper.cs +++ b/src/AElf.Cryptography/SecretSharing/SecretSharingHelper.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; -using Bn254.Net; -using Nethereum.Util; namespace AElf.Cryptography.SecretSharing { @@ -13,52 +11,6 @@ namespace AElf.Cryptography.SecretSharing /// public static class SecretSharingHelper { - public static bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey) - { - try - { - var instance = new Rebex.Security.Cryptography.Ed25519(); - instance.FromPublicKey(publicKey); - return instance.VerifyMessage(message, signature); - } - catch (Exception e) - { - return false; - } - } - - public static byte[] Keccak256(byte[] message) - { - return Sha3Keccack.Current.CalculateHash(message); - } - - public static (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) - { - var (xUInt256, yUInt256) = Bn254.Net.Bn254.Mul(UInt256.FromBigEndianBytes(x1), UInt256.FromBigEndianBytes(y1), - UInt256.FromBigEndianBytes(s)); - return (xUInt256.ToBigEndianBytes(), yUInt256.ToBigEndianBytes()); - } - - public static (byte[] x3, byte[] y3) Bn254G1Mul(byte[] x1, byte[] y1, byte[] x2, byte[] y2) - { - var (x3UInt256, y3UInt256) = Bn254.Net.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 Bn254.Net.Bn254.Pairing(elements); - } public static List EncodeSecret(byte[] secretMessage, int threshold, int totalParts) { // Polynomial construction. From 230fcebc7426a9bcb81039a301d76b6b85ae7f11 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Thu, 26 Dec 2024 16:11:14 +0800 Subject: [PATCH 14/24] Adjust impletation of zk function --- .../Whitelist/IWhitelistProvider.cs | 22 ++++++- src/AElf.Cryptography/Bn254/Bn254Helper.cs | 37 ++++++++++++ src/AElf.Cryptography/EdDSA/EdDsaHelper.cs | 22 +++++++ src/AElf.Cryptography/Keccak/KeccakHelper.cs | 12 ++++ .../PureFunction/PureFunctionHelper.cs | 57 ------------------- 5 files changed, 91 insertions(+), 59 deletions(-) create mode 100644 src/AElf.Cryptography/Bn254/Bn254Helper.cs create mode 100644 src/AElf.Cryptography/EdDSA/EdDsaHelper.cs create mode 100644 src/AElf.Cryptography/Keccak/KeccakHelper.cs delete mode 100644 src/AElf.Cryptography/PureFunction/PureFunctionHelper.cs diff --git a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs index 3b9dc807b9..e1112740ef 100644 --- a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs +++ b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs @@ -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; @@ -48,7 +51,6 @@ private void WhitelistAssemblies(Whitelist whitelist) .Assembly(typeof(Address).Assembly, Trust.Full) // AElf.Types .Assembly(typeof(IMethod).Assembly, Trust.Full) // AElf.CSharp.Core .Assembly(typeof(SecretSharingHelper).Assembly, Trust.Partial) // AElf.Cryptography - .Assembly(typeof(PureFunctionHelper).Assembly, Trust.Full) // AElf.Cryptography .Assembly(typeof(ISmartContractBridgeContext).Assembly, Trust.Full) // AElf.Kernel.SmartContract.Shared .Assembly(typeof(Groth16.Net.Verifier).Assembly, Trust.Full) // AElf.Cryptography.ECDSA ; @@ -202,6 +204,22 @@ private void WhitelistAElfTypes(Whitelist whitelist) .Namespace("AElf.Cryptography.SecretSharing", Permission.Denied, type => type .Type(typeof(SecretSharingHelper), Permission.Denied, member => member .Member(nameof(SecretSharingHelper.DecodeSecret), Permission.Allowed) - )); + )) + .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) + )) + ; + } } \ No newline at end of file diff --git a/src/AElf.Cryptography/Bn254/Bn254Helper.cs b/src/AElf.Cryptography/Bn254/Bn254Helper.cs new file mode 100644 index 0000000000..08f0297b3f --- /dev/null +++ b/src/AElf.Cryptography/Bn254/Bn254Helper.cs @@ -0,0 +1,37 @@ +using Bn254.Net; + +namespace AElf.Cryptography.Bn254 +{ + public class Bn254Helper + { + public (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) + { + var (xUInt256, yUInt256) = global::Bn254.Net.Bn254.Mul(UInt256.FromBigEndianBytes(x1), + UInt256.FromBigEndianBytes(y1), + UInt256.FromBigEndianBytes(s)); + return (xUInt256.ToBigEndianBytes(), yUInt256.ToBigEndianBytes()); + } + + public (byte[] x3, byte[] y3) Bn254G1Add(byte[] x1, byte[] y1, byte[] x2, byte[] y2) + { + var (x3UInt256, y3UInt256) = global::Bn254.Net.Bn254.Add(UInt256.FromBigEndianBytes(x1), + UInt256.FromBigEndianBytes(y1), + UInt256.FromBigEndianBytes(x2), UInt256.FromBigEndianBytes(y2)); + return (x3UInt256.ToBigEndianBytes(), y3UInt256.ToBigEndianBytes()); + } + + public 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 global::Bn254.Net.Bn254.Pairing(elements); + } + } +} \ No newline at end of file diff --git a/src/AElf.Cryptography/EdDSA/EdDsaHelper.cs b/src/AElf.Cryptography/EdDSA/EdDsaHelper.cs new file mode 100644 index 0000000000..02046e8a02 --- /dev/null +++ b/src/AElf.Cryptography/EdDSA/EdDsaHelper.cs @@ -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; + } + } + } +} \ No newline at end of file diff --git a/src/AElf.Cryptography/Keccak/KeccakHelper.cs b/src/AElf.Cryptography/Keccak/KeccakHelper.cs new file mode 100644 index 0000000000..dbb182f29c --- /dev/null +++ b/src/AElf.Cryptography/Keccak/KeccakHelper.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/src/AElf.Cryptography/PureFunction/PureFunctionHelper.cs b/src/AElf.Cryptography/PureFunction/PureFunctionHelper.cs deleted file mode 100644 index 01cc9e51c1..0000000000 --- a/src/AElf.Cryptography/PureFunction/PureFunctionHelper.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using Bn254.Net; -using Nethereum.Util; -using Rebex.Security.Cryptography; - -namespace AElf.Cryptography.SecretSharing -{ - public static class PureFunctionHelper - { - 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; - } - } - - public static byte[] Keccak256(byte[] message) - { - return Sha3Keccack.Current.CalculateHash(message); - } - - public static (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) - { - var (xUInt256, yUInt256) = Bn254.Net.Bn254.Mul(UInt256.FromBigEndianBytes(x1), UInt256.FromBigEndianBytes(y1), - UInt256.FromBigEndianBytes(s)); - return (xUInt256.ToBigEndianBytes(), yUInt256.ToBigEndianBytes()); - } - - public static (byte[] x3, byte[] y3) Bn254G1Mul(byte[] x1, byte[] y1, byte[] x2, byte[] y2) - { - var (x3UInt256, y3UInt256) = Bn254.Net.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 Bn254.Net.Bn254.Pairing(elements); - } - } -} \ No newline at end of file From c1247616c649dd4f3168f9a19745ae1e307e7604 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Fri, 27 Dec 2024 11:08:29 +0800 Subject: [PATCH 15/24] Adjust to static method --- src/AElf.Cryptography/Bn254/Bn254Helper.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AElf.Cryptography/Bn254/Bn254Helper.cs b/src/AElf.Cryptography/Bn254/Bn254Helper.cs index 08f0297b3f..318a82b355 100644 --- a/src/AElf.Cryptography/Bn254/Bn254Helper.cs +++ b/src/AElf.Cryptography/Bn254/Bn254Helper.cs @@ -2,9 +2,9 @@ namespace AElf.Cryptography.Bn254 { - public class Bn254Helper + public static class Bn254Helper { - public (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) + public static (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) { var (xUInt256, yUInt256) = global::Bn254.Net.Bn254.Mul(UInt256.FromBigEndianBytes(x1), UInt256.FromBigEndianBytes(y1), @@ -12,7 +12,7 @@ public class Bn254Helper return (xUInt256.ToBigEndianBytes(), yUInt256.ToBigEndianBytes()); } - public (byte[] x3, byte[] y3) Bn254G1Add(byte[] x1, byte[] y1, byte[] x2, byte[] y2) + public static (byte[] x3, byte[] y3) Bn254G1Add(byte[] x1, byte[] y1, byte[] x2, byte[] y2) { var (x3UInt256, y3UInt256) = global::Bn254.Net.Bn254.Add(UInt256.FromBigEndianBytes(x1), UInt256.FromBigEndianBytes(y1), @@ -20,7 +20,7 @@ public class Bn254Helper return (x3UInt256.ToBigEndianBytes(), y3UInt256.ToBigEndianBytes()); } - public bool Bn254Pairing((byte[], byte[], byte[], byte[], byte[], byte[])[] input) + 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++) From a2ef9a6590de563884a3db9376551a7900c64883 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Fri, 27 Dec 2024 13:10:53 +0800 Subject: [PATCH 16/24] Add WhitelistCryptographyHelpers whitelist method --- .../Whitelist/IWhitelistProvider.cs | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs index e1112740ef..69bef5c723 100644 --- a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs +++ b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs @@ -171,6 +171,31 @@ private void WhitelistOthers(Whitelist whitelist) ) ; } + + private void WhitelistCryptographyHelpers(Whitelist whitelist) + { + whitelist + // Selectively allowed types and members + .Namespace("AElf.Cryptography.SecretSharing", Permission.Denied, type => type + .Type(typeof(SecretSharingHelper), Permission.Denied, member => member + .Member(nameof(SecretSharingHelper.DecodeSecret), Permission.Allowed) + )) + .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() { @@ -180,6 +205,7 @@ private Whitelist CreateWhitelist() WhitelistReflectionTypes(whitelist); WhitelistLinqAndCollections(whitelist); WhitelistOthers(whitelist); + WhitelistCryptographyHelpers(whitelist); return whitelist; } } @@ -204,22 +230,6 @@ private void WhitelistAElfTypes(Whitelist whitelist) .Namespace("AElf.Cryptography.SecretSharing", Permission.Denied, type => type .Type(typeof(SecretSharingHelper), Permission.Denied, member => member .Member(nameof(SecretSharingHelper.DecodeSecret), Permission.Allowed) - )) - .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) - )) - ; - + )); } } \ No newline at end of file From c75210482e6b38e0cf0fe84f4fef12d8089f9bb2 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Sun, 29 Dec 2024 21:26:17 +0800 Subject: [PATCH 17/24] Adjust zk code --- AElf.All.sln | 14 - .../Patchers/Module/SafeMath/Patcher.cs | 1 - .../Whitelist/IWhitelistProvider.cs | 7 +- src/AElf.Cryptography/Bn254/Bn254Helper.cs | 7 +- .../AElf.Sdk.CSharp.Internal.csproj | 28 -- src/AElf.Sdk.CSharp.Internal/AssemblyInfo.cs | 3 - .../InternalBuiltIns.cs | 61 ---- .../AElf.Sdk.CSharp.Spec.csproj | 11 - src/AElf.Sdk.CSharp.Spec/IBuiltIns.cs | 10 - src/AElf.Sdk.CSharp/AElf.Sdk.CSharp.csproj | 1 - .../CSharpSmartContractAbstract.cs | 5 +- .../CSharpSmartContractContext.cs | 2 - .../ContractsPreparation.cs | 1 - .../Action.cs | 3 +- .../CSharpSmartContractContextTests.cs | 308 +++++++++--------- 15 files changed, 162 insertions(+), 300 deletions(-) delete mode 100644 src/AElf.Sdk.CSharp.Internal/AElf.Sdk.CSharp.Internal.csproj delete mode 100644 src/AElf.Sdk.CSharp.Internal/AssemblyInfo.cs delete mode 100644 src/AElf.Sdk.CSharp.Internal/InternalBuiltIns.cs delete mode 100644 src/AElf.Sdk.CSharp.Spec/AElf.Sdk.CSharp.Spec.csproj delete mode 100644 src/AElf.Sdk.CSharp.Spec/IBuiltIns.cs diff --git a/AElf.All.sln b/AElf.All.sln index 782e186970..34ad27a9ac 100644 --- a/AElf.All.sln +++ b/AElf.All.sln @@ -385,10 +385,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 @@ -1111,14 +1107,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 @@ -1313,7 +1301,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 diff --git a/src/AElf.CSharp.CodeOps/Patchers/Module/SafeMath/Patcher.cs b/src/AElf.CSharp.CodeOps/Patchers/Module/SafeMath/Patcher.cs index 2bc2e46232..2d8ec1ebe6 100644 --- a/src/AElf.CSharp.CodeOps/Patchers/Module/SafeMath/Patcher.cs +++ b/src/AElf.CSharp.CodeOps/Patchers/Module/SafeMath/Patcher.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using AElf.Sdk.CSharp; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Cecil.Rocks; diff --git a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs index 69bef5c723..41e3ba704d 100644 --- a/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs +++ b/src/AElf.CSharp.CodeOps/Validators/Whitelist/IWhitelistProvider.cs @@ -176,10 +176,6 @@ private void WhitelistCryptographyHelpers(Whitelist whitelist) { whitelist // Selectively allowed types and members - .Namespace("AElf.Cryptography.SecretSharing", Permission.Denied, type => type - .Type(typeof(SecretSharingHelper), Permission.Denied, member => member - .Member(nameof(SecretSharingHelper.DecodeSecret), Permission.Allowed) - )) .Namespace("AElf.Cryptography.Bn254", Permission.Denied, type => type .Type(typeof(Bn254Helper), Permission.Denied, member => member .Member(nameof(Bn254Helper.Bn254Pairing), Permission.Allowed) @@ -229,7 +225,6 @@ private void WhitelistAElfTypes(Whitelist whitelist) // Selectively allowed types and members .Namespace("AElf.Cryptography.SecretSharing", Permission.Denied, type => type .Type(typeof(SecretSharingHelper), Permission.Denied, member => member - .Member(nameof(SecretSharingHelper.DecodeSecret), Permission.Allowed) - )); + .Member(nameof(SecretSharingHelper.DecodeSecret), Permission.Allowed))); } } \ No newline at end of file diff --git a/src/AElf.Cryptography/Bn254/Bn254Helper.cs b/src/AElf.Cryptography/Bn254/Bn254Helper.cs index 318a82b355..0cf74fc3bc 100644 --- a/src/AElf.Cryptography/Bn254/Bn254Helper.cs +++ b/src/AElf.Cryptography/Bn254/Bn254Helper.cs @@ -1,4 +1,5 @@ using Bn254.Net; +using NetBn254 = Bn254.Net; namespace AElf.Cryptography.Bn254 { @@ -6,7 +7,7 @@ public static class Bn254Helper { public static (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) { - var (xUInt256, yUInt256) = global::Bn254.Net.Bn254.Mul(UInt256.FromBigEndianBytes(x1), + var (xUInt256, yUInt256) = NetBn254.Bn254.Mul(UInt256.FromBigEndianBytes(x1), UInt256.FromBigEndianBytes(y1), UInt256.FromBigEndianBytes(s)); return (xUInt256.ToBigEndianBytes(), yUInt256.ToBigEndianBytes()); @@ -14,7 +15,7 @@ public static (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) public static (byte[] x3, byte[] y3) Bn254G1Add(byte[] x1, byte[] y1, byte[] x2, byte[] y2) { - var (x3UInt256, y3UInt256) = global::Bn254.Net.Bn254.Add(UInt256.FromBigEndianBytes(x1), + var (x3UInt256, y3UInt256) = NetBn254.Bn254.Add(UInt256.FromBigEndianBytes(x1), UInt256.FromBigEndianBytes(y1), UInt256.FromBigEndianBytes(x2), UInt256.FromBigEndianBytes(y2)); return (x3UInt256.ToBigEndianBytes(), y3UInt256.ToBigEndianBytes()); @@ -31,7 +32,7 @@ public static bool Bn254Pairing((byte[], byte[], byte[], byte[], byte[], byte[]) UInt256.FromBigEndianBytes(x3), UInt256.FromBigEndianBytes(y3)); } - return global::Bn254.Net.Bn254.Pairing(elements); + return NetBn254.Bn254.Pairing(elements); } } } \ No newline at end of file diff --git a/src/AElf.Sdk.CSharp.Internal/AElf.Sdk.CSharp.Internal.csproj b/src/AElf.Sdk.CSharp.Internal/AElf.Sdk.CSharp.Internal.csproj deleted file mode 100644 index ff42c2fa80..0000000000 --- a/src/AElf.Sdk.CSharp.Internal/AElf.Sdk.CSharp.Internal.csproj +++ /dev/null @@ -1,28 +0,0 @@ - - - - net8.0 - AElf.Sdk.CSharp.Internal - true - latest - Types for the C# smart contract SDK. - AElf.Sdk.CSharp.Internal - - - - - all - - - all - - - all - - - - - - - - diff --git a/src/AElf.Sdk.CSharp.Internal/AssemblyInfo.cs b/src/AElf.Sdk.CSharp.Internal/AssemblyInfo.cs deleted file mode 100644 index 1b80097c7f..0000000000 --- a/src/AElf.Sdk.CSharp.Internal/AssemblyInfo.cs +++ /dev/null @@ -1,3 +0,0 @@ -using System.Runtime.CompilerServices; - -[assembly: InternalsVisibleTo("AElf.Sdk.CSharp")] \ No newline at end of file diff --git a/src/AElf.Sdk.CSharp.Internal/InternalBuiltIns.cs b/src/AElf.Sdk.CSharp.Internal/InternalBuiltIns.cs deleted file mode 100644 index 0d61e255b8..0000000000 --- a/src/AElf.Sdk.CSharp.Internal/InternalBuiltIns.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using AElf.Sdk.CSharp.Spec; -using Bn254.Net; -using Nethereum.Util; - -namespace AElf.Sdk.CSharp.Internal; - -internal class InternalBuiltIns : IBuiltIns -{ - public static void Initialize() - { - // call this method to ensure this assembly is loaded in the runtime. - } - - public bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey) - { - try - { - var instance = new Rebex.Security.Cryptography.Ed25519(); - instance.FromPublicKey(publicKey); - return instance.VerifyMessage(message, signature); - } - catch (Exception e) - { - return false; - } - } - - public byte[] Keccak256(byte[] message) - { - return Sha3Keccack.Current.CalculateHash(message); - } - - public (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) - { - var (xUInt256, yUInt256) = Bn254.Net.Bn254.Mul(UInt256.FromBigEndianBytes(x1), UInt256.FromBigEndianBytes(y1), - UInt256.FromBigEndianBytes(s)); - return (xUInt256.ToBigEndianBytes(), yUInt256.ToBigEndianBytes()); - } - - public (byte[] x3, byte[] y3) Bn254G1Add(byte[] x1, byte[] y1, byte[] x2, byte[] y2) - { - var (x3UInt256, y3UInt256) = Bn254.Net.Bn254.Add(UInt256.FromBigEndianBytes(x1), UInt256.FromBigEndianBytes(y1), - UInt256.FromBigEndianBytes(x2), UInt256.FromBigEndianBytes(y2)); - return (x3UInt256.ToBigEndianBytes(), y3UInt256.ToBigEndianBytes()); - } - - public 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 Bn254.Net.Bn254.Pairing(elements); - } -} \ No newline at end of file diff --git a/src/AElf.Sdk.CSharp.Spec/AElf.Sdk.CSharp.Spec.csproj b/src/AElf.Sdk.CSharp.Spec/AElf.Sdk.CSharp.Spec.csproj deleted file mode 100644 index 81ab49bf3a..0000000000 --- a/src/AElf.Sdk.CSharp.Spec/AElf.Sdk.CSharp.Spec.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - net8.0 - enable - enable - Release - true - - - diff --git a/src/AElf.Sdk.CSharp.Spec/IBuiltIns.cs b/src/AElf.Sdk.CSharp.Spec/IBuiltIns.cs deleted file mode 100644 index f19de71ebe..0000000000 --- a/src/AElf.Sdk.CSharp.Spec/IBuiltIns.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AElf.Sdk.CSharp.Spec; - -public interface IBuiltIns -{ - bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey); - byte[] Keccak256(byte[] message); - (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s); - (byte[] x3, byte[] y3) Bn254G1Add(byte[] x1, byte[] y1, byte[] x2, byte[] y2); - bool Bn254Pairing((byte[], byte[], byte[], byte[], byte[], byte[])[] input); -} \ No newline at end of file diff --git a/src/AElf.Sdk.CSharp/AElf.Sdk.CSharp.csproj b/src/AElf.Sdk.CSharp/AElf.Sdk.CSharp.csproj index 00cf548872..3d27d43369 100644 --- a/src/AElf.Sdk.CSharp/AElf.Sdk.CSharp.csproj +++ b/src/AElf.Sdk.CSharp/AElf.Sdk.CSharp.csproj @@ -13,7 +13,6 @@ - diff --git a/src/AElf.Sdk.CSharp/CSharpSmartContractAbstract.cs b/src/AElf.Sdk.CSharp/CSharpSmartContractAbstract.cs index 5553b6eb5a..f550dc596e 100644 --- a/src/AElf.Sdk.CSharp/CSharpSmartContractAbstract.cs +++ b/src/AElf.Sdk.CSharp/CSharpSmartContractAbstract.cs @@ -1,6 +1,5 @@ using AElf.Kernel.SmartContract; using AElf.Types; -using AElf.Sdk.CSharp.Spec; namespace AElf.Sdk.CSharp; @@ -21,6 +20,6 @@ protected void Assert(bool asserted, string message = "Assertion failed!") } internal abstract void InternalInitialize(ISmartContractBridgeContext bridgeContext); - - public IBuiltIns BuiltIns { get; internal set; } + + // public IBuiltIns BuiltIns { get; internal set; } } \ No newline at end of file diff --git a/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs b/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs index caf5cbde5e..911d71a2e6 100644 --- a/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs +++ b/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using AElf.Kernel.SmartContract; -using AElf.Sdk.CSharp.Internal; -using AElf.Sdk.CSharp.Spec; using AElf.Types; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; diff --git a/test/AElf.Contracts.Economic.TestBase/ContractsPreparation.cs b/test/AElf.Contracts.Economic.TestBase/ContractsPreparation.cs index cde20e76c9..5aeca9457c 100644 --- a/test/AElf.Contracts.Economic.TestBase/ContractsPreparation.cs +++ b/test/AElf.Contracts.Economic.TestBase/ContractsPreparation.cs @@ -18,7 +18,6 @@ using AElf.Cryptography.ECDSA; using AElf.CSharp.Core.Extension; using AElf.Kernel; -using AElf.Sdk.CSharp; using AElf.Standards.ACS3; using AElf.Types; using Google.Protobuf; diff --git a/test/AElf.Contracts.TestContract.VirtualTransactionEvent/Action.cs b/test/AElf.Contracts.TestContract.VirtualTransactionEvent/Action.cs index 99fa3348e2..9703205edf 100644 --- a/test/AElf.Contracts.TestContract.VirtualTransactionEvent/Action.cs +++ b/test/AElf.Contracts.TestContract.VirtualTransactionEvent/Action.cs @@ -1,5 +1,4 @@ -using AElf.Sdk.CSharp; -using AElf.Types; +using AElf.Types; using Google.Protobuf.WellKnownTypes; namespace AElf.Contracts.TestContract.VirtualTransactionEvent; diff --git a/test/AElf.Sdk.CSharp.Tests/CSharpSmartContractContextTests.cs b/test/AElf.Sdk.CSharp.Tests/CSharpSmartContractContextTests.cs index 19e57e247b..24ac83db54 100644 --- a/test/AElf.Sdk.CSharp.Tests/CSharpSmartContractContextTests.cs +++ b/test/AElf.Sdk.CSharp.Tests/CSharpSmartContractContextTests.cs @@ -15,40 +15,40 @@ namespace AElf.Sdk.CSharp.Tests; public class CSharpSmartContractContextTests : SdkCSharpTestBase { - [Fact] - public void Verify_Ed25519Verify() - { - var bridgeContext = GetRequiredService().Create(); - var origin = SampleAddress.AddressList[0]; - bridgeContext.TransactionContext = new TransactionContext - { - Origin = origin, - Transaction = new Transaction - { - From = SampleAddress.AddressList[1], - To = SampleAddress.AddressList[2] - } - }; - var contractContext = new CSharpSmartContractContext(bridgeContext); - var publicKey = "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a"; - var message = ""; - var signature = "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b"; - var ed25519VerifyResult = contractContext.Ed25519Verify( - ByteArrayHelper.HexStringToByteArray(signature), - ByteArrayHelper.HexStringToByteArray(message), - ByteArrayHelper.HexStringToByteArray(publicKey)); - ed25519VerifyResult.ShouldBe(true); - - var contractContext1 = new CSharpSmartContractContext(bridgeContext); - var publicKey1 = "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a"; - var message1 = "1"; - var signature1 = "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b"; - Should.Throw(() => contractContext1.Ed25519Verify( - ByteArrayHelper.HexStringToByteArray(signature1), - ByteArrayHelper.HexStringToByteArray(message1), - ByteArrayHelper.HexStringToByteArray(publicKey1))); - - } + // [Fact] + // public void Verify_Ed25519Verify() + // { + // var bridgeContext = GetRequiredService().Create(); + // var origin = SampleAddress.AddressList[0]; + // bridgeContext.TransactionContext = new TransactionContext + // { + // Origin = origin, + // Transaction = new Transaction + // { + // From = SampleAddress.AddressList[1], + // To = SampleAddress.AddressList[2] + // } + // }; + // var contractContext = new CSharpSmartContractContext(bridgeContext); + // var publicKey = "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a"; + // var message = ""; + // var signature = "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b"; + // var ed25519VerifyResult = contractContext.Ed25519Verify( + // ByteArrayHelper.HexStringToByteArray(signature), + // ByteArrayHelper.HexStringToByteArray(message), + // ByteArrayHelper.HexStringToByteArray(publicKey)); + // ed25519VerifyResult.ShouldBe(true); + // + // var contractContext1 = new CSharpSmartContractContext(bridgeContext); + // var publicKey1 = "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a"; + // var message1 = "1"; + // var signature1 = "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b"; + // Should.Throw(() => contractContext1.Ed25519Verify( + // ByteArrayHelper.HexStringToByteArray(signature1), + // ByteArrayHelper.HexStringToByteArray(message1), + // ByteArrayHelper.HexStringToByteArray(publicKey1))); + // + // } [Fact] public void Verify_Transaction_Origin_SetValue() @@ -88,124 +88,124 @@ public void Transaction_VerifySignature_Test() result.ShouldBeTrue(); } - [Fact] - public void keccak256_test() - { - var bridgeContext = GetRequiredService().Create(); - var origin = SampleAddress.AddressList[0]; - var contractContext = new CSharpSmartContractContext(bridgeContext); - byte[] message = System.Text.Encoding.UTF8.GetBytes("Test message"); - var fact = contractContext.Keccak256(message); - var expected = Sha3Keccack.Current.CalculateHash(message); - fact.ShouldBe(expected); - } - public static byte[] ToBytes32(BigIntValue value) - { - var bytes = value.ToBigEndianBytes(); - var newArray = new byte[32]; - for (int i = 0; i < bytes.Length; i++) - { - newArray[31 - i] = bytes[bytes.Length - 1 - i]; - } - - return newArray; - } - - [Fact] - public void Bn254G1Mul_Test() - { - var bridgeContext = GetRequiredService().Create(); - var contractContext = new CSharpSmartContractContext(bridgeContext); - - // Arrange - byte[] x1 = ToBytes32(new BigIntValue(0)); - byte[] y1 = ToBytes32(new BigIntValue(0)); - byte[] scalar = ToBytes32(new BigIntValue(0)); - - // use raw api to compute result - var (expectedXUInt256, expectedYUInt256) = Bn254.Net.Bn254.Mul( - UInt256.FromBigEndianBytes(x1), - UInt256.FromBigEndianBytes(y1), - UInt256.FromBigEndianBytes(scalar) - ); - var expectedX = expectedXUInt256.ToBigEndianBytes(); - var expectedY = expectedYUInt256.ToBigEndianBytes(); - - // Act - var (xResult, yResult) = contractContext.Bn254G1Mul(x1, y1, scalar); - - // Assert - xResult.ShouldBe(expectedX); - yResult.ShouldBe(expectedY); - } - - [Fact] - public void Bn254G1Add_Test() - { - var bridgeContext = GetRequiredService().Create(); - var contractContext = new CSharpSmartContractContext(bridgeContext); - - // Arrange - byte[] x1 = ToBytes32(new BigIntValue(0)); - byte[] y1 = ToBytes32(new BigIntValue(0)); - byte[] x2 = ToBytes32(new BigIntValue(0)); - byte[] y2 = ToBytes32(new BigIntValue(0)); - - // Use raw API to compute expected results - var (expectedX3UInt256, expectedY3UInt256) = Bn254.Net.Bn254.Add( - UInt256.FromBigEndianBytes(x1), - UInt256.FromBigEndianBytes(y1), - UInt256.FromBigEndianBytes(x2), - UInt256.FromBigEndianBytes(y2) - ); - var expectedX3 = expectedX3UInt256.ToBigEndianBytes(); - var expectedY3 = expectedY3UInt256.ToBigEndianBytes(); - - // Act - var (x3Result, y3Result) = contractContext.Bn254G1Add(x1, y1, x2, y2); - - // Assert - x3Result.ShouldBe(expectedX3); - y3Result.ShouldBe(expectedY3); - } - - - [Fact] - public void Bn254Pairing_Test() - { - var bridgeContext = GetRequiredService().Create(); - var contractContext = new CSharpSmartContractContext(bridgeContext); - - // Arrange - var input = new (byte[], byte[], byte[], byte[], byte[], byte[])[] - { - ( - ToBytes32(new BigIntValue(0)), - ToBytes32(new BigIntValue(0)), - ToBytes32(new BigIntValue(0)), - ToBytes32(new BigIntValue(0)), - ToBytes32(new BigIntValue(0)), - ToBytes32(new BigIntValue(0)) - ) - }; - - // Use raw API to compute expected results - bool expected = Bn254.Net.Bn254.Pairing(new (UInt256, UInt256, UInt256, UInt256, UInt256, UInt256)[] - { - ( - UInt256.FromBigEndianBytes(input[0].Item1), - UInt256.FromBigEndianBytes(input[0].Item2), - UInt256.FromBigEndianBytes(input[0].Item3), - UInt256.FromBigEndianBytes(input[0].Item4), - UInt256.FromBigEndianBytes(input[0].Item5), - UInt256.FromBigEndianBytes(input[0].Item6) - ) - }); - - // Act - bool result = contractContext.Bn254Pairing(input); - - // Assert - result.ShouldBe(expected); - } + // [Fact] + // public void keccak256_test() + // { + // var bridgeContext = GetRequiredService().Create(); + // var origin = SampleAddress.AddressList[0]; + // var contractContext = new CSharpSmartContractContext(bridgeContext); + // byte[] message = System.Text.Encoding.UTF8.GetBytes("Test message"); + // var fact = contractContext.Keccak256(message); + // var expected = Sha3Keccack.Current.CalculateHash(message); + // fact.ShouldBe(expected); + // } + // public static byte[] ToBytes32(BigIntValue value) + // { + // var bytes = value.ToBigEndianBytes(); + // var newArray = new byte[32]; + // for (int i = 0; i < bytes.Length; i++) + // { + // newArray[31 - i] = bytes[bytes.Length - 1 - i]; + // } + // + // return newArray; + // } + // + // [Fact] + // public void Bn254G1Mul_Test() + // { + // var bridgeContext = GetRequiredService().Create(); + // var contractContext = new CSharpSmartContractContext(bridgeContext); + // + // // Arrange + // byte[] x1 = ToBytes32(new BigIntValue(0)); + // byte[] y1 = ToBytes32(new BigIntValue(0)); + // byte[] scalar = ToBytes32(new BigIntValue(0)); + // + // // use raw api to compute result + // var (expectedXUInt256, expectedYUInt256) = Bn254.Net.Bn254.Mul( + // UInt256.FromBigEndianBytes(x1), + // UInt256.FromBigEndianBytes(y1), + // UInt256.FromBigEndianBytes(scalar) + // ); + // var expectedX = expectedXUInt256.ToBigEndianBytes(); + // var expectedY = expectedYUInt256.ToBigEndianBytes(); + // + // // Act + // var (xResult, yResult) = contractContext.Bn254G1Mul(x1, y1, scalar); + // + // // Assert + // xResult.ShouldBe(expectedX); + // yResult.ShouldBe(expectedY); + // } + // + // [Fact] + // public void Bn254G1Add_Test() + // { + // var bridgeContext = GetRequiredService().Create(); + // var contractContext = new CSharpSmartContractContext(bridgeContext); + // + // // Arrange + // byte[] x1 = ToBytes32(new BigIntValue(0)); + // byte[] y1 = ToBytes32(new BigIntValue(0)); + // byte[] x2 = ToBytes32(new BigIntValue(0)); + // byte[] y2 = ToBytes32(new BigIntValue(0)); + // + // // Use raw API to compute expected results + // var (expectedX3UInt256, expectedY3UInt256) = Bn254.Net.Bn254.Add( + // UInt256.FromBigEndianBytes(x1), + // UInt256.FromBigEndianBytes(y1), + // UInt256.FromBigEndianBytes(x2), + // UInt256.FromBigEndianBytes(y2) + // ); + // var expectedX3 = expectedX3UInt256.ToBigEndianBytes(); + // var expectedY3 = expectedY3UInt256.ToBigEndianBytes(); + // + // // Act + // var (x3Result, y3Result) = contractContext.Bn254G1Add(x1, y1, x2, y2); + // + // // Assert + // x3Result.ShouldBe(expectedX3); + // y3Result.ShouldBe(expectedY3); + // } + // + // + // [Fact] + // public void Bn254Pairing_Test() + // { + // var bridgeContext = GetRequiredService().Create(); + // var contractContext = new CSharpSmartContractContext(bridgeContext); + // + // // Arrange + // var input = new (byte[], byte[], byte[], byte[], byte[], byte[])[] + // { + // ( + // ToBytes32(new BigIntValue(0)), + // ToBytes32(new BigIntValue(0)), + // ToBytes32(new BigIntValue(0)), + // ToBytes32(new BigIntValue(0)), + // ToBytes32(new BigIntValue(0)), + // ToBytes32(new BigIntValue(0)) + // ) + // }; + // + // // Use raw API to compute expected results + // bool expected = Bn254.Net.Bn254.Pairing(new (UInt256, UInt256, UInt256, UInt256, UInt256, UInt256)[] + // { + // ( + // UInt256.FromBigEndianBytes(input[0].Item1), + // UInt256.FromBigEndianBytes(input[0].Item2), + // UInt256.FromBigEndianBytes(input[0].Item3), + // UInt256.FromBigEndianBytes(input[0].Item4), + // UInt256.FromBigEndianBytes(input[0].Item5), + // UInt256.FromBigEndianBytes(input[0].Item6) + // ) + // }); + // + // // Act + // bool result = contractContext.Bn254Pairing(input); + // + // // Assert + // result.ShouldBe(expected); + // } } \ No newline at end of file From 3383c90b6456cdf3598a54b8590d40d628117529 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Mon, 30 Dec 2024 09:52:57 +0800 Subject: [PATCH 18/24] remove priveteAssets --- src/AElf.Cryptography/AElf.Cryptography.csproj | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/AElf.Cryptography/AElf.Cryptography.csproj b/src/AElf.Cryptography/AElf.Cryptography.csproj index d652a84e0c..c26d4ec24f 100644 --- a/src/AElf.Cryptography/AElf.Cryptography.csproj +++ b/src/AElf.Cryptography/AElf.Cryptography.csproj @@ -10,15 +10,9 @@ - - all - - - all - - - all - + + + From ee4801fb6c2e52ef6d167b607f7c26f57b0af7c2 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Mon, 30 Dec 2024 10:00:26 +0800 Subject: [PATCH 19/24] adjust version of Nethereum.Web3 --- src/AElf.Cryptography/AElf.Cryptography.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AElf.Cryptography/AElf.Cryptography.csproj b/src/AElf.Cryptography/AElf.Cryptography.csproj index c26d4ec24f..641e967bdd 100644 --- a/src/AElf.Cryptography/AElf.Cryptography.csproj +++ b/src/AElf.Cryptography/AElf.Cryptography.csproj @@ -12,7 +12,7 @@ - + From a2e35798009d1bb051eb2967fb80edf3dae3048e Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Mon, 30 Dec 2024 11:55:25 +0800 Subject: [PATCH 20/24] remove unused code --- .../Patchers/Module/SafeMath/Patcher.cs | 1 + .../ContractCodeLoadContext.cs | 2 +- .../AElf.Runtime.CSharp.csproj | 3 - .../CSharpSmartContractAbstract.cs | 2 - .../CSharpSmartContractContext.cs | 59 ++----- ...lainTransactionExecutingAsPluginService.cs | 1 - .../AElf.Sdk.CSharp.Tests.csproj | 8 - .../CSharpSmartContractContextTests.cs | 159 ------------------ .../ed25519_testdata.json | 44 ----- 9 files changed, 15 insertions(+), 264 deletions(-) delete mode 100644 test/AElf.Sdk.CSharp.Tests/ed25519_testdata.json diff --git a/src/AElf.CSharp.CodeOps/Patchers/Module/SafeMath/Patcher.cs b/src/AElf.CSharp.CodeOps/Patchers/Module/SafeMath/Patcher.cs index 2d8ec1ebe6..2bc2e46232 100644 --- a/src/AElf.CSharp.CodeOps/Patchers/Module/SafeMath/Patcher.cs +++ b/src/AElf.CSharp.CodeOps/Patchers/Module/SafeMath/Patcher.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using AElf.Sdk.CSharp; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Cecil.Rocks; diff --git a/src/AElf.Runtime.CSharp.Core/ContractCodeLoadContext.cs b/src/AElf.Runtime.CSharp.Core/ContractCodeLoadContext.cs index c8df9a2114..507ef7bdcc 100644 --- a/src/AElf.Runtime.CSharp.Core/ContractCodeLoadContext.cs +++ b/src/AElf.Runtime.CSharp.Core/ContractCodeLoadContext.cs @@ -28,7 +28,7 @@ protected override Assembly Load(AssemblyName assemblyName) /// private Assembly LoadFromFolderOrDefault(AssemblyName assemblyName) { - if ("AElf.Sdk.CSharp".Equals(assemblyName.Name)) + if (assemblyName.Name.StartsWith("AElf.Sdk")) { // Sdk assembly should NOT be shared using var stream = _sdkStreamManager.GetStream(assemblyName); diff --git a/src/AElf.Runtime.CSharp/AElf.Runtime.CSharp.csproj b/src/AElf.Runtime.CSharp/AElf.Runtime.CSharp.csproj index b9c1d1df61..bf9914645e 100644 --- a/src/AElf.Runtime.CSharp/AElf.Runtime.CSharp.csproj +++ b/src/AElf.Runtime.CSharp/AElf.Runtime.CSharp.csproj @@ -22,9 +22,6 @@ - - - diff --git a/src/AElf.Sdk.CSharp/CSharpSmartContractAbstract.cs b/src/AElf.Sdk.CSharp/CSharpSmartContractAbstract.cs index f550dc596e..31d642fdf0 100644 --- a/src/AElf.Sdk.CSharp/CSharpSmartContractAbstract.cs +++ b/src/AElf.Sdk.CSharp/CSharpSmartContractAbstract.cs @@ -20,6 +20,4 @@ protected void Assert(bool asserted, string message = "Assertion failed!") } internal abstract void InternalInitialize(ISmartContractBridgeContext bridgeContext); - - // public IBuiltIns BuiltIns { get; internal set; } } \ No newline at end of file diff --git a/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs b/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs index 911d71a2e6..5e3ed6c94a 100644 --- a/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs +++ b/src/AElf.Sdk.CSharp/CSharpSmartContractContext.cs @@ -14,12 +14,9 @@ namespace AElf.Sdk.CSharp; /// public class CSharpSmartContractContext : ISmartContractBridgeContext { - // private IBuiltIns BuiltInsImplementation { get; } - public CSharpSmartContractContext(ISmartContractBridgeContext smartContractBridgeContextImplementation) { SmartContractBridgeContextImplementation = smartContractBridgeContextImplementation; - // BuiltInsImplementation = new InternalBuiltIns(); } public ISmartContractBridgeContext SmartContractBridgeContextImplementation { get; } @@ -88,7 +85,7 @@ public void FireLogEvent(LogEvent logEvent) /// The height of the block that contains the transaction before charging. /// public Transaction Transaction => SmartContractBridgeContextImplementation.Transaction; - + /// /// The time included in the current blocks header. /// @@ -151,7 +148,7 @@ public void DeployContract(Address address, SmartContractRegistration registrati { SmartContractBridgeContextImplementation.DeployContract(address, registration, name); } - + /// /// Update a smart contract (only the genesis contract can call it). /// @@ -162,21 +159,17 @@ public void UpdateContract(Address address, SmartContractRegistration registrati { SmartContractBridgeContextImplementation.UpdateContract(address, registration, name); } - + public ContractInfoDto DeploySmartContract(Address address, SmartContractRegistration registration, Hash name) { - return SmartContractBridgeContextImplementation.DeploySmartContract(address, registration, name); + return SmartContractBridgeContextImplementation.DeploySmartContract(address,registration,name); } - - public ContractInfoDto UpdateSmartContract(Address address, SmartContractRegistration registration, Hash name, - string previousContractVersion) + public ContractInfoDto UpdateSmartContract(Address address, SmartContractRegistration registration, Hash name,string previousContractVersion) { - return SmartContractBridgeContextImplementation.UpdateSmartContract(address, registration, name, - previousContractVersion); + return SmartContractBridgeContextImplementation.UpdateSmartContract(address,registration,name,previousContractVersion); } - public ContractVersionCheckDto CheckContractVersion(string previousContractVersion, - SmartContractRegistration registration) + public ContractVersionCheckDto CheckContractVersion(string previousContractVersion, SmartContractRegistration registration) { return SmartContractBridgeContextImplementation.CheckContractVersion(previousContractVersion, registration); } @@ -228,14 +221,13 @@ public void SendVirtualInline(Hash fromVirtualAddress, Address toAddress, string SmartContractBridgeContextImplementation.SendVirtualInline(fromVirtualAddress, toAddress, methodName, args); } - - public void SendVirtualInline(Hash fromVirtualAddress, Address toAddress, string methodName, ByteString args, - bool logTransaction) + + public void SendVirtualInline(Hash fromVirtualAddress, Address toAddress, string methodName, ByteString args,bool logTransaction) { SmartContractBridgeContextImplementation.SendVirtualInline(fromVirtualAddress, toAddress, methodName, - args, logTransaction); + args,logTransaction); } - + /// /// Sends a virtual inline transaction to another contract. This method is only available to system smart contract. @@ -253,7 +245,7 @@ public void SendVirtualInlineBySystemContract(Hash fromVirtualAddress, Address t SmartContractBridgeContextImplementation.SendVirtualInlineBySystemContract(fromVirtualAddress, toAddress, methodName, args); } - + public void SendVirtualInlineBySystemContract(Hash fromVirtualAddress, Address toAddress, string methodName, ByteString args, bool logTransaction) { @@ -394,34 +386,9 @@ public Address ConvertVirtualAddressToContractAddressWithContractHashName(Hash v return SmartContractBridgeContextImplementation.ConvertVirtualAddressToContractAddressWithContractHashName( virtualAddress); } - + public bool ECVrfVerify(byte[] pubKey, byte[] alpha, byte[] pi, out byte[] beta) { return SmartContractBridgeContextImplementation.ECVrfVerify(pubKey, alpha, pi, out beta); } - - // public bool Ed25519Verify(byte[] signature, byte[] message, byte[] publicKey) - // { - // return BuiltInsImplementation.Ed25519Verify(signature, message, publicKey); - // } - // - // public byte[] Keccak256(byte[] message) - // { - // return BuiltInsImplementation.Keccak256(message); - // } - // - // public (byte[] x, byte[] y) Bn254G1Mul(byte[] x1, byte[] y1, byte[] s) - // { - // return BuiltInsImplementation.Bn254G1Mul(x1, y1, s); - // } - // - // public (byte[] x3, byte[] y3) Bn254G1Add(byte[] x1, byte[] y1, byte[] x2, byte[] y2) - // { - // return BuiltInsImplementation.Bn254G1Add(x1, y1, x2, y2); - // } - // - // public bool Bn254Pairing((byte[], byte[], byte[], byte[], byte[], byte[])[] input) - // { - // return BuiltInsImplementation.Bn254Pairing(input); - // } } \ No newline at end of file diff --git a/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs b/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs index 51d07eafe4..f43cef0e42 100644 --- a/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs +++ b/test/AElf.Kernel.SmartContract.ExecutionPluginForMethodFee.Tests/Service/PlainTransactionExecutingAsPluginService.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using AElf.Kernel.Blockchain.Application; using AElf.Kernel.FeatureDisable.Core; using AElf.Kernel.SmartContract.Application; using AElf.Kernel.SmartContract.Domain; diff --git a/test/AElf.Sdk.CSharp.Tests/AElf.Sdk.CSharp.Tests.csproj b/test/AElf.Sdk.CSharp.Tests/AElf.Sdk.CSharp.Tests.csproj index 9a260f1451..b7379a81dc 100644 --- a/test/AElf.Sdk.CSharp.Tests/AElf.Sdk.CSharp.Tests.csproj +++ b/test/AElf.Sdk.CSharp.Tests/AElf.Sdk.CSharp.Tests.csproj @@ -4,14 +4,12 @@ false - all runtime; build; native; contentfiles; analyzers - @@ -32,10 +30,4 @@ - - - - all - - \ No newline at end of file diff --git a/test/AElf.Sdk.CSharp.Tests/CSharpSmartContractContextTests.cs b/test/AElf.Sdk.CSharp.Tests/CSharpSmartContractContextTests.cs index 24ac83db54..4e0f98d97a 100644 --- a/test/AElf.Sdk.CSharp.Tests/CSharpSmartContractContextTests.cs +++ b/test/AElf.Sdk.CSharp.Tests/CSharpSmartContractContextTests.cs @@ -1,12 +1,9 @@ -using System; using AElf.Cryptography; using AElf.Kernel; using AElf.Kernel.SmartContract; using AElf.Kernel.SmartContract.Application; using AElf.Types; -using Bn254.Net; using Google.Protobuf; -using Nethereum.Util; using Shouldly; using Xunit; using CustomContract = AElf.Runtime.CSharp.Tests.TestContract; @@ -15,41 +12,6 @@ namespace AElf.Sdk.CSharp.Tests; public class CSharpSmartContractContextTests : SdkCSharpTestBase { - // [Fact] - // public void Verify_Ed25519Verify() - // { - // var bridgeContext = GetRequiredService().Create(); - // var origin = SampleAddress.AddressList[0]; - // bridgeContext.TransactionContext = new TransactionContext - // { - // Origin = origin, - // Transaction = new Transaction - // { - // From = SampleAddress.AddressList[1], - // To = SampleAddress.AddressList[2] - // } - // }; - // var contractContext = new CSharpSmartContractContext(bridgeContext); - // var publicKey = "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a"; - // var message = ""; - // var signature = "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b"; - // var ed25519VerifyResult = contractContext.Ed25519Verify( - // ByteArrayHelper.HexStringToByteArray(signature), - // ByteArrayHelper.HexStringToByteArray(message), - // ByteArrayHelper.HexStringToByteArray(publicKey)); - // ed25519VerifyResult.ShouldBe(true); - // - // var contractContext1 = new CSharpSmartContractContext(bridgeContext); - // var publicKey1 = "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a"; - // var message1 = "1"; - // var signature1 = "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b"; - // Should.Throw(() => contractContext1.Ed25519Verify( - // ByteArrayHelper.HexStringToByteArray(signature1), - // ByteArrayHelper.HexStringToByteArray(message1), - // ByteArrayHelper.HexStringToByteArray(publicKey1))); - // - // } - [Fact] public void Verify_Transaction_Origin_SetValue() { @@ -87,125 +49,4 @@ public void Transaction_VerifySignature_Test() var result = bridgeContext.VerifySignature(transaction); result.ShouldBeTrue(); } - - // [Fact] - // public void keccak256_test() - // { - // var bridgeContext = GetRequiredService().Create(); - // var origin = SampleAddress.AddressList[0]; - // var contractContext = new CSharpSmartContractContext(bridgeContext); - // byte[] message = System.Text.Encoding.UTF8.GetBytes("Test message"); - // var fact = contractContext.Keccak256(message); - // var expected = Sha3Keccack.Current.CalculateHash(message); - // fact.ShouldBe(expected); - // } - // public static byte[] ToBytes32(BigIntValue value) - // { - // var bytes = value.ToBigEndianBytes(); - // var newArray = new byte[32]; - // for (int i = 0; i < bytes.Length; i++) - // { - // newArray[31 - i] = bytes[bytes.Length - 1 - i]; - // } - // - // return newArray; - // } - // - // [Fact] - // public void Bn254G1Mul_Test() - // { - // var bridgeContext = GetRequiredService().Create(); - // var contractContext = new CSharpSmartContractContext(bridgeContext); - // - // // Arrange - // byte[] x1 = ToBytes32(new BigIntValue(0)); - // byte[] y1 = ToBytes32(new BigIntValue(0)); - // byte[] scalar = ToBytes32(new BigIntValue(0)); - // - // // use raw api to compute result - // var (expectedXUInt256, expectedYUInt256) = Bn254.Net.Bn254.Mul( - // UInt256.FromBigEndianBytes(x1), - // UInt256.FromBigEndianBytes(y1), - // UInt256.FromBigEndianBytes(scalar) - // ); - // var expectedX = expectedXUInt256.ToBigEndianBytes(); - // var expectedY = expectedYUInt256.ToBigEndianBytes(); - // - // // Act - // var (xResult, yResult) = contractContext.Bn254G1Mul(x1, y1, scalar); - // - // // Assert - // xResult.ShouldBe(expectedX); - // yResult.ShouldBe(expectedY); - // } - // - // [Fact] - // public void Bn254G1Add_Test() - // { - // var bridgeContext = GetRequiredService().Create(); - // var contractContext = new CSharpSmartContractContext(bridgeContext); - // - // // Arrange - // byte[] x1 = ToBytes32(new BigIntValue(0)); - // byte[] y1 = ToBytes32(new BigIntValue(0)); - // byte[] x2 = ToBytes32(new BigIntValue(0)); - // byte[] y2 = ToBytes32(new BigIntValue(0)); - // - // // Use raw API to compute expected results - // var (expectedX3UInt256, expectedY3UInt256) = Bn254.Net.Bn254.Add( - // UInt256.FromBigEndianBytes(x1), - // UInt256.FromBigEndianBytes(y1), - // UInt256.FromBigEndianBytes(x2), - // UInt256.FromBigEndianBytes(y2) - // ); - // var expectedX3 = expectedX3UInt256.ToBigEndianBytes(); - // var expectedY3 = expectedY3UInt256.ToBigEndianBytes(); - // - // // Act - // var (x3Result, y3Result) = contractContext.Bn254G1Add(x1, y1, x2, y2); - // - // // Assert - // x3Result.ShouldBe(expectedX3); - // y3Result.ShouldBe(expectedY3); - // } - // - // - // [Fact] - // public void Bn254Pairing_Test() - // { - // var bridgeContext = GetRequiredService().Create(); - // var contractContext = new CSharpSmartContractContext(bridgeContext); - // - // // Arrange - // var input = new (byte[], byte[], byte[], byte[], byte[], byte[])[] - // { - // ( - // ToBytes32(new BigIntValue(0)), - // ToBytes32(new BigIntValue(0)), - // ToBytes32(new BigIntValue(0)), - // ToBytes32(new BigIntValue(0)), - // ToBytes32(new BigIntValue(0)), - // ToBytes32(new BigIntValue(0)) - // ) - // }; - // - // // Use raw API to compute expected results - // bool expected = Bn254.Net.Bn254.Pairing(new (UInt256, UInt256, UInt256, UInt256, UInt256, UInt256)[] - // { - // ( - // UInt256.FromBigEndianBytes(input[0].Item1), - // UInt256.FromBigEndianBytes(input[0].Item2), - // UInt256.FromBigEndianBytes(input[0].Item3), - // UInt256.FromBigEndianBytes(input[0].Item4), - // UInt256.FromBigEndianBytes(input[0].Item5), - // UInt256.FromBigEndianBytes(input[0].Item6) - // ) - // }); - // - // // Act - // bool result = contractContext.Bn254Pairing(input); - // - // // Assert - // result.ShouldBe(expected); - // } } \ No newline at end of file diff --git a/test/AElf.Sdk.CSharp.Tests/ed25519_testdata.json b/test/AElf.Sdk.CSharp.Tests/ed25519_testdata.json deleted file mode 100644 index 60d4a2bad4..0000000000 --- a/test/AElf.Sdk.CSharp.Tests/ed25519_testdata.json +++ /dev/null @@ -1,44 +0,0 @@ -[ - { - "secret_key": "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60", - "public_key": "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a", - "message": "", - "signed": "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b", - "signature": "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b" - }, - { - "secret_key": "4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb", - "public_key": "3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c", - "message": "72", - "signed": "92a009a9f0d4cab8720e820b5f642540a2b27b5416503f8fb3762223ebdb69da085ac1e43e15996e458f3613d0f11d8c387b2eaeb4302aeeb00d291612bb0c0072", - "signature": "92a009a9f0d4cab8720e820b5f642540a2b27b5416503f8fb3762223ebdb69da085ac1e43e15996e458f3613d0f11d8c387b2eaeb4302aeeb00d291612bb0c00" - }, - { - "secret_key": "c5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7", - "public_key": "fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025", - "message": "af82", - "signed": "6291d657deec24024827e69c3abe01a30ce548a284743a445e3680d7db5ac3ac18ff9b538d16f290ae67f760984dc6594a7c15e9716ed28dc027beceea1ec40aaf82", - "signature": "6291d657deec24024827e69c3abe01a30ce548a284743a445e3680d7db5ac3ac18ff9b538d16f290ae67f760984dc6594a7c15e9716ed28dc027beceea1ec40a" - }, - { - "secret_key": "0d4a05b07352a5436e180356da0ae6efa0345ff7fb1572575772e8005ed978e9", - "public_key": "e61a185bcef2613a6c7cb79763ce945d3b245d76114dd440bcf5f2dc1aa57057", - "message": "cbc77b", - "signed": "d9868d52c2bebce5f3fa5a79891970f309cb6591e3e1702a70276fa97c24b3a8e58606c38c9758529da50ee31b8219cba45271c689afa60b0ea26c99db19b00ccbc77b", - "signature": "d9868d52c2bebce5f3fa5a79891970f309cb6591e3e1702a70276fa97c24b3a8e58606c38c9758529da50ee31b8219cba45271c689afa60b0ea26c99db19b00c" - }, - { - "secret_key": "6df9340c138cc188b5fe4464ebaa3f7fc206a2d55c3434707e74c9fc04e20ebb", - "public_key": "c0dac102c4533186e25dc43128472353eaabdb878b152aeb8e001f92d90233a7", - "message": "5f4c8989", - "signed": "124f6fc6b0d100842769e71bd530664d888df8507df6c56dedfdb509aeb93416e26b918d38aa06305df3095697c18b2aa832eaa52edc0ae49fbae5a85e150c075f4c8989", - "signature": "124f6fc6b0d100842769e71bd530664d888df8507df6c56dedfdb509aeb93416e26b918d38aa06305df3095697c18b2aa832eaa52edc0ae49fbae5a85e150c07" - }, - { - "secret_key": "b780381a65edf8b78f6945e8dbec7941ac049fd4c61040cf0c324357975a293c", - "public_key": "e253af0766804b869bb1595be9765b534886bbaab8305bf50dbc7f899bfb5f01", - "message": "18b6bec097", - "signed": "b2fc46ad47af464478c199e1f8be169f1be6327c7f9a0a6689371ca94caf04064a01b22aff1520abd58951341603faed768cf78ce97ae7b038abfe456aa17c0918b6bec097", - "signature": "b2fc46ad47af464478c199e1f8be169f1be6327c7f9a0a6689371ca94caf04064a01b22aff1520abd58951341603faed768cf78ce97ae7b038abfe456aa17c09" - } -] \ No newline at end of file From 7b1eb9b7654b3bcfe76418b0dcc9a39416b37e12 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Wed, 1 Jan 2025 18:49:19 +0800 Subject: [PATCH 21/24] Add unit test --- .../Bn254HelperTest.cs | 111 ++++++++++++++++++ .../EdDsaHelperTest.cs | 25 ++++ .../KeccakHelperTest.cs | 22 ++++ 3 files changed, 158 insertions(+) create mode 100644 test/AElf.Cryptography.Tests/Bn254HelperTest.cs create mode 100644 test/AElf.Cryptography.Tests/EdDsaHelperTest.cs create mode 100644 test/AElf.Cryptography.Tests/KeccakHelperTest.cs diff --git a/test/AElf.Cryptography.Tests/Bn254HelperTest.cs b/test/AElf.Cryptography.Tests/Bn254HelperTest.cs new file mode 100644 index 0000000000..5a46f165bc --- /dev/null +++ b/test/AElf.Cryptography.Tests/Bn254HelperTest.cs @@ -0,0 +1,111 @@ +using AElf.Cryptography.Bn254; +using AElf.Types; +using Bn254.Net; +using Shouldly; +using Xunit; +using NetBn254 = Bn254.Net; + +namespace AElf.Cryptography.Tests; + +public class EdDsaHelperTest +{ + public static byte[] ToBytes32(BigIntValue value) + { + var bytes = value.ToBigEndianBytes(); + var newArray = new byte[32]; + for (int i = 0; i < bytes.Length; i++) + { + newArray[31 - i] = bytes[bytes.Length - 1 - i]; + } + + return newArray; + } + + [Fact] + public void Bn254G1Mul_Test() + { + // Arrange + byte[] x1 = ToBytes32(new BigIntValue(0)); + byte[] y1 = ToBytes32(new BigIntValue(0)); + byte[] scalar = ToBytes32(new BigIntValue(0)); + + // use raw api to compute result + var (expectedXuInt256, expectedYuInt256) = NetBn254.Bn254.Mul( + UInt256.FromBigEndianBytes(x1), + UInt256.FromBigEndianBytes(y1), + UInt256.FromBigEndianBytes(scalar) + ); + var expectedX = expectedXuInt256.ToBigEndianBytes(); + var expectedY = expectedYuInt256.ToBigEndianBytes(); + + // Act + var (xResult, yResult) = Bn254Helper.Bn254G1Mul(x1, y1, scalar); + + // Assert + xResult.ShouldBe(expectedX); + yResult.ShouldBe(expectedY); + } + + [Fact] + public void Bn254G1Add_Test() + { + // Arrange + byte[] x1 = ToBytes32(new BigIntValue(0)); + byte[] y1 = ToBytes32(new BigIntValue(0)); + byte[] x2 = ToBytes32(new BigIntValue(0)); + byte[] y2 = ToBytes32(new BigIntValue(0)); + + // Use raw API to compute expected results + var (expectedX3UInt256, expectedY3UInt256) = NetBn254.Bn254.Add( + UInt256.FromBigEndianBytes(x1), + UInt256.FromBigEndianBytes(y1), + UInt256.FromBigEndianBytes(x2), + UInt256.FromBigEndianBytes(y2) + ); + var expectedX3 = expectedX3UInt256.ToBigEndianBytes(); + var expectedY3 = expectedY3UInt256.ToBigEndianBytes(); + + // Act + var (x3Result, y3Result) = Bn254Helper.Bn254G1Add(x1, y1, x2, y2); + + // Assert + x3Result.ShouldBe(expectedX3); + y3Result.ShouldBe(expectedY3); + } + + [Fact] + public void Bn254Pairing_Test() + { + // Arrange + var input = new (byte[], byte[], byte[], byte[], byte[], byte[])[] + { + ( + ToBytes32(new BigIntValue(0)), + ToBytes32(new BigIntValue(0)), + ToBytes32(new BigIntValue(0)), + ToBytes32(new BigIntValue(0)), + ToBytes32(new BigIntValue(0)), + ToBytes32(new BigIntValue(0)) + ) + }; + + // Use raw API to compute expected results + bool expected = NetBn254.Bn254.Pairing(new (UInt256, UInt256, UInt256, UInt256, UInt256, UInt256)[] + { + ( + UInt256.FromBigEndianBytes(input[0].Item1), + UInt256.FromBigEndianBytes(input[0].Item2), + UInt256.FromBigEndianBytes(input[0].Item3), + UInt256.FromBigEndianBytes(input[0].Item4), + UInt256.FromBigEndianBytes(input[0].Item5), + UInt256.FromBigEndianBytes(input[0].Item6) + ) + }); + + // Act + bool result = Bn254Helper.Bn254Pairing(input); + + // Assert + result.ShouldBe(expected); + } +} \ No newline at end of file diff --git a/test/AElf.Cryptography.Tests/EdDsaHelperTest.cs b/test/AElf.Cryptography.Tests/EdDsaHelperTest.cs new file mode 100644 index 0000000000..443415463c --- /dev/null +++ b/test/AElf.Cryptography.Tests/EdDsaHelperTest.cs @@ -0,0 +1,25 @@ +using AElf.Cryptography.EdDSA; +using Shouldly; +using Xunit; + +namespace AElf.Cryptography.Tests; + +public class Bn254HelperTest +{ + [Fact] + public void Ed25519Verify_Test() + { + var publicKey = "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a"; + var message = ""; + var signature = + "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b"; + + var publicKeyBytes = ByteArrayHelper.HexStringToByteArray(publicKey); + var messageBytes = ByteArrayHelper.HexStringToByteArray(message); + var signatureBytes = ByteArrayHelper.HexStringToByteArray(signature); + + var ed25519VerifyResult = EdDsaHelper.Ed25519Verify(signatureBytes, messageBytes, publicKeyBytes); + + ed25519VerifyResult.ShouldBe(true); + } +} \ No newline at end of file diff --git a/test/AElf.Cryptography.Tests/KeccakHelperTest.cs b/test/AElf.Cryptography.Tests/KeccakHelperTest.cs new file mode 100644 index 0000000000..d6c8faa3fa --- /dev/null +++ b/test/AElf.Cryptography.Tests/KeccakHelperTest.cs @@ -0,0 +1,22 @@ +using System.Text; +using AElf.Cryptography.Keccak; +using Nethereum.Util; +using Shouldly; +using Xunit; + +namespace AElf.Cryptography.Tests; + +public class KeccakHelperTest +{ + [Fact] + public void Keccak256_Test() + { + byte[] message = Encoding.UTF8.GetBytes("Test message"); + + var expectedHash = Sha3Keccack.Current.CalculateHash(message); + + var computedHash = KeccakHelper.Keccak256(message); + + computedHash.ShouldBe(expectedHash); + } +} \ No newline at end of file From 99e57c9ff6825b82f4133a0f685e33c71802fa24 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Thu, 2 Jan 2025 17:37:41 +0800 Subject: [PATCH 22/24] Change method name to TransactionResultWithBVP --- .../Services/TransactionResultAppService.cs | 4 ++-- .../BlockChainAppServiceTest.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AElf.WebApp.Application.Chain/Services/TransactionResultAppService.cs b/src/AElf.WebApp.Application.Chain/Services/TransactionResultAppService.cs index 1923b9f989..c382c0a8de 100644 --- a/src/AElf.WebApp.Application.Chain/Services/TransactionResultAppService.cs +++ b/src/AElf.WebApp.Application.Chain/Services/TransactionResultAppService.cs @@ -25,7 +25,7 @@ public interface ITransactionResultAppService { Task GetTransactionResultAsync(string transactionId); - Task GetTransactionResultV2Async(string transactionId); + Task GetTransactionResultWithBVPAsync(string transactionId); Task> GetTransactionResultsAsync(string blockHash, int offset = 0, int limit = 10); @@ -127,7 +127,7 @@ await _transactionResultProxyService.InvalidTransactionResultService.GetInvalidT /// /// transaction id /// - public async Task GetTransactionResultV2Async(string transactionId) + public async Task GetTransactionResultWithBVPAsync(string transactionId) { Hash transactionIdHash; try diff --git a/test/AElf.WebApp.Application.Chain.Tests/BlockChainAppServiceTest.cs b/test/AElf.WebApp.Application.Chain.Tests/BlockChainAppServiceTest.cs index 926798cbe1..d72f7d6d4d 100644 --- a/test/AElf.WebApp.Application.Chain.Tests/BlockChainAppServiceTest.cs +++ b/test/AElf.WebApp.Application.Chain.Tests/BlockChainAppServiceTest.cs @@ -687,7 +687,7 @@ public async Task Get_TransactionResult_Success_Test() } [Fact] - public async Task Get_TransactionResultV2_Expired_Test() + public async Task Get_TransactionResultWithBVP_Expired_Test() { // Generate a transaction var transaction = await _osTestHelper.GenerateTransferTransaction(); @@ -701,7 +701,7 @@ public async Task Get_TransactionResultV2_Expired_Test() // Check transaction status var response = await GetResponseAsObjectAsync( - $"/api/blockChain/transactionResultV2?transactionId={transactionHex}"); + $"/api/blockChain/transactionResultWithBVP?transactionId={transactionHex}"); response.StatusWithBVP.ShouldBe(TransactionResultStatus.Expired.ToString().ToUpper()); } From 03ede965e5951d45186d449ab4a6830e2fb1b09a Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Fri, 3 Jan 2025 16:36:56 +0800 Subject: [PATCH 23/24] Remove inline_transaction.proto --- protobuf/inline_transaction.proto | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 protobuf/inline_transaction.proto diff --git a/protobuf/inline_transaction.proto b/protobuf/inline_transaction.proto deleted file mode 100644 index 8aa96497fe..0000000000 --- a/protobuf/inline_transaction.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -option csharp_namespace = "AElf.Types"; - - -import "aelf/core.proto"; -import "aelf/options.proto"; - -service InlineTransaction { -} - -message InlineTransactionCreated { - option (aelf.is_event) = true; - aelf.Transaction transaction = 1 [(aelf.is_indexed) = true]; -} From 3688493daf8b0c3a8ad80a901c580b33150c25c2 Mon Sep 17 00:00:00 2001 From: chopin-fan Date: Fri, 3 Jan 2025 16:42:49 +0800 Subject: [PATCH 24/24] Remove poseidong --- src/AElf.CSharp.CodeOps/AElf.CSharp.CodeOps.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/AElf.CSharp.CodeOps/AElf.CSharp.CodeOps.csproj b/src/AElf.CSharp.CodeOps/AElf.CSharp.CodeOps.csproj index d931ee9e76..74a45d8ccf 100644 --- a/src/AElf.CSharp.CodeOps/AElf.CSharp.CodeOps.csproj +++ b/src/AElf.CSharp.CodeOps/AElf.CSharp.CodeOps.csproj @@ -11,7 +11,6 @@ -