@ethernity-cloud/sdk-js 1.5.15 → 1.5.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/info.js +324 -324
- package/nodenithy/build/securelock/.ecld-test-stage/ecld_state.js +815 -761
- package/nodenithy/build/securelock/.ecld-test-stage/esr_local.js +12 -8
- package/nodenithy/build/securelock/.ecld-test-stage/nonce_ladder.js +165 -138
- package/nodenithy/build/securelock/src/ecld_state.js +815 -761
- package/nodenithy/build/securelock/src/esr_local.js +12 -8
- package/nodenithy/build/securelock/src/etny_exec.js +5 -0
- package/nodenithy/build/securelock/src/task_status.js +6 -0
- package/package.json +1 -1
- package/test.js +2 -0
|
@@ -104,8 +104,10 @@ class MemContract {
|
|
|
104
104
|
return ethers.BigNumber.from(e ? e.version : 0);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
async relayNonce(enclave) {
|
|
108
|
-
|
|
107
|
+
async relayNonce(enclave, keyHash) {
|
|
108
|
+
// Per (enclave, key), like the contract: same-key commits serialize,
|
|
109
|
+
// different keys are independent.
|
|
110
|
+
return ethers.BigNumber.from(this._nonce[key(enclave, keyHash)] || 0);
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
async commitDigest(enclave, keyHash, cid, expectedVersion, relayNonce, nonce = 0) {
|
|
@@ -128,9 +130,10 @@ class MemContract {
|
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
// ---- the on-chain commitFor, applied locally ----
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
//
|
|
133
|
+
// The per-key nonce advances by EXACTLY 1 on every commit, like the
|
|
134
|
+
// contract: nonce == 0 ("omitted") gets the next value assigned by the
|
|
135
|
+
// registry itself; a non-zero nonce is a client-pinned guard and must be
|
|
136
|
+
// EXACTLY the stored value + 1 (no gaps, no reuse) or NonceOutOfOrder.
|
|
134
137
|
applyCommit(enclave, keyHash, cid, expectedVersion, nonce = 0) {
|
|
135
138
|
const k = key(enclave, keyHash);
|
|
136
139
|
const entry = this._entries[k] || {};
|
|
@@ -140,15 +143,16 @@ class MemContract {
|
|
|
140
143
|
}
|
|
141
144
|
let storedNonce = Number(entry.nonce || 0);
|
|
142
145
|
const n = Number(nonce || 0);
|
|
143
|
-
if (n
|
|
146
|
+
if (n === 0) {
|
|
147
|
+
storedNonce += 1;
|
|
148
|
+
} else {
|
|
144
149
|
if (n !== storedNonce + 1) {
|
|
145
150
|
throw new Error(`NonceOutOfOrder: stored ${storedNonce}, given ${n}`);
|
|
146
151
|
}
|
|
147
152
|
storedNonce = n;
|
|
148
153
|
}
|
|
149
154
|
this._entries[k] = { cid, version: cur + 1, updatedAt: 0, nonce: storedNonce };
|
|
150
|
-
|
|
151
|
-
this._nonce[e] = (this._nonce[e] || 0) + 1;
|
|
155
|
+
this._nonce[k] = (this._nonce[k] || 0) + 1;
|
|
152
156
|
this._persist();
|
|
153
157
|
}
|
|
154
158
|
}
|
|
@@ -210,6 +210,11 @@ async function exec(payload, input, globals = null) {
|
|
|
210
210
|
if (error && error.constructor && error.constructor.name === 'StateNonceError') {
|
|
211
211
|
return [TaskStatus.ESR_NONCE_VIOLATION, 'ESR_NONCE_VIOLATION: ' + error.message];
|
|
212
212
|
}
|
|
213
|
+
// Over the per-run commit cap (100): the over-limit commit was NOT
|
|
214
|
+
// applied; the earlier commits stand and will be relayed.
|
|
215
|
+
if (error && error.constructor && error.constructor.name === 'StateLimitError') {
|
|
216
|
+
return [TaskStatus.ESR_COMMIT_LIMIT_EXCEEDED, 'ESR_COMMIT_LIMIT_EXCEEDED: ' + error.message];
|
|
217
|
+
}
|
|
213
218
|
const detail = (error && (error.stack || error.message)) || String(error);
|
|
214
219
|
console.error('Error in payload execution -- full stack follows:\n' + detail);
|
|
215
220
|
|
|
@@ -19,6 +19,12 @@ class TaskStatus {
|
|
|
19
19
|
static ESR_GAS_LIMIT_EXCEEDED = 34; // ESR commits would exceed the per-order relayed-gas budget.
|
|
20
20
|
static SECURITY_VIOLATION = 35; // A state commit was authorized under a caller other than
|
|
21
21
|
static ESR_NONCE_VIOLATION = 36; // A commit's idempotency nonce was already used -- duplicate
|
|
22
|
+
// The enclave signed state commits but they did not land on the registry
|
|
23
|
+
// within 5 blocks -- the node did not relay them. The validator REFUNDS.
|
|
24
|
+
static ESR_RELAY_TIMEOUT = 37;
|
|
25
|
+
// More than 100 state commits in one run -- the per-run cap that bounds
|
|
26
|
+
// relayed transactions and the result size. dApp-side fault: NO refund.
|
|
27
|
+
static ESR_COMMIT_LIMIT_EXCEEDED = 38;
|
|
22
28
|
// suppressed, state unchanged (StateNonceError).
|
|
23
29
|
// the task's submitter (the in-enclave ownership check was
|
|
24
30
|
// bypassed). Set by the securelock on a detected forged
|
package/package.json
CHANGED
package/test.js
CHANGED
|
@@ -58,6 +58,8 @@ const TASK_STATUS_NAMES = {
|
|
|
58
58
|
34: 'ESR_GAS_LIMIT_EXCEEDED',
|
|
59
59
|
35: 'SECURITY_VIOLATION',
|
|
60
60
|
36: 'ESR_NONCE_VIOLATION',
|
|
61
|
+
37: 'ESR_RELAY_TIMEOUT',
|
|
62
|
+
38: 'ESR_COMMIT_LIMIT_EXCEEDED',
|
|
61
63
|
};
|
|
62
64
|
|
|
63
65
|
const VENDORED_SRC = path.join(__dirname, 'nodenithy', 'build', 'securelock', 'src');
|