mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-26 04:25:57 +00:00
forge fmt
This commit is contained in:
parent
4bcea31c2a
commit
ae61f3d359
6 changed files with 47 additions and 39 deletions
9
.github/workflows/lint.yml
vendored
9
.github/workflows/lint.yml
vendored
|
@ -73,6 +73,15 @@ jobs:
|
||||||
- name: Run rustfmt
|
- name: Run rustfmt
|
||||||
run: cargo +${{ steps.nightly.outputs.version }} fmt -- --check
|
run: cargo +${{ steps.nightly.outputs.version }} fmt -- --check
|
||||||
|
|
||||||
|
- name: Install foundry
|
||||||
|
uses: foundry-rs/foundry-toolchain@8f1998e9878d786675189ef566a2e4bf24869773
|
||||||
|
with:
|
||||||
|
version: nightly-41d4e5437107f6f42c7711123890147bc736a609
|
||||||
|
cache: false
|
||||||
|
|
||||||
|
- name: Run forge fmt
|
||||||
|
run: FOUNDRY_FMT_SORT_INPUTS=false FOUNDRY_FMT_LINE_LENGTH=100 FOUNDRY_FMT_TABLE_WIDTH=2 FOUNDRY_FMT_BRACKET_SPACING=true FOUNDRY_FMT_INT_TYPES=preserve forge fmt --check $(find . -iname "*.sol")
|
||||||
|
|
||||||
machete:
|
machete:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
|
@ -4,24 +4,22 @@ pragma solidity ^0.8.26;
|
||||||
// See https://github.com/noot/schnorr-verify for implementation details
|
// See https://github.com/noot/schnorr-verify for implementation details
|
||||||
library Schnorr {
|
library Schnorr {
|
||||||
// secp256k1 group order
|
// secp256k1 group order
|
||||||
uint256 constant private Q =
|
uint256 private constant Q = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141;
|
||||||
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141;
|
|
||||||
|
|
||||||
// We fix the key to have:
|
// We fix the key to have:
|
||||||
// 1) An even y-coordinate
|
// 1) An even y-coordinate
|
||||||
// 2) An x-coordinate < Q
|
// 2) An x-coordinate < Q
|
||||||
uint8 constant private KEY_PARITY = 27;
|
uint8 private constant KEY_PARITY = 27;
|
||||||
|
|
||||||
// px := public key x-coordinate, where the public key has an even y-coordinate
|
// px := public key x-coordinate, where the public key has an even y-coordinate
|
||||||
// message := the message signed
|
// message := the message signed
|
||||||
// c := Schnorr signature challenge
|
// c := Schnorr signature challenge
|
||||||
// s := Schnorr signature solution
|
// s := Schnorr signature solution
|
||||||
function verify(
|
function verify(bytes32 px, bytes memory message, bytes32 c, bytes32 s)
|
||||||
bytes32 px,
|
internal
|
||||||
bytes memory message,
|
pure
|
||||||
bytes32 c,
|
returns (bool)
|
||||||
bytes32 s
|
{
|
||||||
) internal pure returns (bool) {
|
|
||||||
// ecrecover = (m, v, r, s) -> key
|
// ecrecover = (m, v, r, s) -> key
|
||||||
// We instead pass the following to obtain the nonce (not the key)
|
// We instead pass the following to obtain the nonce (not the key)
|
||||||
// Then we hash it and verify it matches the challenge
|
// Then we hash it and verify it matches the challenge
|
||||||
|
|
|
@ -4,12 +4,11 @@ pragma solidity ^0.8.26;
|
||||||
import "../Schnorr.sol";
|
import "../Schnorr.sol";
|
||||||
|
|
||||||
contract TestSchnorr {
|
contract TestSchnorr {
|
||||||
function verify(
|
function verify(bytes32 public_key, bytes calldata message, bytes32 c, bytes32 s)
|
||||||
bytes32 public_key,
|
external
|
||||||
bytes calldata message,
|
pure
|
||||||
bytes32 c,
|
returns (bool)
|
||||||
bytes32 s
|
{
|
||||||
) external pure returns (bool) {
|
|
||||||
return Schnorr.verify(public_key, message, c, s);
|
return Schnorr.verify(public_key, message, c, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,9 @@ contract Router {
|
||||||
}
|
}
|
||||||
|
|
||||||
event SeraiKeyUpdated(uint256 indexed nonce, bytes32 indexed key);
|
event SeraiKeyUpdated(uint256 indexed nonce, bytes32 indexed key);
|
||||||
event InInstruction(address indexed from, address indexed coin, uint256 amount, bytes instruction);
|
event InInstruction(
|
||||||
|
address indexed from, address indexed coin, uint256 amount, bytes instruction
|
||||||
|
);
|
||||||
event Executed(uint256 indexed nonce, bytes32 indexed batch);
|
event Executed(uint256 indexed nonce, bytes32 indexed batch);
|
||||||
|
|
||||||
error InvalidSignature();
|
error InvalidSignature();
|
||||||
|
@ -62,10 +64,10 @@ contract Router {
|
||||||
|
|
||||||
// updateSeraiKey validates the given Schnorr signature against the current public key, and if
|
// updateSeraiKey validates the given Schnorr signature against the current public key, and if
|
||||||
// successful, updates the contract's public key to the one specified.
|
// successful, updates the contract's public key to the one specified.
|
||||||
function updateSeraiKey(
|
function updateSeraiKey(bytes32 newSeraiKey, Signature calldata signature)
|
||||||
bytes32 newSeraiKey,
|
external
|
||||||
Signature calldata signature
|
_updateSeraiKeyAtEndOfFn(_nonce, newSeraiKey)
|
||||||
) external _updateSeraiKeyAtEndOfFn(_nonce, newSeraiKey) {
|
{
|
||||||
bytes memory message = abi.encodePacked("updateSeraiKey", block.chainid, _nonce, newSeraiKey);
|
bytes memory message = abi.encodePacked("updateSeraiKey", block.chainid, _nonce, newSeraiKey);
|
||||||
_nonce++;
|
_nonce++;
|
||||||
|
|
||||||
|
@ -74,25 +76,15 @@ contract Router {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function inInstruction(
|
function inInstruction(address coin, uint256 amount, bytes memory instruction) external payable {
|
||||||
address coin,
|
|
||||||
uint256 amount,
|
|
||||||
bytes memory instruction
|
|
||||||
) external payable {
|
|
||||||
if (coin == address(0)) {
|
if (coin == address(0)) {
|
||||||
if (amount != msg.value) {
|
if (amount != msg.value) {
|
||||||
revert InvalidAmount();
|
revert InvalidAmount();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(bool success, bytes memory res) =
|
(bool success, bytes memory res) = address(coin).call(
|
||||||
address(coin).call(
|
abi.encodeWithSelector(IERC20.transferFrom.selector, msg.sender, address(this), amount)
|
||||||
abi.encodeWithSelector(
|
);
|
||||||
IERC20.transferFrom.selector,
|
|
||||||
msg.sender,
|
|
||||||
address(this),
|
|
||||||
amount
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Require there was nothing returned, which is done by some non-standard tokens, or that the
|
// Require there was nothing returned, which is done by some non-standard tokens, or that the
|
||||||
// ERC20 contract did in fact return true
|
// ERC20 contract did in fact return true
|
||||||
|
@ -193,9 +185,9 @@ contract Router {
|
||||||
|
|
||||||
// Perform the calls with a set gas budget
|
// Perform the calls with a set gas budget
|
||||||
(uint32 gas, bytes memory code) = abi.decode(transactions[i].destination, (uint32, bytes));
|
(uint32 gas, bytes memory code) = abi.decode(transactions[i].destination, (uint32, bytes));
|
||||||
address(this).call{
|
address(this).call{ gas: gas }(
|
||||||
gas: gas
|
abi.encodeWithSelector(Router.arbitaryCallOut.selector, code)
|
||||||
}(abi.encodeWithSelector(Router.arbitaryCallOut.selector, code));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,11 @@ contract TestERC20 {
|
||||||
function name() public pure returns (string memory) {
|
function name() public pure returns (string memory) {
|
||||||
return "Test ERC20";
|
return "Test ERC20";
|
||||||
}
|
}
|
||||||
|
|
||||||
function symbol() public pure returns (string memory) {
|
function symbol() public pure returns (string memory) {
|
||||||
return "TEST";
|
return "TEST";
|
||||||
}
|
}
|
||||||
|
|
||||||
function decimals() public pure returns (uint8) {
|
function decimals() public pure returns (uint8) {
|
||||||
return 18;
|
return 18;
|
||||||
}
|
}
|
||||||
|
@ -29,11 +31,13 @@ contract TestERC20 {
|
||||||
function balanceOf(address owner) public view returns (uint256) {
|
function balanceOf(address owner) public view returns (uint256) {
|
||||||
return balances[owner];
|
return balances[owner];
|
||||||
}
|
}
|
||||||
|
|
||||||
function transfer(address to, uint256 value) public returns (bool) {
|
function transfer(address to, uint256 value) public returns (bool) {
|
||||||
balances[msg.sender] -= value;
|
balances[msg.sender] -= value;
|
||||||
balances[to] += value;
|
balances[to] += value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function transferFrom(address from, address to, uint256 value) public returns (bool) {
|
function transferFrom(address from, address to, uint256 value) public returns (bool) {
|
||||||
allowances[from][msg.sender] -= value;
|
allowances[from][msg.sender] -= value;
|
||||||
balances[from] -= value;
|
balances[from] -= value;
|
||||||
|
@ -45,6 +49,7 @@ contract TestERC20 {
|
||||||
allowances[msg.sender][spender] = value;
|
allowances[msg.sender][spender] = value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function allowance(address owner, address spender) public view returns (uint256) {
|
function allowance(address owner, address spender) public view returns (uint256) {
|
||||||
return allowances[owner][spender];
|
return allowances[owner][spender];
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ contract Deployer {
|
||||||
uint64 block_number;
|
uint64 block_number;
|
||||||
address created_contract;
|
address created_contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapping(bytes32 => Deployment) public deployments;
|
mapping(bytes32 => Deployment) public deployments;
|
||||||
|
|
||||||
error Reentrancy();
|
error Reentrancy();
|
||||||
|
@ -51,11 +52,15 @@ contract Deployer {
|
||||||
bool called;
|
bool called;
|
||||||
// This contract doesn't have any other use of transient storage, nor is to be inherited, making
|
// This contract doesn't have any other use of transient storage, nor is to be inherited, making
|
||||||
// this usage of the zero address safe
|
// this usage of the zero address safe
|
||||||
assembly { called := tload(0) }
|
assembly {
|
||||||
|
called := tload(0)
|
||||||
|
}
|
||||||
if (called) {
|
if (called) {
|
||||||
revert Reentrancy();
|
revert Reentrancy();
|
||||||
}
|
}
|
||||||
assembly { tstore(0, 1) }
|
assembly {
|
||||||
|
tstore(0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
// Check this wasn't prior deployed
|
// Check this wasn't prior deployed
|
||||||
bytes32 init_code_hash = keccak256(init_code);
|
bytes32 init_code_hash = keccak256(init_code);
|
||||||
|
|
Loading…
Reference in a new issue