Skip to content

Commit a1a3c33

Browse files
authored
Merge branch 'master' into fxamacker/support-evm-registers-in-check-storage
2 parents 0b7bdcf + 661a419 commit a1a3c33

File tree

5 files changed

+50
-21
lines changed

5 files changed

+50
-21
lines changed

access/validator.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,20 @@ func (v *TransactionValidator) checkExpiry(tx *flow.TransactionBody) error {
320320
return nil
321321
}
322322

323-
func (v *TransactionValidator) checkCanBeParsed(tx *flow.TransactionBody) error {
323+
func (v *TransactionValidator) checkCanBeParsed(tx *flow.TransactionBody) (err error) {
324+
defer func() {
325+
if r := recover(); r != nil {
326+
if panicErr, ok := r.(error); ok {
327+
err = InvalidScriptError{ParserErr: panicErr}
328+
} else {
329+
err = InvalidScriptError{ParserErr: fmt.Errorf("non-error-typed panic: %v", r)}
330+
}
331+
}
332+
}()
324333
if v.options.CheckScriptsParse {
325-
_, err := parser.ParseProgram(nil, tx.Script, parser.Config{})
326-
if err != nil {
327-
return InvalidScriptError{ParserErr: err}
334+
_, parseErr := parser.ParseProgram(nil, tx.Script, parser.Config{})
335+
if parseErr != nil {
336+
return InvalidScriptError{ParserErr: parseErr}
328337
}
329338
}
330339

engine/collection/ingest/engine_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@ func (suite *Suite) TestInvalidTransaction() {
172172
suite.Assert().True(errors.As(err, &access.InvalidScriptError{}))
173173
})
174174

175+
// In some cases the Cadence parser will panic rather than return an error.
176+
// If this happens, we should recover from the panic and return an InvalidScriptError.
177+
// See: https://github.com/onflow/cadence/issues/3428, https://github.com/dapperlabs/flow-go/issues/6964
178+
suite.Run("transaction script exceeds parse token limit (Cadence parser panic should be caught)", func() {
179+
const tokenLimit = 1 << 19
180+
script := "{};"
181+
for len(script) < tokenLimit {
182+
script += script
183+
}
184+
185+
tx := unittest.TransactionBodyFixture()
186+
tx.ReferenceBlockID = suite.root.ID()
187+
tx.Script = []byte("transaction { execute {" + script + "}}")
188+
189+
err := suite.engine.ProcessTransaction(&tx)
190+
suite.Assert().Error(err)
191+
suite.Assert().True(errors.As(err, &access.InvalidScriptError{}))
192+
})
193+
175194
suite.Run("invalid signature format", func() {
176195
signer := flow.Testnet.Chain().ServiceAddress()
177196
keyIndex := uint32(0)

engine/verification/verifier/engine.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,27 +163,28 @@ func (e *Engine) process(originID flow.Identifier, event interface{}) error {
163163
func (e *Engine) verify(ctx context.Context, originID flow.Identifier,
164164
vc *verification.VerifiableChunkData) error {
165165
// log it first
166-
log := e.log.With().Timestamp().
167-
Hex("origin", logging.ID(originID)).
166+
log := e.log.With().
168167
Uint64("chunk_index", vc.Chunk.Index).
169168
Hex("result_id", logging.Entity(vc.Result)).
169+
Uint64("block_height", vc.Header.Height).
170+
Hex("block_id", vc.Chunk.ChunkBody.BlockID[:]).
170171
Logger()
171172

172173
log.Info().Msg("verifiable chunk received by verifier engine")
173174

174175
// only accept internal calls
175176
if originID != e.me.NodeID() {
176-
return fmt.Errorf("invalid remote origin for verify")
177+
return fmt.Errorf("invalid remote origin for verify: %v", originID)
177178
}
178179

179-
var err error
180-
181180
// extracts chunk ID
182181
ch, ok := vc.Result.Chunks.ByIndex(vc.Chunk.Index)
183182
if !ok {
184183
return engine.NewInvalidInputErrorf("chunk out of range requested: %v", vc.Chunk.Index)
185184
}
186-
log.With().Hex("chunk_id", logging.Entity(ch)).Logger()
185+
log = log.With().
186+
Hex("chunk_id", logging.Entity(ch)).
187+
Logger()
187188

188189
// execute the assigned chunk
189190
span, _ := e.tracer.StartSpanFromContext(ctx, trace.VERVerChunkVerify)
@@ -200,58 +201,58 @@ func (e *Engine) verify(ctx context.Context, originID flow.Identifier,
200201
// if any fault found with the chunk
201202
switch chFault := err.(type) {
202203
case *chmodels.CFMissingRegisterTouch:
203-
e.log.Warn().
204+
log.Warn().
204205
Str("chunk_fault_type", "missing_register_touch").
205206
Str("chunk_fault", chFault.Error()).
206207
Msg("chunk fault found, could not verify chunk")
207208
// still create approvals for this case
208209
case *chmodels.CFNonMatchingFinalState:
209210
// TODO raise challenge
210-
e.log.Warn().
211+
log.Warn().
211212
Str("chunk_fault_type", "final_state_mismatch").
212213
Str("chunk_fault", chFault.Error()).
213214
Msg("chunk fault found, could not verify chunk")
214215
return nil
215216
case *chmodels.CFInvalidVerifiableChunk:
216217
// TODO raise challenge
217-
e.log.Error().
218+
log.Error().
218219
Str("chunk_fault_type", "invalid_verifiable_chunk").
219220
Str("chunk_fault", chFault.Error()).
220221
Msg("chunk fault found, could not verify chunk")
221222
return nil
222223
case *chmodels.CFInvalidEventsCollection:
223224
// TODO raise challenge
224-
e.log.Error().
225+
log.Error().
225226
Str("chunk_fault_type", "invalid_event_collection").
226227
Str("chunk_fault", chFault.Error()).
227228
Msg("chunk fault found, could not verify chunk")
228229
return nil
229230
case *chmodels.CFSystemChunkIncludedCollection:
230-
e.log.Error().
231+
log.Error().
231232
Str("chunk_fault_type", "system_chunk_includes_collection").
232233
Str("chunk_fault", chFault.Error()).
233234
Msg("chunk fault found, could not verify chunk")
234235
return nil
235236
case *chmodels.CFExecutionDataBlockIDMismatch:
236-
e.log.Error().
237+
log.Error().
237238
Str("chunk_fault_type", "execution_data_block_id_mismatch").
238239
Str("chunk_fault", chFault.Error()).
239240
Msg("chunk fault found, could not verify chunk")
240241
return nil
241242
case *chmodels.CFExecutionDataChunksLengthMismatch:
242-
e.log.Error().
243+
log.Error().
243244
Str("chunk_fault_type", "execution_data_chunks_count_mismatch").
244245
Str("chunk_fault", chFault.Error()).
245246
Msg("chunk fault found, could not verify chunk")
246247
return nil
247248
case *chmodels.CFExecutionDataInvalidChunkCID:
248-
e.log.Error().
249+
log.Error().
249250
Str("chunk_fault_type", "execution_data_chunk_cid_mismatch").
250251
Str("chunk_fault", chFault.Error()).
251252
Msg("chunk fault found, could not verify chunk")
252253
return nil
253254
case *chmodels.CFInvalidExecutionDataID:
254-
e.log.Error().
255+
log.Error().
255256
Str("chunk_fault_type", "execution_data_root_cid_mismatch").
256257
Str("chunk_fault", chFault.Error()).
257258
Msg("chunk fault found, could not verify chunk")

integration/benchmark/cmd/ci/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func main() {
6565
bigQueryUpload := flag.Bool("bigquery-upload", true, "whether to upload results to BigQuery (true / false)")
6666
pushgateway := flag.String("pushgateway", "disabled", "host:port for pushgateway")
6767
bigQueryProjectFlag := flag.String("bigquery-project", "ff-data-platform", "project name for the bigquery uploader")
68-
bigQueryDatasetFlag := flag.String("bigquery-dataset", "dev_src_flow_tps_metrics", "dataset name for the bigquery uploader")
68+
bigQueryDatasetFlag := flag.String("bigquery-dataset", "dev_src_flow_performance_metrics", "dataset name for the bigquery uploader")
6969
bigQueryRawTableFlag := flag.String("bigquery-raw-table", "rawResults", "table name for the bigquery raw results")
7070
flag.Parse()
7171

network/p2p/inspector/validation/control_message_validation_inspector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ func (c *ControlMsgValidationInspector) truncateIWantMessageIds(from peer.ID, rp
941941
sampleSize := int(10 * lastHighest)
942942
if sampleSize == 0 || sampleSize > c.config.IWant.MessageIdCountThreshold {
943943
// invalid or 0 sample size is suspicious
944-
lg.Warn().Str(logging.KeySuspicious, "true").Msg("zero or invalid sample size, using default max sample size")
944+
lg.Debug().Str(logging.KeySuspicious, "true").Msg("zero or invalid sample size, using default max sample size")
945945
sampleSize = c.config.IWant.MessageIdCountThreshold
946946
}
947947
for _, iWant := range rpc.GetControl().GetIwant() {

0 commit comments

Comments
 (0)