-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix: string slice panic & automated smart contract tests #76
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
189c85d
fix: string slice panic & automated smart contract tests
chris13524 761866c
chore: add foundry install
chris13524 6892ae6
fix: missing cacao feature dependency
chris13524 2e81ea9
chore: simplify CI testing params
chris13524 1eba3f5
fix: EIP-191 and JWT panics
chris13524 4424b74
chore: debug output by logging it
chris13524 b2d94d0
chore: add Foundry to dependency list
chris13524 2b3a50c
fix: pre-build contracts to avoid race condition
chris13524 234518a
chore: apply lint to all crates
chris13524 3aa8727
Merge branch 'main' into fix/string-slice-panic
chris13524 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,12 @@ version = "0.1.0" | |
edition = "2021" | ||
|
||
[dependencies] | ||
relay_rpc = { path = "../relay_rpc" } | ||
relay_rpc = { path = "../relay_rpc", features = ["cacao"] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't actually compile without this; forgot in previous PRs. Wasn't caught because CI here always sets this feature. |
||
reqwest = { version = "0.12.2", features = ["json"] } | ||
serde = "1.0" | ||
tokio = { version = "1.0", features = ["test-util", "macros"] } | ||
tracing = "0.1.40" | ||
url = "2" | ||
|
||
[lints.clippy] | ||
indexing_slicing = "deny" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
pragma solidity ^0.8.25; | ||
|
||
// https://eips.ethereum.org/EIPS/eip-1271#reference-implementation | ||
|
||
contract Eip1271Mock { | ||
address owner; | ||
|
||
constructor() { | ||
owner = msg.sender; | ||
} | ||
|
||
/** | ||
* @notice Verifies that the signer is the owner of the signing contract. | ||
*/ | ||
function isValidSignature( | ||
bytes32 _hash, | ||
bytes calldata _signature | ||
) external view returns (bytes4) { | ||
// Validate signatures | ||
if (recoverSigner(_hash, _signature) == owner) { | ||
return 0x1626ba7e; | ||
} else { | ||
return 0xffffffff; | ||
} | ||
} | ||
|
||
/** | ||
* @notice Recover the signer of hash, assuming it's an EOA account | ||
* @dev Only for EthSign signatures | ||
* @param _hash Hash of message that was signed | ||
* @param _signature Signature encoded as (bytes32 r, bytes32 s, uint8 v) | ||
*/ | ||
function recoverSigner( | ||
bytes32 _hash, | ||
bytes memory _signature | ||
) internal pure returns (address signer) { | ||
require(_signature.length == 65, "SignatureValidator#recoverSigner: invalid signature length"); | ||
|
||
// Variables are not scoped in Solidity. | ||
uint8 v = uint8(_signature[64]); | ||
bytes32 r; | ||
bytes32 s; | ||
assembly { | ||
// Slice the signature into r and s components | ||
r := mload(add(_signature, 32)) | ||
s := mload(add(_signature, 64)) | ||
} | ||
|
||
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature | ||
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines | ||
// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most | ||
// signatures from current libraries generate a unique signature with an s-value in the lower half order. | ||
// | ||
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value | ||
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or | ||
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept | ||
// these malleable signatures as well. | ||
// | ||
// Source OpenZeppelin | ||
// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/cryptography/ECDSA.sol | ||
|
||
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { | ||
revert("SignatureValidator#recoverSigner: invalid signature 's' value"); | ||
} | ||
|
||
if (v != 27 && v != 28) { | ||
revert("SignatureValidator#recoverSigner: invalid signature 'v' value"); | ||
} | ||
|
||
// Recover ECDSA signer | ||
signer = ecrecover(_hash, v, r, s); | ||
|
||
// Prevent signer from being 0x0 | ||
require( | ||
signer != address(0x0), | ||
"SignatureValidator#recoverSigner: INVALID_SIGNER" | ||
); | ||
|
||
return signer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--all-features
implies--features cacao
--retries
doesn't seem to be necessary in latest version