Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate params in RPC server #268

Merged
merged 10 commits into from
Jul 4, 2024
Merged

Validate params in RPC server #268

merged 10 commits into from
Jul 4, 2024

Conversation

emlautarom1
Copy link
Contributor

Current Behavior

The current RPC server does not validate the parameters on each method, opening up the possibility of errors due to nil dereference panics or unsatisfied invariants.

New Behavior

Each method on the RPC server validates the parameters returning an error in case of failure before doing any actual work.

Breaking Changes

There should not be any breaking changes.

Observations

Currently we are only checking for hidden nil values.

@emlautarom1 emlautarom1 linked an issue Jul 2, 2024 that may be closed by this pull request
Copy link
Contributor

@Hyodar Hyodar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Can you also add a basic max range check for the checkpoint messages timestamps as well? Just a sanity bound to avoid overloads (e.g. 2h range max between start and end)

- Check for nil
- Check for invalid range
- Check for range too large
@emlautarom1
Copy link
Contributor Author

@Hyodar added range check to RPC

@Hyodar
Copy link
Contributor

Hyodar commented Jul 3, 2024

Int test failed with the timestamp range check because the first checkpoint is actually 0 -> current. We could change this without much of an issue so the first checkpoint is toTimestamp - interval -> toTimestamp (feel free to do that), but this reminds me we still then need to chunk GetAggregatedCheckpointMessages calls on the operators if this is ever needed.

@emlautarom1
Copy link
Contributor Author

We could change this without much of an issue so the first checkpoint is toTimestamp - interval -> toTimestamp

Could you point me out to where this would need to be changed?

@Hyodar
Copy link
Contributor

Hyodar commented Jul 3, 2024

Could you point me out to where this would need to be changed?

In sendNewCheckpointTask, you can first get the toTimestamp and, if the last timestamp is 0, just do fromTimestamp = toTimestamp - agg.checkpointInterval or such.

@emlautarom1
Copy link
Contributor Author

There still seems to be an issue here. I've changed the sendNewCheckpointTask interval as follows:

	toTimestamp := block.Time()
	fromTimestamp := lastCheckpointToTimestamp + 1
	if lastCheckpointToTimestamp == 0 {
		fromTimestamp = toTimestamp - uint64(agg.checkpointInterval)
	}

yet the integration test continues to fail.

@Hyodar
Copy link
Contributor

Hyodar commented Jul 3, 2024

I think you need to get the seconds only, seems to be underflowing. Here's the error:

{"level":"info","ts":1720032516.9505258,"caller":"aggregator/aggregator.go:397","msg":"Aggregator sending new task","fromTimestamp":18446744035429584175,"toTimestamp":1720032559}
{"level":"error","ts":1720032516.9521868,"caller":"chainio/avs_writer.go:88","msg":"Error assembling CreateCheckpointTask tx","stacktrace":"github.com/NethermindEth/near-sffl/core/chainio.(*AvsWriter).SendNewCheckpointTask\n\t/home/runner/work/near-sffl/near-sffl/core/chainio/avs_writer.go:88\ngithub.com/NethermindEth/near-sffl/aggregator.(*Aggregator).sendNewCheckpointTask\n\t/home/runner/work/near-sffl/near-sffl/aggregator/aggregator.go:399"}
{"level":"error","ts":1720032516.952221,"caller":"aggregator/aggregator.go:401","msg":"Aggregator failed to send checkpoint","err":"execution reverted: revert: fromTimestamp greater than toTimestamp","stacktrace":"github.com/NethermindEth/near-sffl/aggregator.(*Aggregator).sendNewCheckpointTask\n\t/home/runner/work/near-sffl/near-sffl/aggregator/aggregator.go:401"}

@emlautarom1
Copy link
Contributor Author

I think you need to get the seconds only, seems to be underflowing

Good catch, this is not the first time that I've had the same issue.

@emlautarom1 emlautarom1 merged commit 438de44 into main Jul 4, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve parameter validation in aggregator routes
3 participants