Skip to content

Commit

Permalink
Merge branch 'wevm:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-bozin-txfusion authored Oct 29, 2024
2 parents 323d375 + 1b88c09 commit 83a80b4
Show file tree
Hide file tree
Showing 205 changed files with 4,599 additions and 5,250 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-rpc-providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:

- name: Install Playwright Browsers
if: ${{ matrix.runtime == 'next' || matrix.runtime == 'vite' }}
run: pnpx playwright@1.40.1 install --with-deps
run: pnpx playwright@1.41.2 install --with-deps

- name: Install dependencies
uses: ./.github/actions/install-dependencies
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
workflow_dispatch:

jobs:
lint:
name: Lint
check:
name: Check
runs-on: ubuntu-latest
timeout-minutes: 5

Expand All @@ -18,11 +18,11 @@ jobs:
- name: Install dependencies
uses: ./.github/actions/install-dependencies

- name: Lint repo
run: pnpm lint:repo
- name: Check repo
run: pnpm check:repo

- name: Lint code
run: pnpm lint
- name: Check code
run: pnpm check

- uses: stefanzweifel/git-auto-commit-action@v5
env:
Expand All @@ -34,7 +34,7 @@ jobs:

build:
name: Build
needs: lint
needs: check
runs-on: ubuntu-latest
timeout-minutes: 5

Expand All @@ -61,7 +61,7 @@ jobs:

types:
name: Types
needs: lint
needs: check
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
Expand All @@ -84,7 +84,7 @@ jobs:
run: pnpm contracts:build

- name: Check types
run: pnpm typecheck
run: pnpm check:types

- name: Bench types
if: matrix.version != '5.0.4'
Expand Down Expand Up @@ -187,7 +187,7 @@ jobs:

- name: Install Playwright Browsers
if: ${{ matrix.runtime == 'next' || matrix.runtime == 'vite' }}
run: pnpx playwright@1.40.1 install --with-deps
run: pnpx playwright@1.41.2 install --with-deps

- name: Build
run: pnpm build
Expand Down
86 changes: 86 additions & 0 deletions contracts/src/UniversalSigValidator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
pragma solidity ^0.8.17;

// SPDX-License-Identifier: UNLICENSED

// https://github.com/AmbireTech/signature-validator

interface IERC1271Wallet {
function isValidSignature(
bytes32 hash,
bytes calldata signature
) external view returns (bytes4 magicValue);
}

contract VerifySig {
// ERC-6492 suffix: https://eips.ethereum.org/EIPS/eip-6492
bytes32 private constant ERC6492_DETECTION_SUFFIX =
0x6492649264926492649264926492649264926492649264926492649264926492;
bytes4 private constant ERC1271_SUCCESS = 0x1626ba7e;

/**
* @notice Verifies that the signature is valid for that signer and hash
*/
function isValidSig(
address _signer,
bytes32 _hash,
bytes memory _signature
) public returns (bool) {
// The order here is strictly defined in https://eips.ethereum.org/EIPS/eip-6492
// - ERC-6492 suffix check and verification first, while being permissive in case the contract is already deployed so as to not invalidate old sigs
// - ERC-1271 verification if there's contract code
// - finally, ecrecover
if (trailingBytes32(_signature) == ERC6492_DETECTION_SUFFIX) {
address create2Factory;
bytes memory factoryCalldata;
bytes memory originalSig;
(create2Factory, factoryCalldata, originalSig) = abi.decode(
_signature,
(address, bytes, bytes)
);

(bool success, ) = create2Factory.call(factoryCalldata);

if (_signer.code.length == 0) {
require(success, "SignatureValidator: deployment");
}

return
IERC1271Wallet(_signer).isValidSignature(_hash, originalSig) ==
ERC1271_SUCCESS;
}

if (_signer.code.length > 0) {
return
IERC1271Wallet(_signer).isValidSignature(_hash, _signature) ==
ERC1271_SUCCESS;
}

// ecrecover verification
require(
_signature.length == 65,
"SignatureValidator#recoverSigner: invalid signature length"
);
bytes32[3] memory _sig;
assembly {
_sig := _signature
}
bytes32 r = _sig[1];
bytes32 s = _sig[2];
uint8 v = uint8(_signature[64]);
if (v != 27 && v != 28) {
revert(
"SignatureValidator#recoverSigner: invalid signature v value"
);
}
return ecrecover(_hash, v, r, s) == _signer;
}

function trailingBytes32(
bytes memory data
) internal pure returns (bytes32 ret) {
require(data.length >= 32);
assembly {
ret := mload(add(data, mload(data)))
}
}
}
86 changes: 4 additions & 82 deletions contracts/src/deployless/DeploylessUniversalSigValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,14 @@ pragma solidity ^0.8.17;
// SPDX-License-Identifier: UNLICENSED

