@@ -21,15 +21,15 @@ An `EventTriggerDefinition` is a structured data object that combines:
2121 trigger the release of the decryption key.
2222
2323Reference:
24- [ EventTriggerDefinition Type] ( https://github.com/shutter-network/rolling-shutter/blob/42f562532acfc4f89f630d3de809fc4451636ab2 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L21-L25 )
24+ [ EventTriggerDefinition Type] ( https://github.com/shutter-network/rolling-shutter/blob/7b3013978b997dc7507656851c792012f6836241 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L21-L25 )
2525
2626### LogPredicate
2727
2828A ` LogPredicate ` pairs a reference to a specific value within an event log with
2929a predicate that must be satisfied for the trigger to fire.
3030
3131Reference:
32- [ LogPredicate Type] ( https://github.com/shutter-network/rolling-shutter/blob/42f562532acfc4f89f630d3de809fc4451636ab2 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L27-L32 )
32+ [ LogPredicate Type] ( https://github.com/shutter-network/rolling-shutter/blob/7b3013978b997dc7507656851c792012f6836241 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L27-L32 )
3333
3434### LogValueRef
3535
@@ -39,12 +39,21 @@ It can reference:
3939- ** Topics (Offsets 0-3)** : The indexed parameters of the event log. A topic is
4040 referenced by its index (0-3), where offset 0 is topic[ 0] , etc.
4141- ** Data (Offsets 4+)** : The non-indexed data section of the log. Offset
42- values >= 4 refer to 32-byte words in the log data, where offset 4 is the
43- first word (bytes 0-31), offset 5 is the second word (bytes 32-63), etc. Note:
44- data offset always starts at 4, even if there are fewer than 4 topics defined.
42+ values >= 4 refer to slices in the log data, where offset 4 is the first ABI
43+ encoded slice, offset 5 is the second such slice, etc.
44+
45+ - The ` Dynamic ` attribute defines whether data at the offset position should be
46+ read as a single 32 byte word, or, if the offset should be interpreted as an
47+ [ ABI encoding of a data slice] ( https://docs.soliditylang.org/en/latest/abi-spec.html ) ,
48+ where
49+ - ` internal_offset_in_bytes = uint64(WORD@Offset) ` => ` IOIB `
50+ - ` length = uint64(WORD@IOIB) `
51+ - ` dataslice = data[IOIB + 32 : IOIB + 32 + length] `
52+ - Note: data offset always starts at 4, even if there are fewer than 4 topics
53+ defined.
4554
4655Reference:
47- [ LogValueRef Type and Documentation] ( https://github.com/shutter-network/rolling-shutter/blob/42f562532acfc4f89f630d3de809fc4451636ab2 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L34-L43 )
56+ [ LogValueRef Type and Documentation] ( https://github.com/shutter-network/rolling-shutter/blob/7b3013978b997dc7507656851c792012f6836241 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L34-L43 )
4857
4958### ValuePredicate
5059
@@ -53,7 +62,7 @@ log value. It consists of an operation (`Op`) and a set of arguments. The type
5362and number of arguments required depend on the operation.
5463
5564Reference:
56- [ ValuePredicate Type] ( https://github.com/shutter-network/rolling-shutter/blob/42f562532acfc4f89f630d3de809fc4451636ab2 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L45-L53 )
65+ [ ValuePredicate Type] ( https://github.com/shutter-network/rolling-shutter/blob/7b3013978b997dc7507656851c792012f6836241 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L45-L53 )
5766
5867## Encoding Format
5968
@@ -64,21 +73,21 @@ encoding with a version byte prefix:
6473
6574```
6675EventTriggerDefinitionBytes := {
67- version: uint8 // Current version is 0x01
76+ version: uint8 // Current version is 0x02
6877 rlp_encoded_content: []byte // RLP-encoded EventTriggerDefinition
6978}
7079```
7180
72- The version byte (` 0x01 ` ) allows for future format changes. After the version
81+ The version byte (` 0x02 ` ) allows for future format changes. After the version
7382byte, the remaining bytes are RLP-encoded content representing the
7483` EventTriggerDefinition ` structure.
7584
7685Reference:
77- [ MarshalBytes and UnmarshalBytes Implementation] ( https://github.com/shutter-network/rolling-shutter/blob/42f562532acfc4f89f630d3de809fc4451636ab2 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L58-L86 )
86+ [ MarshalBytes and UnmarshalBytes Implementation] ( https://github.com/shutter-network/rolling-shutter/blob/7b3013978b997dc7507656851c792012f6836241 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L58-L86 )
7887
7988### Versioning
8089
81- The current version is ** 0x01 ** as defined by the ` Version ` constant.
90+ The current version is ** 0x02 ** as defined by the ` Version ` constant.
8291
8392### RLP Encoding Details
8493
@@ -96,8 +105,7 @@ LogPredicate := {
96105 valuePredicate: ValuePredicate
97106}
98107
99- LogValueRef := Offset // if Length == 1
100- LogValueRef := [Offset, Length] // if Length > 1
108+ LogValueRef := {Dynamic, Offset}
101109
102110ValuePredicate := {
103111 op: uint64,
@@ -106,11 +114,11 @@ ValuePredicate := {
106114}
107115
108116# actual dense format is more akin to this:
109- [contract_address, [[offset, [op, [int_args], [byte_args]]], […]]]
117+ [contract_address, [[dynamic, offset, [op, [int_args], [byte_args]]], […]]]
110118```
111119
112120Reference:
113- [ RLP Encoding Implementation] ( https://github.com/shutter-network/rolling-shutter/blob/42f562532acfc4f89f630d3de809fc4451636ab2 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L211-L392 )
121+ [ RLP Encoding Implementation] ( https://github.com/shutter-network/rolling-shutter/blob/7b3013978b997dc7507656851c792012f6836241 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L208-L414 )
114122
115123## Operators
116124
@@ -137,7 +145,7 @@ value predicate.
137145 - Returns true if value == argument (byte-by-byte comparison)
138146
139147Reference:
140- [ Operator Constants] ( https://github.com/shutter-network/rolling-shutter/blob/42f562532acfc4f89f630d3de809fc4451636ab2 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L298-L305 )
148+ [ Operator Constants] ( https://github.com/shutter-network/rolling-shutter/blob/7b3013978b997dc7507656851c792012f6836241 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L320-L327 )
141149
142150Note, that different operators require different numbers and types of arguments:
143151
@@ -153,20 +161,21 @@ Ethereum log satisfies the `EventTriggerDefinition`:
1531612 . The log must satisfy ** all** log predicates (logical ` AND ` of all conditions)
154162
155163Reference:
156- [ Match Method] ( https://github.com/shutter-network/rolling-shutter/blob/42f562532acfc4f89f630d3de809fc4451636ab2 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L159-L176 )
164+ [ Match Method] ( https://github.com/shutter-network/rolling-shutter/blob/7b3013978b997dc7507656851c792012f6836241 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L161-L179 )
157165
158166### LogValueRef.GetValue
159167
160168To retrieve a value from a log:
161169
162170- ** Topics (Offset < 4)** : Returns the log's topic at index Offset as a 32-byte
163171 value
164- - ** Data (Offset >= 4)** : Extracts a slice of 32-byte words from the log's data,
165- starting at word index (Offset - 4). If the slice extends beyond the log's
166- data, it is zero-padded on the right to the expected length.
172+ - ** Data (Offset >= 4)** : Extracts a slice from the log's data, starting at word
173+ index (Offset - 4). The length of the slice is defined in the log data
174+ according to the
175+ [ ABI event encoding spec] ( https://docs.soliditylang.org/en/latest/abi-spec.html ) .
167176
168177Reference:
169- [ GetValue Method ] ( https://github.com/shutter-network/rolling-shutter/blob/main /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L210-L228 )
178+ [ GetValue Methods ] ( https://github.com/shutter-network/rolling-shutter/blob/7b3013978b997dc7507656851c792012f6836241 /rolling-shutter/keyperimpl/shutterservice/eventtrigger.go#L246-L318 )
170179
171180## Generating EventTriggerDefinition from EVM Contract ABI
172181
@@ -214,16 +223,16 @@ function generateEventTriggerDefinition(
214223 if (param.indexed) {
215224 // Topics are at offsets 0-3
216225 offset = calculateTopicIndex(event, param)
217- length = 1
218226 } else {
219227 // Data starts at offset 4
220228 offset = 4 + calculateDataWordOffset(event, param)
221- length = calculateDataWordLength(param.type)
222229 }
223230
231+ dynamic = decide_if_dynamic_type(param.type)
232+
224233 logValueRef = LogValueRef{
234+ Dynamic: dynamic,
225235 Offset: offset,
226- Length: length
227236 }
228237
229238 // Create the ValuePredicate
@@ -270,6 +279,10 @@ Non-indexed parameters are stored in the log's data field. They are packed as
270279For types smaller than 32 bytes, they are right-padded (for fixed-size types) or
271280stored in a single word.
272281
282+ However, for ` Dynamic ` types, the words only specify an internal offset to
283+ another word that encodes the data slices length. The actual data will be at
284+ ` internal_offset + 32 ` and be ` length ` bytes long.
285+
273286## Examples
274287
275288### Example 1: ERC20 Transfer Trigger
@@ -302,8 +315,7 @@ Trigger when a specific address transfers tokens:
302315 "logPredicates" : [
303316 {
304317 "logValueRef" : {
305- "offset" : 1 ,
306- "length" : 1
318+ "offset" : 1
307319 },
308320 "valuePredicate" : {
309321 "op" : 5 ,
@@ -349,8 +361,7 @@ Trigger when a swap occurs with minimum token amount:
349361 "logPredicates" : [
350362 {
351363 "logValueRef" : {
352- "offset" : 1 ,
353- "length" : 1
364+ "offset" : 1
354365 },
355366 "valuePredicate" : {
356367 "op" : 5 ,
@@ -362,8 +373,7 @@ Trigger when a swap occurs with minimum token amount:
362373 },
363374 {
364375 "logValueRef" : {
365- "offset" : 5 ,
366- "length" : 1
376+ "offset" : 5
367377 },
368378 "valuePredicate" : {
369379 "op" : 4 ,
@@ -374,3 +384,7 @@ Trigger when a swap occurs with minimum token amount:
374384 ]
375385}
376386```
387+
388+ Note: an example for an event trigger definition compiler can be found in
389+ [ shutter-api] ( https://github.com/shutter-network/shutter-api ) (the
390+ ` /event/compile_event_trigger_definition ` endpoint.)
0 commit comments