fix: make GatewayContract compatible with current KMS in trustless case #181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes the code of GatewayContract and Gateway library a lot more complex than previously, but this was needed since KMS did not implement the specific data handling in the trustless decryption case, and we decided not to change anything from KMS side. Since the trustless case became more complex, it consumes more gas, but we had no other option since we want the KMS to be agnostic to wether decryption was requested in trustless or trusted mode.
To mitigate the increase in gas cost, I implementend one of the optimizations we talked about : I am no longer doing a KMSVerifier call inside the GatewayContract in the trustless case (since in this case we assume that the dapp will do the verification itself).
Some other more minor improvements include : switching the
external
modifier ofremoveOffset
tointernal
, and movingthe $.isFulfilled[requestID] = true;
line at the start of thefulfillRequest
function as this will be needed to avoid reentrancy later, because in a future version we will probably remove theonlyRelayer
modifier, to avoid "relayer censorship" risk.Once you approve the PR, I will need to release the patched version of
fhevm-core-contracts
to also upgrade the gateway library similarly infhevm
and also release then a patch offhevm
fyi.