From 5083d2a97c1519ea48a7989a6d993ce63188e881 Mon Sep 17 00:00:00 2001 From: envin Date: Tue, 19 Nov 2024 12:44:32 +0100 Subject: [PATCH 1/3] feat(pam): support recipient without prefix --- solidity/src/contracts/PAM.sol | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/solidity/src/contracts/PAM.sol b/solidity/src/contracts/PAM.sol index 3831a5e6..204f477d 100644 --- a/solidity/src/contracts/PAM.sol +++ b/solidity/src/contracts/PAM.sol @@ -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 && @@ -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]))); From a9e0a1c4549c850fe0eff20bf0771783da840962 Mon Sep 17 00:00:00 2001 From: envin Date: Tue, 19 Nov 2024 12:45:01 +0100 Subject: [PATCH 2/3] test(pam): settle with no prefix recipient --- solidity/test/forge/PAM.t.sol | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/solidity/test/forge/PAM.t.sol b/solidity/test/forge/PAM.t.sol index 5a0d7427..eb9bfbb6 100644 --- a/solidity/test/forge/PAM.t.sol +++ b/solidity/test/forge/PAM.t.sol @@ -349,4 +349,45 @@ 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); + } } From 7166b32e1195e37049d73250a24973c21244d067 Mon Sep 17 00:00:00 2001 From: envin Date: Wed, 20 Nov 2024 17:09:17 +0100 Subject: [PATCH 3/3] style: fix style --- solidity/src/contracts/PAM.sol | 8 ++++---- solidity/test/forge/PAM.t.sol | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/solidity/src/contracts/PAM.sol b/solidity/src/contracts/PAM.sol index 204f477d..b1dffc7c 100644 --- a/solidity/src/contracts/PAM.sol +++ b/solidity/src/contracts/PAM.sol @@ -150,11 +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])); - bytes memory _recipient = recipientLen == 42 ? - content[2 + offset:offset += recipientLen] : - 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 && diff --git a/solidity/test/forge/PAM.t.sol b/solidity/test/forge/PAM.t.sol index eb9bfbb6..d10577b0 100644 --- a/solidity/test/forge/PAM.t.sol +++ b/solidity/test/forge/PAM.t.sol @@ -355,7 +355,8 @@ contract PAMTest is Test, Helper { bytes32 eosChainId = 0x73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d; bytes32 eosAdapter = 0x0000000000000000000000000000000000000000706e6574776f726b61646132; // 'adapter' uint256 destinationChainIdSepolia = 11155111; - string memory attestatorPublicKey2 = "0x04397db47d49685dfef7dd2d7da91c59a2551d6ea069f58d3e3318b70d34a0f3c7f39d5bd2a92b41f4eddd88caec85d74c39062f6e9abde9da7feef510a4c0b762"; + string + memory attestatorPublicKey2 = "0x04397db47d49685dfef7dd2d7da91c59a2551d6ea069f58d3e3318b70d34a0f3c7f39d5bd2a92b41f4eddd88caec85d74c39062f6e9abde9da7feef510a4c0b762"; bytes memory userdata; // Retrieved from the ProofcastEventAttestator testing code @@ -365,7 +366,7 @@ contract PAMTest is Test, Helper { metadata.signature = vm.parseBytes( "b76e1eb6e66d979d53a07cc8858fd542ff501e4ec718fc7632c8e323bb9b392d223348ca2c970914000783266a4d7786abb4fae76f85df06e117c63c33f5a9bd1c" ); - + operation = IAdapter.Operation( 0x0a3bcd8042204cf627b7ae76c4791bbb2b89fa76f49633b2c167f3ac97355a02, // blockhash 0x387706c47f825caad733c6c4a6eb15be3ac3001fd4437613780c4fe25e968a5d, // txHash