Skip to content

Commit de0cda9

Browse files
authored
Merge pull request #677 from shutter-network/complex_event_data
Complex event data
2 parents c86532c + e894921 commit de0cda9

9 files changed

Lines changed: 1703 additions & 578 deletions

File tree

docs/event.md

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ An `EventTriggerDefinition` is a structured data object that combines:
2121
trigger the release of the decryption key.
2222

2323
Reference:
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

2828
A `LogPredicate` pairs a reference to a specific value within an event log with
2929
a predicate that must be satisfied for the trigger to fire.
3030

3131
Reference:
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

4655
Reference:
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
5362
and number of arguments required depend on the operation.
5463

5564
Reference:
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
```
6675
EventTriggerDefinitionBytes := {
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
7382
byte, the remaining bytes are RLP-encoded content representing the
7483
`EventTriggerDefinition` structure.
7584

7685
Reference:
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
102110
ValuePredicate := {
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

112120
Reference:
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

139147
Reference:
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

142150
Note, that different operators require different numbers and types of arguments:
143151

@@ -153,20 +161,21 @@ Ethereum log satisfies the `EventTriggerDefinition`:
153161
2. The log must satisfy **all** log predicates (logical `AND` of all conditions)
154162

155163
Reference:
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

160168
To 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

168177
Reference:
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
270279
For types smaller than 32 bytes, they are right-padded (for fixed-size types) or
271280
stored 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.)

rolling-shutter/go.mod

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,29 @@ require (
6060
)
6161

6262
require (
63+
github.com/DataDog/zstd v1.5.5 // indirect
6364
github.com/Microsoft/go-winio v0.6.2 // indirect
65+
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
6466
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
6567
github.com/beorn7/perks v1.0.1 // indirect
6668
github.com/bits-and-blooms/bitset v1.20.0 // indirect
6769
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
6870
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 // indirect
6971
github.com/cespare/xxhash v1.1.0 // indirect
7072
github.com/cespare/xxhash/v2 v2.3.0 // indirect
73+
github.com/cockroachdb/errors v1.11.3 // indirect
74+
github.com/cockroachdb/fifo v0.0.0-20240616162244-4768e80dfb9a // indirect
75+
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
76+
github.com/cockroachdb/pebble v1.1.2 // indirect
77+
github.com/cockroachdb/redact v1.1.5 // indirect
78+
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
7179
github.com/consensys/bavard v0.1.27 // indirect
7280
github.com/consensys/gnark-crypto v0.16.0 // indirect
7381
github.com/containerd/cgroups v1.1.0 // indirect
7482
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
7583
github.com/cosmos/gogoproto v1.4.1 // indirect
7684
github.com/cosmos/gorocksdb v1.2.0 // indirect
85+
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
7786
github.com/crate-crypto/go-eth-kzg v1.3.0 // indirect
7887
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
7988
github.com/creachadair/taskgroup v0.3.2 // indirect
@@ -92,6 +101,7 @@ require (
92101
github.com/francoispqt/gojay v1.2.13 // indirect
93102
github.com/fsnotify/fsnotify v1.7.0 // indirect
94103
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
104+
github.com/getsentry/sentry-go v0.28.1 // indirect
95105
github.com/ghodss/yaml v1.0.0 // indirect
96106
github.com/go-kit/kit v0.12.0 // indirect
97107
github.com/go-kit/log v0.2.1 // indirect
@@ -103,7 +113,9 @@ require (
103113
github.com/go-openapi/swag v0.22.4 // indirect
104114
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
105115
github.com/godbus/dbus/v5 v5.1.0 // indirect
116+
github.com/gofrs/flock v0.8.1 // indirect
106117
github.com/gogo/protobuf v1.3.2 // indirect
118+
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
107119
github.com/golang/protobuf v1.5.4 // indirect
108120
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
109121
github.com/google/btree v1.0.1 // indirect
@@ -119,6 +131,8 @@ require (
119131
github.com/hashicorp/golang-lru v1.0.2 // indirect
120132
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
121133
github.com/hashicorp/hcl v1.0.0 // indirect
134+
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 // indirect
135+
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
122136
github.com/holiman/uint256 v1.3.2 // indirect
123137
github.com/huin/goupnp v1.3.0 // indirect
124138
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -158,12 +172,14 @@ require (
158172
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
159173
github.com/mattn/go-colorable v0.1.13 // indirect
160174
github.com/mattn/go-isatty v0.0.20 // indirect
175+
github.com/mattn/go-runewidth v0.0.16 // indirect
161176
github.com/miekg/dns v1.1.66 // indirect
162177
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
163178
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
164179
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
165180
github.com/minio/highwayhash v1.0.2 // indirect
166181
github.com/minio/sha256-simd v1.0.1 // indirect
182+
github.com/mitchellh/pointerstructure v1.2.1 // indirect
167183
github.com/mmcloughlin/addchain v0.4.0 // indirect
168184
github.com/mr-tron/base58 v1.2.0 // indirect
169185
github.com/multiformats/go-base32 v0.1.0 // indirect
@@ -176,6 +192,7 @@ require (
176192
github.com/multiformats/go-multistream v0.6.0 // indirect
177193
github.com/multiformats/go-varint v0.0.7 // indirect
178194
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
195+
github.com/olekukonko/tablewriter v0.0.5 // indirect
179196
github.com/onsi/ginkgo/v2 v2.22.2 // indirect
180197
github.com/opencontainers/runtime-spec v1.2.0 // indirect
181198
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
@@ -195,6 +212,7 @@ require (
195212
github.com/pion/sdp/v3 v3.0.10 // indirect
196213
github.com/pion/srtp/v3 v3.0.4 // indirect
197214
github.com/pion/stun v0.6.1 // indirect
215+
github.com/pion/stun/v2 v2.0.0 // indirect
198216
github.com/pion/stun/v3 v3.0.0 // indirect
199217
github.com/pion/transport/v2 v2.2.10 // indirect
200218
github.com/pion/transport/v3 v3.0.7 // indirect
@@ -210,8 +228,10 @@ require (
210228
github.com/quic-go/webtransport-go v0.8.1-0.20241018022711-4ac2c9250e66 // indirect
211229
github.com/raulk/go-watchdog v1.3.0 // indirect
212230
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
231+
github.com/rivo/uniseg v0.4.7 // indirect
213232
github.com/rogpeppe/go-internal v1.13.1 // indirect
214233
github.com/rs/cors v1.9.0 // indirect
234+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
215235
github.com/sasha-s/go-deadlock v0.3.1 // indirect
216236
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
217237
github.com/spaolacci/murmur3 v1.1.0 // indirect
@@ -222,8 +242,10 @@ require (
222242
github.com/tendermint/tm-db v0.6.7 // indirect
223243
github.com/tklauser/go-sysconf v0.3.13 // indirect
224244
github.com/tklauser/numcpus v0.7.0 // indirect
245+
github.com/urfave/cli/v2 v2.27.5 // indirect
225246
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
226247
github.com/wlynxg/anet v0.0.5 // indirect
248+
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
227249
github.com/yusufpapurcu/wmi v1.2.3 // indirect
228250
go.etcd.io/bbolt v1.3.7 // indirect
229251
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
@@ -238,11 +260,13 @@ require (
238260
golang.org/x/net v0.40.0 // indirect
239261
golang.org/x/sys v0.33.0 // indirect
240262
golang.org/x/text v0.25.0 // indirect
263+
golang.org/x/time v0.9.0 // indirect
241264
golang.org/x/tools v0.33.0 // indirect
242265
gonum.org/v1/gonum v0.16.0 // indirect
243266
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
244267
google.golang.org/grpc v1.67.1 // indirect
245268
gopkg.in/ini.v1 v1.67.0 // indirect
269+
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
246270
gopkg.in/yaml.v2 v2.4.0 // indirect
247271
lukechampine.com/blake3 v1.4.1 // indirect
248272
rsc.io/tmplfunc v0.0.3 // indirect

0 commit comments

Comments
 (0)