// https://github.com/AmbireTech/signature-validator
import { VerifySig } from "../UniversalSigValidator.sol";

interface IERC1271Wallet {
function isValidSignature(
bytes32 hash,
bytes calldata signature
) external view returns (bytes4 magicValue);
}

contract VerifySig {
contract DeploylessVerifySig is VerifySig {
constructor(address _signer, bytes32 _hash, bytes memory _signature) {
bool isValidSig = isValidUniversalSig(_signer, _hash, _signature);
bool isValid = isValidSig(_signer, _hash, _signature);
assembly {
mstore(0, isValidSig)
mstore(0, isValid)
return(31, 1)
}
}

// ERC-6492 suffix: https://eips.ethereum.org/EIPS/eip-6492
bytes32 private constant ERC6492_DETECTION_SUFFIX =
0x6492649264926492649264926492649264926492649264926492649264926492;
bytes4 private constant ERC1271_SUCCESS = 0x1626ba7e;

/**
* @notice Verifies that the signature is valid for that signer and hash
*/
function isValidUniversalSig(
address _signer,
bytes32 _hash,
bytes memory _signature
) public returns (bool) {
// The order here is strictly defined in https://eips.ethereum.org/EIPS/eip-6492
// - ERC-6492 suffix check and verification first, while being permissive in case the contract is already deployed so as to not invalidate old sigs
// - ERC-1271 verification if there's contract code
// - finally, ecrecover
if (trailingBytes32(_signature) == ERC6492_DETECTION_SUFFIX) {
address create2Factory;
bytes memory factoryCalldata;
bytes memory originalSig;
(create2Factory, factoryCalldata, originalSig) = abi.decode(
_signature,
(address, bytes, bytes)
);

(bool success, ) = create2Factory.call(factoryCalldata);

if (_signer.code.length == 0) {
require(success, "SignatureValidator: deployment");
}

return
IERC1271Wallet(_signer).isValidSignature(_hash, originalSig) ==
ERC1271_SUCCESS;
}

if (_signer.code.length > 0) {
return
IERC1271Wallet(_signer).isValidSignature(_hash, _signature) ==
ERC1271_SUCCESS;
}

// ecrecover verification
require(
_signature.length == 65,
"SignatureValidator#recoverSigner: invalid signature length"
);
bytes32[3] memory _sig;
assembly {
_sig := _signature
}
bytes32 r = _sig[1];
bytes32 s = _sig[2];
uint8 v = uint8(_signature[64]);
if (v != 27 && v != 28) {
revert(
"SignatureValidator#recoverSigner: invalid signature v value"
);
}
return ecrecover(_hash, v, r, s) == _signer;
}

function trailingBytes32(
bytes memory data
) internal pure returns (bytes32 ret) {
require(data.length >= 32);
assembly {
ret := mload(add(data, mload(data)))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;

contract BatchCallInvoker {
contract BatchCallDelegation {
struct Call {
bytes data;
address to;
Expand Down
2 changes: 1 addition & 1 deletion environments/bun/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const client = createPublicClient({
const webSocketClient = createPublicClient({
chain: mainnet,
transport: webSocket(
'wss://eth-mainnet.g.alchemy.com/v2/4iIl6mDHqX3GFrpzmfj2Soirf3MPoAcH',
'wss://eth-mainnet.g.alchemy.com/v2/WV-bLot1hKjjCfpPq603Ro-jViFzwYX8',
),
})

Expand Down
2 changes: 1 addition & 1 deletion environments/next/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
4 changes: 2 additions & 2 deletions environments/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"test": "playwright test"
},
"dependencies": {
"next": "13.5.4",
"next": "14.2.15",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"viem": "file:../../src/"
},
"devDependencies": {
"@playwright/test": "1.40.1",
"@playwright/test": "1.41.2",
"@types/node": "^20.8.3",
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
Expand Down
2 changes: 1 addition & 1 deletion environments/next/src/app/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function Client() {
const webSocketClient = createPublicClient({
chain: mainnet,
transport: webSocket(
'wss://eth-mainnet.g.alchemy.com/v2/4iIl6mDHqX3GFrpzmfj2Soirf3MPoAcH',
'wss://eth-mainnet.g.alchemy.com/v2/WV-bLot1hKjjCfpPq603Ro-jViFzwYX8',
),
})

Expand Down
2 changes: 1 addition & 1 deletion environments/next/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default async function Home() {
const webSocketClient = createPublicClient({
chain: mainnet,
transport: webSocket(
'wss://eth-mainnet.g.alchemy.com/v2/4iIl6mDHqX3GFrpzmfj2Soirf3MPoAcH',
'wss://eth-mainnet.g.alchemy.com/v2/WV-bLot1hKjjCfpPq603Ro-jViFzwYX8',
),
})

Expand Down
2 changes: 1 addition & 1 deletion environments/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const client = createPublicClient({
const webSocketClient = createPublicClient({
chain: mainnet,
transport: webSocket(
'wss://eth-mainnet.g.alchemy.com/v2/4iIl6mDHqX3GFrpzmfj2Soirf3MPoAcH',
'wss://eth-mainnet.g.alchemy.com/v2/WV-bLot1hKjjCfpPq603Ro-jViFzwYX8',
),
})
;(async () => {
Expand Down
2 changes: 1 addition & 1 deletion environments/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const client = createPublicClient({
const webSocketClient = createPublicClient({
chain: mainnet,
transport: webSocket(
'wss://eth-mainnet.g.alchemy.com/v2/4iIl6mDHqX3GFrpzmfj2Soirf3MPoAcH',
'wss://eth-mainnet.g.alchemy.com/v2/WV-bLot1hKjjCfpPq603Ro-jViFzwYX8',
),
})

Expand Down
2 changes: 1 addition & 1 deletion environments/tsc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mainnet } from 'viem/chains'
const webSocketClient = createPublicClient({
chain: mainnet,
transport: webSocket(
'wss://eth-mainnet.g.alchemy.com/v2/4iIl6mDHqX3GFrpzmfj2Soirf3MPoAcH',
'wss://eth-mainnet.g.alchemy.com/v2/WV-bLot1hKjjCfpPq603Ro-jViFzwYX8',
),
})

Expand Down
4 changes: 2 additions & 2 deletions environments/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"viem": "file:../../src/"
},
"devDependencies": {
"@playwright/test": "1.40.1",
"@playwright/test": "1.41.2",
"@types/node": "^20.8.3",
"typescript": "^5.0.3",
"vite": "^4.4.5"
"vite": "^5.4.8"
}
}
2 changes: 1 addition & 1 deletion environments/vite/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const client = createPublicClient({
const webSocketClient = createPublicClient({
chain: mainnet,
transport: webSocket(
'wss://eth-mainnet.g.alchemy.com/v2/4iIl6mDHqX3GFrpzmfj2Soirf3MPoAcH',
'wss://eth-mainnet.g.alchemy.com/v2/WV-bLot1hKjjCfpPq603Ro-jViFzwYX8',
),
})

Expand Down
2 changes: 1 addition & 1 deletion examples/_template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
},
"devDependencies": {
"typescript": "^5.0.3",
"vite": "^4.4.5"
"vite": "^5.4.8"
}
}
2 changes: 1 addition & 1 deletion examples/account-abstraction_biconomy-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
},
"devDependencies": {
"typescript": "^5.0.3",
"vite": "^4.4.5"
"vite": "^5.4.8"
}
}
2 changes: 1 addition & 1 deletion examples/blocks_fetching-blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
},
"devDependencies": {
"typescript": "^5.0.3",
"vite": "^4.4.5"
"vite": "^5.4.8"
}
}
2 changes: 1 addition & 1 deletion examples/blocks_watching-blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
},
"devDependencies": {
"typescript": "^5.0.3",
"vite": "^4.4.5"
"vite": "^5.4.8"
}
}
Loading

0 comments on commit 83a80b4

Please sign in to comment.