Skip to content

Commit 7bb710c

Browse files
Add MCMS contracts suite + tests (Tolk) (#43)
* Add drawio example support, document Ownable2Step flow * Add RBACTimelock drawio flow diagram * Polish diagrams * Add color to differentiate op, deploy, and log type of messages * Polish diagrams * Flow chart polish * Add Timelock contract (Tolk) MVP * Remove package-lock.json and add Tolk extension * Update Timelock to tolk 0.13, update NPM packages, update storage management * Trait composition model (admin actions) * Upgrade to tolk 0.99 * Split out contracts/lib/access/access_control.tolk, upgrade to tolk 0.99, format * Remove global storage * Add basic admin role check/modifer to timelock * AC union message type * Rewrite lib/access/access_control.tolk * Separate underlying data from trait and hooks * Fix compile issues * Add lib/access/extension/access_control_enumerable.tolk * Add a generic super (extensions) chain for Traits * Polish docs, remove Ownable example * Add AccessControlEnumerable<T> trait hooks type (reusing AccessControl<T> hooks) * Polish and simplify AC composition structure * Add 'AccessControl_RenounceRole' msg handler * Namespace hooks - AccessControlEnumerable_Hooks<T> * Work on TS bindings * Add lib/access/extension/AccessControlEnumerable bindigs, disable failing tests * Add test * Fix data structure encoding/decoding, debug context mutability * Simplify ACE composition * Fix rebase * Update deps * Merge lib/access/extension/AccessControlEnumerable with lib/access/AccessControl * Remove lib/access/extension/AccessControlEnumerable * AC - Reconstruct the address from the key * Remove tests/libraries/access/Ownable2Step.spec.ts (duplicate) * Move 'tests/libraries/merkle_proof' to 'tests/lib/merkle_proof' * Update contracts to tolk 1.0 * Update to use sDict vs uDict for AccessControl_RoleData.hasRole dict * Add AC contract docs * Add outgoing message definitions to AC contract * Send AC outgoing messages on changes * Fix rebase, move utils.tolk, fmt * Add tolk lazy * Remove unused timelock utils * Add Timelock docs and outgoing message structs * Add Timelock incoming message structs * Set up Timelock contract struct with data and hooks * Add hashOperationBatch fn * Add Timelock<T>.blockedFnSelectors storage and fns * Add Timelock<T>.checkFunctionSelectorNotBlocked fn * Add Timelock fns that manage timestamps * Implement block/unblock fn selector * Add Timelock<T>.executeBatch fn * Add Timelock<T>.scheduleBatch/cancel fns * Add Timelock<T>.init fn * Iterate over collections * Add Timelock<T>.updateDelay fn * Add Timelock<T>.bypasserExecuteBatch fn + polish args * Add Timelock_InMessage processing + fixes * Cleanup Timelock admin fns * Add Timelock_TopUp opcode * Remove unused opcode handling and code/files * Polish, rename, move paths * Add Timelock TS bindings * Add Timelock contract data and call encoders * Expose Timelock getters * Simplify Timelock message handling, storage updates * self.context is now optional * Polish Timelock role bindings, enable few tests, remove unused getter bindings * Restructure onInternalMessage handling * Enable and add more Timelock/AC tests * Polish ts bindings, add update delay test * Add the rest of Timelock TS getters, add more tests * Add missing TS getter bindings and polish * Enable sendScheduleBatch test, fix opcode bug * Fix post rebase Nix yarn.lock hash * Fix Timelock_CallScheduled msg size * Timestamp as unit64 * PR comments * Add MCMS and CallProxy contracts (#77) * Add Timelock incoming message structs * Upgrade to tolk 0.99 Add MCMS contract (init) Add MCMC contract method structure and errors Add MCMC outgoing messages/events structs Add default execute hook and getters Add MCMS<T>.execute fn Resolve MCMS_Execute msg size issue Add MCMS<T>.setConfig fn impl Add Ownable2Step to MCMS Restructure MCMS data storage to avoid limits Add MCMS signature verification Add MCMS TS bindings (structs, errors) Add MCMS TS bindings (msgs, getters) Add MCMS<T>.setRoot group quorum checks Finish MCMS<T>.setRoot fn Add MCMS MerkleProof verify Fix rebase Typo Add more MCMS.ts bindings [WIP] Add MCMS deploy test (+bindings) Add MCMS chain ID (globalId) check Encode address? (Option) properly Add uint32 ID to contract for multiple instances Polish bindings More bindings structure polish Start translating EVM test/IntegrationTest.t.sol Add CallProxy contract Refactor Counter/Ownable2Step contracts and bindings MCMS integration test - add counter deploy Remove 'contracts/contracts/examples/counter_legacy.tact' and update Go bindings deleted: ../contracts/wrappers/CounterLegacy.compile.ts Replace tracetracking-specific counter bindings Fix lint and add tolk 1.0 declaration to /examples/counter.tolk Use wrappers.Deploy to fix deploy timing issue Fix msg (opcode) serialization issue Fix Timelock<T>.bypasserExecuteBatch (reply vs. event emit) Fix rbac_timelock.tolk value:0 reply, replace with emit Fix rbac_timelock.hashOperationBatch TS binding * Post rebase fixes * [NONEVM-2276] TS tests Timelock Cancel&BlockFunction (#89) test: base test setup test: timelock cancel test: block function * [NONEVM-2276] TS tests Timelock Hashing (#93) test: Timelock Hashing * [NONEVM-2276] TS tests Timelock Getters (#95) test: timelock getters * [NONEVM-2276] TS tests Timelock Receivable (#94) test: timelock receivable * [NONEVM-2276] TS tests Timelock Schedule Batch (#96) test: timelock schedule batch * [NONEVM-2276] TS tests Timelock Update Delay (#98) test: timelock update delay * Post-rebase fixes --------- Co-authored-by: Patricio <[email protected]> --------- Co-authored-by: Patricio <[email protected]>
1 parent 5631f3d commit 7bb710c

File tree

81 files changed

+11341
-8605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+11341
-8605
lines changed

.devcontainer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
"kamadorueda.alejandra",
1515
// Tact language support for VS Code
1616
"tonstudio.vscode-tact",
17+
// Tolk language support for VS Code
18+
"ton-core.tolk-vscode",
1719
// Go language support for VS Code
18-
"golang.go"
20+
"golang.go",
21+
// Draw.io diagram support for VS Code
22+
"hediet.vscode-drawio"
1923
]
2024
}
2125
},

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nodejs 23.11.1
1+
nodejs 24.3.0

