https://github.com/mingderwang/chatgtp-wallet-foundry
https://chatgpt.com/share/66e61ae2-2f70-800f-94c2-9fd9366bbe50
https://github.com/mingderwang/chatgtp-wallet-foundry
Last synced: about 2 months ago
JSON representation
https://chatgpt.com/share/66e61ae2-2f70-800f-94c2-9fd9366bbe50
- Host: GitHub
- URL: https://github.com/mingderwang/chatgtp-wallet-foundry
- Owner: mingderwang
- Created: 2024-09-14T23:23:02.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-15T00:01:28.000Z (almost 2 years ago)
- Last Synced: 2025-01-14T09:16:20.659Z (over 1 year ago)
- Language: Solidity
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## ChatGTP is Wrong
```
function isValidSignature(bytes32 hash, bytes memory signature) public view returns (bytes4) {
bytes32 messageHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
address recoveredSigner = recoverSigner(messageHash, signature);
if (recoveredSigner == owner) {
return 0x1626ba7e; // Magic value for valid signatures
} else {
return 0xffffffff; // Invalid signature
}
}
function recoverSigner(bytes32 _hash, bytes memory _signature) internal pure returns (address) {
(bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);
return ecrecover(_hash, v, r, s);
}
```
It's clear that, Wallet Contract can't use ecrecover to return the signer's address.
```
➜ chatgtp-wallet-foundry git:(main) ✗ forge test
[⠢] Compiling...
No files changed, compilation skipped
Ran 3 tests for test/Wallet.t.sol:WalletTest
[FAIL. Reason: assertion failed: 0xffffffff00000000000000000000000000000000000000000000000000000000 != 0x3078666666666666666600000000000000000000000000000000000000000000] testInvalidSignature() (gas: 18076)
[PASS] testOwnerIsSet() (gas: 10592)
[FAIL. Reason: assertion failed: 0xffffffff00000000000000000000000000000000000000000000000000000000 != 0x3078313632366261376500000000000000000000000000000000000000000000] testValidSignature() (gas: 25801)
Suite result: FAILED. 1 passed; 2 failed; 0 skipped; finished in 66.28ms (5.70ms CPU time)
Ran 1 test suite in 1.16s (66.28ms CPU time): 1 tests passed, 2 failed, 0 skipped (3 total tests)
Failing tests:
Encountered 2 failing tests in test/Wallet.t.sol:WalletTest
[FAIL. Reason: assertion failed: 0xffffffff00000000000000000000000000000000000000000000000000000000 != 0x3078666666666666666600000000000000000000000000000000000000000000] testInvalidSignature() (gas: 18076)
[FAIL. Reason: assertion failed: 0xffffffff00000000000000000000000000000000000000000000000000000000 != 0x3078313632366261376500000000000000000000000000000000000000000000] testValidSignature() (gas: 25801)
Encountered a total of 2 failing tests, 1 tests succeeded
```
## Foundry
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
Foundry consists of:
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
## Documentation
https://book.getfoundry.sh/
## Usage
### Build
```shell
$ forge build
```
### Test
```shell
$ forge test
```
### Format
```shell
$ forge fmt
```
### Gas Snapshots
```shell
$ forge snapshot
```
### Anvil
```shell
$ anvil
```
### Deploy
```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url --private-key
```
### Cast
```shell
$ cast
```
### Help
```shell
$ forge --help
$ anvil --help
$ cast --help
```