Skip to content

Commit

Permalink
fix sig parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
r0wdy1 committed Nov 13, 2023
1 parent 87eeb1f commit 8ba92c0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/zkbob/sequencer/ZkBobSequencer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ contract ZkBobSequencer is CustomABIDecoder, Parameters, MemoUtils {

(uint64 expiry, address _user) = _parsePermitData(_memo);

console2.log("expiry decoded", expiry);

(uint8 v, bytes32 r, bytes32 s) = _permittable_signature_proxy_fee();

console2.log("decoded r", bytes32ToHexString(r));
console2.log("decoded s", bytes32ToHexString(s));
console2.log("decoded v", v);
// console2.log("decoded nullifier", bytes32ToHexString(_nullifier));
console2.log("decoded holder", _user);
console2.log("decoded _tokenAmount", _tokenAmount);
IERC20Permit(_pool.token()).receiveWithSaltedPermit(
_user,
uint256(_tokenAmount) * TOKEN_DENOMINATOR / TOKEN_NUMERATOR,
uint256(_tokenAmount),
expiry,
bytes32(_nullifier),
v,
Expand Down
17 changes: 17 additions & 0 deletions src/zkbob/utils/CustomABIDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,23 @@ contract CustomABIDecoder {
return string(hexString);
}

function bytes32ToHexString(
bytes32 data
) public pure returns (string memory) {
bytes memory hexString = new bytes(2 * data.length);

for (uint256 i = 0; i < data.length; i++) {
bytes2 b = bytes2(uint16(uint8(data[i])));
bytes1 hi = bytes1(uint8(uint16(b)) / 16);
bytes1 lo = bytes1(uint8(uint16(b)) % 16);

hexString[2 * i] = char(hi);
hexString[2 * i + 1] = char(lo);
}

return string(hexString);
}

function char(bytes1 b) internal pure returns (bytes1 c) {
if (uint8(b) < 10) {
return bytes1(uint8(b) + 0x30);
Expand Down
9 changes: 6 additions & 3 deletions test/zkbob/ZkBobSequencer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,11 @@ abstract contract AbstractZkBobPoolSequencerTest is AbstractForkTest {
bytes32 proxyDigest,
bytes32 proverDigest
) internal pure returns (bytes memory) {
(uint8 vProver, bytes32 rProver, bytes32 sProver) = vm.sign(
(uint8 vProxy, bytes32 rProxy, bytes32 sProxy) = vm.sign(
pk1,
proxyDigest
);
(uint8 vProxy, bytes32 rProxy, bytes32 sProxy) = vm.sign(
(uint8 vProver, bytes32 rProver, bytes32 sProver) = vm.sign(
pk1,
proverDigest
);
Expand All @@ -421,7 +421,7 @@ abstract contract AbstractZkBobPoolSequencerTest is AbstractForkTest {
bytes32 r,
bytes32 s
) internal pure returns (bytes memory) {
return abi.encodePacked(uint256(s) + (v == 28 ? (1 << 255) : 0));
return abi.encodePacked(r,uint256(s) + (v == 28 ? (1 << 255) : 0));
}

function _encodePermitDeposit(
Expand Down Expand Up @@ -575,6 +575,7 @@ abstract contract AbstractZkBobPoolSequencerTest is AbstractForkTest {
bytes memory encodedSig = _encodePermitSignature(v,r,s);

console2.log("encodedSig",bytesToHexString(encodedSig));
console2.log("encodedSig.length",encodedSig.length);
console2.log("digest", bytes32ToHexString(proxyPermitDigest));
address poolToken = pool.token();
vm.prank(address(sequencer));
Expand All @@ -587,6 +588,8 @@ abstract contract AbstractZkBobPoolSequencerTest is AbstractForkTest {
r,
s
);

assertTrue(false);
}
function _digestSaltedPermit(
address _holder,
Expand Down

0 comments on commit 8ba92c0

Please sign in to comment.