Skip to content

Commit

Permalink
fix: update data encoding for sygma
Browse files Browse the repository at this point in the history
  • Loading branch information
viatrix committed Jun 21, 2023
1 parent 8dc2902 commit 83b0f26
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
18 changes: 16 additions & 2 deletions packages/evm/contracts/adapters/Sygma/SygmaHeaderReporter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,27 @@ contract SygmaHeaderReporter {
// bytes executeContractAddress
sygmaAdapter,
// uint8 len(executionDataDepositor)
uint8(32),
uint8(20),
// bytes executionDataDepositor
address(this),
// bytes executionDataDepositor + executionData
abi.encode(address(this), blockNumbers, blockHeaders)
prepareDepositData(blockNumbers, blockHeaders)
);
IBridge(_bridge).deposit{ value: msg.value }(destinationDomainID, _resourceID, depositData, feeData);
for (uint i = 0; i < blockNumbers.length; i++) {
emit HeaderReported(address(this), blockNumbers[i], blockHeaders[i]);
}
}

function slice(bytes calldata input, uint256 position) public pure returns (bytes memory) {
return input[position:];
}

function prepareDepositData(
uint256[] memory blockNumbers,
bytes32[] memory blockHeaders
) public view returns (bytes memory) {
bytes memory encoded = abi.encode(address(0), blockNumbers, blockHeaders);
return this.slice(encoded, 32);
}
}
14 changes: 9 additions & 5 deletions packages/evm/test/adapters/Sygma/02_SygmaHeaderReporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ const setup = async () => {

const prepareDepositData = async (reporterAddress: string, ids: string[], hashes: string[], adapter: string) => {
const abiCoder = ethers.utils.defaultAbiCoder
const executionData = abiCoder.encode(["address", "uint256[]", "bytes32[]"], [reporterAddress, ids, hashes])
const executionData = abiCoder
.encode(["address", "uint256[]", "bytes32[]"], [ethers.constants.AddressZero, ids, hashes])
.substring(66)

const SygmaAdapter = await ethers.getContractFactory("SygmaAdapter")
const functionSig = SygmaAdapter.interface.getSighash("storeHashes")
Expand All @@ -46,8 +48,9 @@ const prepareDepositData = async (reporterAddress: string, ids: string[], hashes
// IDepositAdapterTarget(address(0)).execute.selector,
// uint8(20),
// _targetDepositAdapter,
// uint8(32),
// abi.encode(address(this), depositContractCalldata)
// uint8(20),
// _depositorAddress,
// abi.encode(depositContractCalldata)
// );

const depositData =
Expand All @@ -56,8 +59,9 @@ const prepareDepositData = async (reporterAddress: string, ids: string[], hashes
functionSig.substring(2) +
"14" +
adapter.toLowerCase().substring(2) +
"20" +
executionData.substring(2)
"14" +
reporterAddress.toLowerCase().substring(2) +
executionData
return depositData
}

Expand Down

0 comments on commit 83b0f26

Please sign in to comment.