diff --git a/bcos-executor/src/precompiled/extension/PaillierPrecompiled.cpp b/bcos-executor/src/precompiled/extension/PaillierPrecompiled.cpp index 9501d37855..3a5af41ebe 100644 --- a/bcos-executor/src/precompiled/extension/PaillierPrecompiled.cpp +++ b/bcos-executor/src/precompiled/extension/PaillierPrecompiled.cpp @@ -41,11 +41,14 @@ contract Paillier #endif const char* const PAILLIER_METHOD_SET_STR = "paillierAdd(string,string)"; +const char* const PAILLIER_METHOD_ADD_RAW_STR = "paillierAdd(bytes,bytes)"; PaillierPrecompiled::PaillierPrecompiled(const crypto::Hash::Ptr& _hashImpl) : Precompiled(_hashImpl), m_callPaillier(std::make_shared()) { name2Selector[PAILLIER_METHOD_SET_STR] = getFuncSelector(PAILLIER_METHOD_SET_STR, _hashImpl); + name2Selector[PAILLIER_METHOD_ADD_RAW_STR] = + getFuncSelector(PAILLIER_METHOD_ADD_RAW_STR, _hashImpl); } PrecompiledExecResult::Ptr PaillierPrecompiled::call( @@ -82,6 +85,28 @@ PrecompiledExecResult::Ptr PaillierPrecompiled::call( getErrorCodeOut(_callParameters->mutableExecResult(), CODE_INVALID_CIPHERS, codec); } } + else if (func == name2Selector[PAILLIER_METHOD_ADD_RAW_STR] && + blockContext.blockVersion() >= uint32_t(bcos::protocol::BlockVersion::V3_6_VERSION)) + { // paillierAdd(bytes,bytes) + bytes cipher1; + bytes cipher2; + codec.decode(data, cipher1, cipher2); + bytes result; + try + { + result = m_callPaillier->paillierAdd(cipher1, cipher2); + gasPricer->appendOperation(InterfaceOpcode::PaillierAdd); + _callParameters->setExecResult(codec.encode(result)); + } + catch (CallException& e) + { + PRECOMPILED_LOG(INFO) << LOG_BADGE("PaillierPrecompiled") + << LOG_DESC(std::string(e.what())) + << LOG_KV("cipher1", toHex(cipher1)) + << LOG_KV("cipher2", toHex(cipher2)); + getErrorCodeOut(_callParameters->mutableExecResult(), CODE_INVALID_CIPHERS, codec); + } + } else { PRECOMPILED_LOG(ERROR) << LOG_BADGE("PaillierPrecompiled") diff --git a/bcos-executor/src/precompiled/solidity/PaillierPrecompiled.sol b/bcos-executor/src/precompiled/solidity/PaillierPrecompiled.sol index 0b853da8a3..4769f1951a 100644 --- a/bcos-executor/src/precompiled/solidity/PaillierPrecompiled.sol +++ b/bcos-executor/src/precompiled/solidity/PaillierPrecompiled.sol @@ -5,5 +5,10 @@ abstract contract PaillierPrecompiled { function paillierAdd( string memory cipher1, string memory cipher2 - ) public virtual view returns (string memory); + ) public virtual returns (string memory); + + function paillierAdd( + bytes memory cipher1, + bytes memory cipher2 + ) public virtual returns (bytes memory); } diff --git a/cmake/ProjectPaillier.cmake b/cmake/ProjectPaillier.cmake index 863d564571..4f9adf2723 100644 --- a/cmake/ProjectPaillier.cmake +++ b/cmake/ProjectPaillier.cmake @@ -8,11 +8,14 @@ endif() ExternalProject_Add(paillier PREFIX ${CMAKE_SOURCE_DIR}/deps - DOWNLOAD_NAME paillier-1daf3b23.tar.gz + DOWNLOAD_NAME paillier-e1944826.tar.gz DOWNLOAD_NO_PROGRESS 1 - URL https://github.com/FISCO-BCOS/paillier-lib/archive/1daf3b23b01121e8522a8b264be933f6d236fdb8.tar.gz - https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/FISCO-BCOS/deps/paillier-1daf3b23.tar.gz - URL_HASH SHA256=574c8315961ea2ba9534a739675172a0e580ca140c9b2a6fb1008aaf608ae1c9 + # URL https://github.com/FISCO-BCOS/paillier-lib/archive/1daf3b23b01121e8522a8b264be933f6d236fdb8.tar.gz + # https://osp-1257653870.cos.ap-guangzhou.myqcloud.com/FISCO-BCOS/FISCO-BCOS/deps/paillier-1daf3b23.tar.gz + # URL_HASH SHA256=574c8315961ea2ba9534a739675172a0e580ca140c9b2a6fb1008aaf608ae1c9 + URL https://github.com/Shareong/paillier-lib/archive/e1944826ba291a603ff705b3ff8c0cbafa55dcd5.tar.gz + URL_HASH SHA256=bc0cd2d5391961c466651558136432134dd4012e4fdfd4df9d2bcda5fb8404dd + BUILD_IN_SOURCE 1 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release diff --git a/libinitializer/StorageInitializer.h b/libinitializer/StorageInitializer.h index 99ae13a43b..daec086f39 100644 --- a/libinitializer/StorageInitializer.h +++ b/libinitializer/StorageInitializer.h @@ -42,6 +42,7 @@ struct RocksDBOption size_t writeBufferSize = 64 << 20; // 64MB int minWriteBufferNumberToMerge = 1; size_t blockCacheSize = 128 << 20; // 128MB + bool enable_blob_files = false; }; class StorageInitializer @@ -54,9 +55,10 @@ class StorageInitializer rocksdb::DB* db = nullptr; rocksdb::Options options; // Note: This option will increase much memory - // options.IncreaseParallelism(); + // options.IncreaseParallelism(std::thread::hardware_concurrency()); // Note: This option will increase much memory // options.OptimizeLevelStyleCompaction(); + // create the DB if it's not already present options.create_if_missing = true; // to mitigate write stalls @@ -64,6 +66,10 @@ class StorageInitializer options.max_write_buffer_number = rocksDBOption.maxWriteBufferNumber; // FIXME: enable blob support when space amplification is acceptable // options.enable_blob_files = keyPageSize > 1 ? true : false; + options.enable_blob_files = rocksDBOption.enable_blob_files; + options.bytes_per_sync = 1 << 20; // 1MB + // options.level_compaction_dynamic_level_bytes = true; + // options.compaction_pri = rocksdb::kMinOverlappingRatio; options.compression = rocksdb::kZSTD; options.bottommost_compression = rocksdb::kZSTD; // last level compression options.max_open_files = 256; @@ -85,6 +91,7 @@ class StorageInitializer // use bloom filter to optimize point lookup, i.e. get table_options.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, false)); table_options.optimize_filters_for_memory = true; + table_options.block_size = 64 * 1024; // table_options.cache_index_and_filter_blocks = true; // this will increase memory and // lower performance options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(table_options));