@ocap/tx-protocols 1.18.130 → 1.18.132

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/lib/execute.js CHANGED
@@ -30,7 +30,7 @@ module.exports = ({ filter, runAsLambda }) => {
30
30
  // pipeline before executing the transaction
31
31
  const pre = new Runner();
32
32
  pre.use(pipes.DecodeTx);
33
- pre.use(pipes.VerifyBlocked(filter));
33
+ pre.use(pipes.VerifyBlocked({ filter, stateKeys: ['tx.from'] }));
34
34
  pre.use(pipes.DecodeItx);
35
35
  pre.use(pipes.VerifyTx);
36
36
  pre.use(pipes.VerifyServiceFee);
@@ -127,7 +127,7 @@ module.exports = ({ filter, runAsLambda }) => {
127
127
  try {
128
128
  await runAsLambda((txn) => {
129
129
  // create a new context each time in case we are retrying
130
- ctx = pick(context, ['txBase64', 'statedb', 'indexdb', 'config', 'states', 'extra']);
130
+ ctx = pick(context, ['txBase64', 'statedb', 'indexdb', 'config', 'states', 'filter', 'extra']);
131
131
  Object.defineProperty(ctx, 'txn', { value: txn });
132
132
  return execute(ctx, protocols, true);
133
133
  });
@@ -99,8 +99,12 @@ runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: '
99
99
 
100
100
  // Ensure receiver exist and not migrated
101
101
  runner.use(pipes.ExtractState({ from: 'itx.to', to: 'receiverState', status: 'OK', table: 'account' }));
102
+ runner.use(pipes.VerifyBlocked({ stateKeys: ['receiverState'] }));
102
103
  runner.use(pipes.VerifyAccountMigration({ stateKey: 'receiverState', addressKey: 'itx.to' }));
103
104
 
105
+ // Ensure sender and receiver are not the same
106
+ runner.use(pipes.AntiLandAttack({ senderState: 'senderState', receiverState: 'receiverState' }));
107
+
104
108
  // Extract delegation
105
109
  runner.use(pipes.ExtractState({ from: 'itx.address', to: 'delegationState', table: 'delegation', status: 'OK' }));
106
110
 
@@ -110,6 +110,7 @@ runner.use(pipes.ExtractState({ from: 'tokenAddress', to: 'tokenStates', status:
110
110
  runner.use(verifyMintLimit);
111
111
  runner.use(verifyItxVariables);
112
112
  runner.use(verifyItxAddress('acquire-v2'));
113
+ runner.use(pipes.VerifyBlocked({ stateKeys: ['assetOwner'] }));
113
114
  runner.use(async (context, next) => {
114
115
  const { factoryTokens, senderState } = context;
115
116
  const condition = {
@@ -137,6 +137,7 @@ runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'OK'
137
137
  runner.use(pipes.ExtractState({ from: 'senders', to: 'signerStates', status: 'INVALID_SIGNER_STATE', table: 'account' })); // prettier-ignore
138
138
  runner.use(pipes.ExtractState({ from: 'itx.owner', to: 'ownerState', status: 'OK', table: 'account' }));
139
139
  runner.use(pipes.VerifyAccountMigration({ signerKey: 'signerStates', stateKey: 'senderState', addressKey: 'tx.from' }));
140
+ runner.use(pipes.VerifyBlocked({ stateKeys: ['signerStates', 'ownerState'] }));
140
141
 
141
142
  // 6. verify token state and balance
142
143
  runner.use(pipes.ExtractState({ from: 'tokens', to: 'tokenStates', status: 'INVALID_TOKEN', table: 'token' }));
@@ -61,6 +61,7 @@ runner.use(pipes.ExtractState({ from: 'factoryState.owner', to: 'factoryOwnerSta
61
61
  runner.use(pipes.ExtractState({ from: 'factoryState.trustedIssuers', to: 'issuerStates', status: 'INVALID_ISSUER_STATE' , table: 'account'})); // prettier-ignore
62
62
 
63
63
  runner.use(pipes.ExtractState({ from: 'itx.owner', to: 'ownerState', status: 'OK', table: 'account' }));
64
+ runner.use(pipes.VerifyBlocked({ stateKeys: ['ownerState'] }));
64
65
  runner.use(
65
66
  pipes.VerifyInfo([
66
67
  {
@@ -57,6 +57,7 @@ runner.use(pipes.VerifyListSize({ listKey: ['outputs', 'receivers', 'tokens', 'a
57
57
  // 4. verify sender & receiver
58
58
  runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })); // prettier-ignore
59
59
  runner.use(pipes.ExtractState({ from: 'receivers', to: 'receiverStates', status: 'INVALID_RECEIVER_STATE', table: 'account' })); // prettier-ignore
60
+ runner.use(pipes.VerifyBlocked({ stateKeys: ['receiverStates'] }));
60
61
  runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: 'tx.from' }));
61
62
 
62
63
  // 5. verify stake state
@@ -56,6 +56,7 @@ runner.use(pipes.VerifyListSize({ listKey: ['outputs', 'receivers', 'tokens', 'a
56
56
  // 4. verify sender & receiver
57
57
  runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })); // prettier-ignore
58
58
  runner.use(pipes.ExtractState({ from: 'receivers', to: 'receiverStates', status: 'INVALID_RECEIVER_STATE', table: 'account' })); // prettier-ignore
59
+ runner.use(pipes.VerifyBlocked({ stateKeys: ['receiverStates'] }));
59
60
  runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: 'tx.from' }));
60
61
 
61
62
  // 5. verify stake state
@@ -57,6 +57,7 @@ runner.use(pipes.VerifyListSize({ listKey: ['outputs', 'receivers', 'tokens', 'a
57
57
  // 4. verify sender & receiver
58
58
  runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })); // prettier-ignore
59
59
  runner.use(pipes.ExtractState({ from: 'receivers', to: 'receiverStates', status: 'INVALID_RECEIVER_STATE', table: 'account' })); // prettier-ignore
60
+ runner.use(pipes.VerifyBlocked({ stateKeys: ['receiverStates'] }));
60
61
  runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: 'tx.from' }));
61
62
 
62
63
  // 5. verify stake state
@@ -81,6 +81,7 @@ runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'OK'
81
81
  runner.use(pipes.ExtractState({ from: 'senders', to: 'signerStates', status: 'INVALID_SIGNER_STATE', table: 'account' })); // prettier-ignore
82
82
  runner.use(pipes.VerifyAccountMigration({ signerKey: 'signerStates', stateKey: 'senderState', addressKey: 'tx.from' }));
83
83
  runner.use(pipes.ExtractState({ from: 'itx.receiver', to: 'receiverState', status: 'INVALID_RECEIVER_STATE' })); // can by any type
84
+ runner.use(pipes.VerifyBlocked({ stateKeys: ['signerStates', 'receiverState'] }));
84
85
  runner.use(pipes.VerifyAccountMigration({ stateKey: 'receiverState', addressKey: 'itx.receiver' }));
85
86
 
86
87
  // 6. verify token state and balance
@@ -61,7 +61,6 @@ runner.use(pipes.ExtractState({ from: 'itx.token.address', to: 'tokenState', sta
61
61
 
62
62
  // 4. verify sender and signer states
63
63
  runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })); // prettier-ignore
64
- runner.use(pipes.VerifyAccountMigration({ stateKey: 'senderState', addressKey: 'tx.from' }));
65
64
 
66
65
  // 5. verify amount
67
66
  runner.use((context, next) => {
@@ -146,6 +145,10 @@ runner.use((context, next) => {
146
145
  verifyMultiSigV2(context, next);
147
146
  });
148
147
 
148
+ // 7. verify signers (sender + proposer)
149
+ runner.use(pipes.ExtractState({ from: 'signers', to: 'signerStates', status: 'INVALID_SIGNER_STATE', table: 'account' })); // prettier-ignore
150
+ runner.use(pipes.VerifyAccountMigration({ signerKey: 'signerStates', stateKey: 'senderState', addressKey: 'tx.from' }));
151
+
149
152
  // 8. verify staking: user withdraw is locked in stake
150
153
  runner.use((context, next) => {
151
154
  const { itx, senderState } = context;
@@ -87,8 +87,6 @@ runner.use(pipes.VerifySigner({ signer: 'itx.to' }));
87
87
  runner.use(pipes.VerifyListSize({ listKey: ['senderAssets', 'receiverAssets'] }));
88
88
  runner.use(pipes.VerifyListSize({ listKey: ['senderTokens', 'receiverTokens'] }));
89
89
 
90
- // TODO: anti-replay-exchange-attack
91
-
92
90
  runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'INVALID_SENDER_STATE', table: 'account' })); // prettier-ignore
93
91
  runner.use(pipes.ExtractState({ from: 'tx.delegator', to: 'delegatorState', status: 'OK', table: 'account' }));
94
92
  runner.use(pipes.VerifyDelegation({ type: 'signature', signerKey: 'senderState', delegatorKey: 'delegatorState' }));
@@ -123,6 +121,7 @@ runner.use(pipes.VerifyTokenBalance({ ownerKey: 'senderState', conditionKey: 'se
123
121
  runner.use(pipes.VerifyTokenBalance({ ownerKey: 'receiverState', conditionKey: 'receiverTokenConditions' }));
124
122
 
125
123
  runner.use(pipes.AntiLandAttack({ senderState: 'senderState', receiverState: 'receiverState' }));
124
+ runner.use(pipes.VerifyBlocked({ stateKeys: ['senderState', 'receiverState'] }));
126
125
 
127
126
  runner.use(pipes.ExtractState({ from: 'senderAssets', to: 'priv.senderAssets', status: 'INVALID_ASSET', table: 'asset' })); // prettier-ignore
128
127
  runner.use(pipes.VerifyTransferrable({ assets: 'priv.senderAssets' }));
@@ -112,6 +112,7 @@ runner.use(
112
112
  runner.use(pipes.ExtractReceiver({ from: 'itx.to', to: 'receiver' }));
113
113
  runner.use(pipes.ExtractState({ from: 'receiver', to: 'receiverState', status: 'OK', table: 'account' }));
114
114
  runner.use(pipes.AntiLandAttack({ senderState: 'senderState', receiverState: 'receiverState' }));
115
+ runner.use(pipes.VerifyBlocked({ stateKeys: ['senderState', 'receiverState'] }));
115
116
 
116
117
  runner.use(pipes.ExtractState({ from: 'assets', to: 'assetStates', status: 'INVALID_ASSET', table: 'asset' }));
117
118
  runner.use(pipes.VerifyTransferrable({ assets: 'assetStates' }));
@@ -127,6 +127,7 @@ runner.use(pipes.VerifyMultiSigV2({ signersKey: 'senders' }));
127
127
  runner.use(pipes.ExtractState({ from: 'tx.from', to: 'senderState', status: 'OK', table: 'account' }));
128
128
  runner.use(pipes.ExtractState({ from: 'senders', to: 'signerStates', status: 'INVALID_SIGNER_STATE', table: 'account' })); // prettier-ignore
129
129
  runner.use(pipes.ExtractState({ from: 'receivers', to: 'receiverStates', status: 'OK', table: 'account' }));
130
+ runner.use(pipes.VerifyBlocked({ stateKeys: ['signerStates', 'receiverStates'] }));
130
131
  runner.use(pipes.AntiLandAttack({ senderState: 'signerStates', receiverState: 'receiverStates' }));
131
132
  runner.use(pipes.VerifyAccountMigration({ signerKey: 'signerStates', stateKey: 'senderState', addressKey: 'tx.from' }));
132
133
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.18.130",
6
+ "version": "1.18.132",
7
7
  "description": "Predefined tx pipeline sets to execute certain type of transactions",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -21,18 +21,18 @@
21
21
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@arcblock/did": "1.18.130",
25
- "@arcblock/did-util": "1.18.130",
26
- "@arcblock/jwt": "1.18.130",
27
- "@arcblock/validator": "1.18.130",
28
- "@ocap/asset": "1.18.130",
29
- "@ocap/mcrypto": "1.18.130",
30
- "@ocap/merkle-tree": "1.18.130",
31
- "@ocap/message": "1.18.130",
32
- "@ocap/state": "1.18.130",
33
- "@ocap/tx-pipeline": "1.18.130",
34
- "@ocap/util": "1.18.130",
35
- "@ocap/wallet": "1.18.130",
24
+ "@arcblock/did": "1.18.132",
25
+ "@arcblock/did-util": "1.18.132",
26
+ "@arcblock/jwt": "1.18.132",
27
+ "@arcblock/validator": "1.18.132",
28
+ "@ocap/asset": "1.18.132",
29
+ "@ocap/mcrypto": "1.18.132",
30
+ "@ocap/merkle-tree": "1.18.132",
31
+ "@ocap/message": "1.18.132",
32
+ "@ocap/state": "1.18.132",
33
+ "@ocap/tx-pipeline": "1.18.132",
34
+ "@ocap/util": "1.18.132",
35
+ "@ocap/wallet": "1.18.132",
36
36
  "debug": "^4.3.4",
37
37
  "deep-diff": "^1.0.2",
38
38
  "empty-value": "^1.0.1",
@@ -47,5 +47,5 @@
47
47
  "jest": "^27.5.1",
48
48
  "start-server-and-test": "^1.14.0"
49
49
  },
50
- "gitHead": "d4846249beb92ef45faad7a23781f631523f288e"
50
+ "gitHead": "6699d47364eb94f564e0fcf6ea55b6e7ea005d0d"
51
51
  }