contracts/contracts/ccip/offramp.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "types.tolk";
22
import "../lib/access/ownable_2step.tolk";
33
import "../lib/upgrades/type_and_version.tolk";
4-
import "./../lib/merkle_multi_proof/merkle_multi_proof.tolk"
4+
import "../lib/crypto/merkle_multi_proof.tolk"
55
import "../deployable/types.tolk";
66
import "../lib/utils.tolk";
77
import "../lib/ocr/multi_ocr3_base";

contracts/contracts/test/examples/counter.tolk renamed to contracts/contracts/examples/counter.tolk

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
tolk 1.0
2+
13
import "@stdlib/common.tolk"
2-
import "../../lib/upgrades/type_and_version.tolk"
3-
import "../../lib/utils.tolk"
4+
import "../lib/upgrades/type_and_version.tolk"
5+
import "../lib/utils.tolk"
6+
import "../lib/access/ownable_2step.tolk"
47

58
/// Counter contract + event emission (Tolk example)
69
/// Message to set the counter value.
@@ -33,6 +36,8 @@ struct CountIncreased {
3336
struct Storage {
3437
id: uint32
3538
value: uint32
39+
40+
ownable: Ownable2Step
3641
}
3742

3843
fun Storage.load(): Storage {
@@ -51,38 +56,53 @@ fun onInternalMessage(in: InMessage) {
5156
SetCount => {
5257
/// Instructs the contract to set the counter.
5358
var st = lazy Storage.load();
59+
st.ownable.requireOwner(in.senderAddress);
5460
st.value = msg.newCount;
5561
st.store();
5662
emit<CountSet>(COUNT_SET_TOPIC, { id: st.id, value: st.value });
5763
}
5864
IncreaseCount => {
5965
/// Instructs the contract to increase the counter.
6066
var st = lazy Storage.load();
67+
st.ownable.requireOwner(in.senderAddress);
6168
st.value = st.value + 1;
6269
st.store();
6370
emit<CountIncreased>(COUNT_INCREASED_TOPIC, { id: st.id, value: st.value });
6471
}
6572
else => {
66-
// ignore empty messages, "wrong opcode" for others
67-
assert (in.body.isEmpty()) throw 0xFFFF;
73+
var st = lazy Storage.load();
74+
val msgHandled = 0
75+
|| st.ownable.onInternalMessage(in.senderAddress, in.body);
76+
st.store();
77+
78+
if (!msgHandled) {
79+
// If the message was not handled
80+
// ignore empty messages, "wrong opcode" for others
81+
assert (in.body.isEmpty()) throw ERROR_WRONG_OP;
82+
}
6883
}
6984
}
7085
}
7186

87+
get fun owner(): address {
88+
val s = lazy Storage.load();
89+
return s.ownable.get_owner();
90+
}
91+
7292
/// Gets the current id of the contract.
7393
get fun id(): int {
74-
val storage = Storage.load();
75-
return storage.id;
94+
val s = lazy Storage.load();
95+
return s.id;
7696
}
7797

7898
/// Gets the current counter value.
7999
get fun value(): int {
80-
val storage = Storage.load();
81-
return storage.value;
100+
val s = lazy Storage.load();
101+
return s.value;
82102
}
83103

84104
/// Gets the current type and version of the contract.
85105
get fun typeAndVersion(): (slice, slice) {
86-
return TypeAndVersion { typeStr: "com.chainlink.ton.examples.Counter", versionStr: "1.0.0" }
106+
return TypeAndVersion { typeStr: "com.chainlink.ton.examples.Counter", versionStr: "1.1.0" }
87107
.typeAndVersion();
88108
}

0 commit comments

Comments
 (0)