Skip to content

Commit

Permalink
Merge pull request #73 from pnetwork-association/fix/avoid-fund-loss
Browse files Browse the repository at this point in the history
Support for recipients without prefix
  • Loading branch information
envin3 authored Nov 20, 2024
2 parents ae59309 + 7166b32 commit 7803f91
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
10 changes: 6 additions & 4 deletions solidity/src/contracts/PAM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ contract PAM is Ownable, IPAM {
uint256 amount = uint256(bytes32(content[offset:offset += 32]));
bytes32 sender = bytes32(content[offset:offset += 32]);
uint256 recipientLen = uint256(bytes32(content[offset:offset += 32]));
address recipient = _bytesToAddress(
content[offset:offset += recipientLen]
);
bytes memory _recipient = recipientLen == 42
? content[2 + offset:offset += recipientLen]
: content[offset:offset += recipientLen];
address recipient = _bytesToAddress(_recipient);

bytes memory data = content[offset:];

return (nonce == operation.nonce &&
Expand Down Expand Up @@ -216,7 +218,7 @@ contract PAM is Ownable, IPAM {
uint160 iaddr = 0;
uint160 b1;
uint160 b2;
for (uint256 i = 2; i < 2 + 2 * 20; i += 2) {
for (uint256 i = 0; i < 2 * 20; i += 2) {
iaddr *= 256;
b1 = uint160(_fromHexCharToUint8(uint8(tmp[i])));
b2 = uint160(_fromHexCharToUint8(uint8(tmp[i + 1])));
Expand Down
42 changes: 42 additions & 0 deletions solidity/test/forge/PAM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,46 @@ contract PAMTest is Test, Helper {

assertTrue(authorized);
}

function test_isAuthrorized_TrueWhen_ValidEosEvent_no0x() public {
bytes32 eosTopicZero = 0x0000000000000000000000000000000000000000000000000000000073776170; // 'swap'
bytes32 eosChainId = 0x73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d;
bytes32 eosAdapter = 0x0000000000000000000000000000000000000000706e6574776f726b61646132; // 'adapter'
uint256 destinationChainIdSepolia = 11155111;
string
memory attestatorPublicKey2 = "0x04397db47d49685dfef7dd2d7da91c59a2551d6ea069f58d3e3318b70d34a0f3c7f39d5bd2a92b41f4eddd88caec85d74c39062f6e9abde9da7feef510a4c0b762";
bytes memory userdata;

// Retrieved from the ProofcastEventAttestator testing code
metadata.preimage = vm.parseBytes(
"0x010273e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d0a3bcd8042204cf627b7ae76c4791bbb2b89fa76f49633b2c167f3ac97355a02387706c47f825caad733c6c4a6eb15be3ac3001fd4437613780c4fe25e968a5d0000000000000000000000000000000000000000706e6574776f726b6164613200000000000000000000000000000000000000000000000000000000737761700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007b226576656e745f6279746573223a223030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030363536463733363936463734373337343734364636423645303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030304141333641373030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303044444141433846384634354330303030303030303030303030303030303030303030303030303030303030303030303030303030303030373036453635373437373646373236423646373736453738303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303032383631333433313336333533373632363633323332333534363338343536333337343533323330333133303433333833393633333334363330333833343331333733323339333433383332333633343434227d"
);
metadata.signature = vm.parseBytes(
"b76e1eb6e66d979d53a07cc8858fd542ff501e4ec718fc7632c8e323bb9b392d223348ca2c970914000783266a4d7786abb4fae76f85df06e117c63c33f5a9bd1c"
);

operation = IAdapter.Operation(
0x0a3bcd8042204cf627b7ae76c4791bbb2b89fa76f49633b2c167f3ac97355a02, // blockhash
0x387706c47f825caad733c6c4a6eb15be3ac3001fd4437613780c4fe25e968a5d, // txHash
0, // nonce
0x0000000000000000000000000000000000000000656f73696f747374746f6b6e, // token
eosChainId, // origin chain id
bytes32(destinationChainIdSepolia), // destination chain id
998300000000000000, // amount
0x0000000000000000000000000000000000000000706e6574776f726b6f776e78, // sender
0xa41657bf225F8Ec7E2010C89c3F084172948264D, // recipient
userdata // user data
);

vm.chainId(destinationChainIdSepolia);

pam = new PAM();
pam.setEmitter(eosChainId, eosAdapter);
pam.setTopicZero(eosChainId, eosTopicZero);
pam.setTeeSigner(vm.parseBytes(attestatorPublicKey2), attestation);

(bool authorized, ) = pam.isAuthorized(operation, metadata);

assertTrue(authorized);
}
}

0 comments on commit 7803f91

Please sign in to comment.