Skip to content

Commit bd3c012

Browse files
Feature/multisig actor (#83)
Signed-off-by: Alexey-N-Chernyshov <[email protected]>
1 parent 63e5c81 commit bd3c012

25 files changed

+2256
-23
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI
22

3-
on:
3+
on:
44
push:
55
branches:
66
- master

core/primitives/big_int.hpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ namespace fc::primitives {
2929
return static_cast<cpp_int>(lhs) * static_cast<cpp_int>(rhs);
3030
}
3131

32+
static inline BigInt operator*(const BigInt &rhs, unsigned long long lhs) {
33+
return static_cast<cpp_int>(lhs) * static_cast<cpp_int>(rhs);
34+
}
35+
36+
static inline BigInt operator/(const BigInt &lhs, const BigInt &rhs) {
37+
return static_cast<cpp_int>(lhs) / static_cast<cpp_int>(rhs);
38+
}
39+
40+
static inline BigInt operator/(const BigInt &lhs, unsigned long long rhs) {
41+
return static_cast<cpp_int>(lhs) / static_cast<cpp_int>(rhs);
42+
}
43+
3244
static inline BigInt operator+(const BigInt &lhs, const BigInt &rhs) {
3345
return static_cast<cpp_int>(lhs) + static_cast<cpp_int>(rhs);
3446
}
@@ -57,6 +69,10 @@ namespace fc::primitives {
5769
return static_cast<cpp_int>(lhs) < static_cast<cpp_int>(rhs);
5870
}
5971

72+
static inline bool operator<(const BigInt &lhs, unsigned long long rhs) {
73+
return static_cast<cpp_int>(lhs) < rhs;
74+
}
75+
6076
static inline bool operator<(const BigInt &lhs, int rhs) {
6177
return static_cast<cpp_int>(lhs) < rhs;
6278
}
@@ -69,6 +85,14 @@ namespace fc::primitives {
6985
return static_cast<cpp_int>(lhs) == rhs;
7086
}
7187

88+
static inline bool operator==(const UBigInt &lhs, const UBigInt &rhs) {
89+
return static_cast<cpp_int>(lhs) == static_cast<cpp_int>(rhs);
90+
}
91+
92+
static inline bool operator==(const UBigInt &lhs, int rhs) {
93+
return static_cast<cpp_int>(lhs) == static_cast<cpp_int>(rhs);
94+
}
95+
7296
template <class Stream,
7397
class T,
7498
typename = std::enable_if_t<
@@ -85,13 +109,12 @@ namespace fc::primitives {
85109
return s << bytes;
86110
}
87111

88-
template <
89-
class Stream,
90-
class T,
91-
typename = std::enable_if_t<
92-
(std::is_same_v<T, BigInt> || std::is_same_v<T, UBigInt>)&&Stream::
93-
is_cbor_decoder_stream>>
94-
Stream &operator>>(Stream &s, T &big_int) {
112+
template <class Stream,
113+
class T,
114+
typename = std::enable_if_t<
115+
(std::is_same_v<T, BigInt> || std::is_same_v<T, UBigInt>)&&std::
116+
remove_reference_t<Stream>::is_cbor_decoder_stream>>
117+
Stream &operator>>(Stream &&s, T &big_int) {
95118
std::vector<uint8_t> bytes;
96119
s >> bytes;
97120
if (bytes.empty()) {

core/primitives/chain_epoch.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define CPP_FILECOIN_PRIMITIVES_CHAIN_EPOCH_HPP
88

99
#include "libp2p/multi/uvarint.hpp"
10+
#include "primitives/big_int.hpp"
1011

1112
namespace fc::primitives {
1213

@@ -16,6 +17,8 @@ namespace fc::primitives {
1617
*/
1718
using ChainEpoch = libp2p::multi::UVarint;
1819

20+
using EpochDuration = BigInt;
21+
1922
} // namespace fc::primitives
2023

2124
#endif // CPP_FILECOIN_PRIMITIVES_CHAIN_EPOCH_HPP

core/vm/actor/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# SPDX-License-Identifier: Apache-2.0
44
#
55

6+
add_subdirectory(builtin)
7+
68
add_library(actor
79
account_actor.cpp
810
actor.cpp
@@ -17,4 +19,5 @@ target_link_libraries(actor
1719
exit_code
1820
hamt
1921
power_table
22+
multisig_actor
2023
)

core/vm/actor/actor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ namespace fc::vm::actor {
2929
|| code == kInitCodeCid || code == kCronCodeCid;
3030
}
3131

32+
bool isSignableActor(const CodeId &code) {
33+
return code == kAccountCodeCid || code == kMultisigCodeCid;
34+
}
35+
3236
const CID kEmptyObjectCid{
3337
CID::Version::V1,
3438
libp2p::multi::MulticodecType::Code::DAG_CBOR,

core/vm/actor/actor.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ namespace fc::vm::actor {
119119
/** Check if only one instance of actor should exists */
120120
bool isSingletonActor(const CodeId &code);
121121

122+
/** Check if actor code can represent external signing parties */
123+
bool isSignableActor(const CodeId &code);
124+
122125
extern const CID kEmptyObjectCid;
123126

124127
extern const CodeId kAccountCodeCid, kCronCodeCid, kStoragePowerCodeCid,

core/vm/actor/actor_method.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ namespace fc::vm::actor {
1616
using runtime::InvocationOutput;
1717
using runtime::Runtime;
1818

19-
/// Actor method signature
19+
/**
20+
* Actor method signature
21+
* @param Actor - actor itself
22+
* @param Runtime - VM context exposed to actors during method execution
23+
* @param MethodParams - parameters for method call
24+
* @return InvocationOutput - invocation method result or error occurred
25+
*/
2026
using ActorMethod = std::function<outcome::result<InvocationOutput>(
2127
const Actor &, Runtime &, const MethodParams &)>;
2228

@@ -28,7 +34,7 @@ namespace fc::vm::actor {
2834

2935
/// Decode actor params, raises appropriate error
3036
template <typename T>
31-
outcome::result<T> decodeActorParams(gsl::span<const uint8_t> params_bytes) {
37+
outcome::result<T> decodeActorParams(MethodParams params_bytes) {
3238
auto maybe_params = codec::cbor::decode<T>(params_bytes);
3339
if (!maybe_params) {
3440
return VMExitCode::DECODE_ACTOR_PARAMS_ERROR;
@@ -38,12 +44,12 @@ namespace fc::vm::actor {
3844

3945
/// Encode actor params, raises appropriate error
4046
template <typename T>
41-
outcome::result<std::vector<uint8_t>> encodeActorParams(const T &params) {
47+
outcome::result<MethodParams> encodeActorParams(const T &params) {
4248
auto maybe_bytes = codec::cbor::encode(params);
4349
if (!maybe_bytes) {
4450
return VMExitCode::ENCODE_ACTOR_PARAMS_ERROR;
4551
}
46-
return maybe_bytes;
52+
return MethodParams{maybe_bytes.value()};
4753
}
4854
} // namespace fc::vm::actor
4955

core/vm/actor/builtin/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
add_subdirectory(multisig)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
add_library(multisig_actor
7+
multisig_actor.cpp
8+
)
9+
target_link_libraries(multisig_actor
10+
actor
11+
outcome
12+
)

0 commit comments

Comments
 (0)